Skip to content

Commit

Permalink
[rb] Fix add_cause method not being able to process an array of hashes (
Browse files Browse the repository at this point in the history
  • Loading branch information
aguspe authored Sep 6, 2024
1 parent a04dd33 commit 247bc2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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
12 changes: 12 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,18 @@ module WebDriver
rescue WebDriver::Error::NoSuchElementError => e
expect(e.backtrace).not_to be_empty
end

it 'has backtrace when using a remote server', only: {driver: :remote,
reason: 'This test should only apply to remote drivers'} do
unless driver.is_a?(WebDriver::Remote::Driver)
raise 'This error needs to be risen for the pending test not to fail on local drivers'
end

driver.send(:bridge).instance_variable_set(:@session_id, 'fake_session_id')
driver.window_handle
rescue WebDriver::Error::InvalidSessionIdError => e
expect(e.backtrace).not_to be_empty
end
end
end # WebDriver
end # Selenium

0 comments on commit 247bc2b

Please sign in to comment.