Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Fix add_cause method not being able to process an array of hashes #14433

Merged
merged 24 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
502ba0a
Fix session issue
aguspe Aug 23, 2024
c7fd486
Test ready
aguspe Aug 24, 2024
f4dd6d6
Fix identation
aguspe Aug 24, 2024
9560333
Add only driver remote
aguspe Aug 24, 2024
5479861
Produce session error
aguspe Aug 25, 2024
537aaed
Merge branch 'trunk' into rb_fix_bracktrace_issue
aguspe Aug 27, 2024
c53cf43
Update test
aguspe Aug 27, 2024
9c8998f
Update backtrace test
aguspe Aug 27, 2024
7d589f8
Update to exclude firefox
aguspe Aug 27, 2024
fea9157
Merge branch 'trunk' into rb_fix_bracktrace_issue
aguspe Aug 29, 2024
9068419
Merge branch 'trunk' into rb_fix_bracktrace_issue
aguspe Aug 30, 2024
9b85510
Force error to be risen so failure does not appear due to guard
aguspe Aug 30, 2024
da3f037
Merge remote-tracking branch 'origin/rb_fix_bracktrace_issue' into rb…
aguspe Aug 30, 2024
2a11e3e
Update error to no such element
aguspe Aug 30, 2024
dc53692
Remove firefox guard
aguspe Aug 31, 2024
0566e39
Go back to use session error for spec
aguspe Sep 2, 2024
1bef5e6
Merge branch 'trunk' into rb_fix_bracktrace_issue
aguspe Sep 2, 2024
8c29ae8
Update the test to cause session error without quit
aguspe Sep 3, 2024
4a682cb
Update to use title
aguspe Sep 3, 2024
d2ea6f8
Avoid window location inactivity
aguspe Sep 4, 2024
87eaa78
Merge branch 'trunk' into rb_fix_bracktrace_issue
aguspe Sep 4, 2024
6b5c55d
Merge branch 'trunk' into rb_fix_bracktrace_issue
aguspe Sep 6, 2024
a0d3f75
Update test to not use any script
aguspe Sep 6, 2024
02b4937
Change test to capture the invalid session id error
aguspe Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions rb/lib/selenium/webdriver/remote/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,30 @@ def assert_ok

def add_cause(ex, error, backtrace)
cause = Error::WebDriverError.new
backtrace = backtrace_from_remote(backtrace) if backtrace.is_a?(Array)
cause.set_backtrace(backtrace)
raise ex, cause: cause
rescue Error.for_error(error)
ex
end

def backtrace_from_remote(server_trace)
server_trace.filter_map do |frame|
next unless frame.is_a?(Hash)

file = frame['fileName']
line = frame['lineNumber']
method = frame['methodName']

class_name = frame['className']
file = "#{class_name}(#{file})" if class_name

method = 'unknown' if method.nil? || method.empty?

"[remote server] #{file}:#{line}:in `#{method}'"
end
end

def process_error
return unless self['value'].is_a?(Hash)

Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/remote/response.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module Selenium

def add_cause: (Error::WebDriverError ex, String error, Array[String] backtrace) -> Error::WebDriverError

def backtrace_from_remote: -> Array[String]

def process_error: () -> Array[Hash[untyped, untyped]]
end
end
Expand Down
7 changes: 7 additions & 0 deletions rb/spec/integration/selenium/webdriver/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ module WebDriver
rescue WebDriver::Error::NoSuchElementError => e
expect(e.backtrace).not_to be_empty
end

it 'has backtrace when using a remote server' do
options = Selenium::WebDriver::Options.chrome(binary: '/path/to/nonexistent/chrome')
Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', options: options
aguspe marked this conversation as resolved.
Show resolved Hide resolved
rescue WebDriver::Error::SessionNotCreatedError => e
expect(e.cause).to be_a(WebDriver::Error::WebDriverError)
end
end
end # WebDriver
end # Selenium