From 502ba0a5cc4618ca46b75222b1c297e62b1a571f Mon Sep 17 00:00:00 2001 From: aguspe Date: Fri, 23 Aug 2024 22:49:13 +0200 Subject: [PATCH 01/17] Fix session issue --- rb/lib/selenium/webdriver/remote/response.rb | 22 ++++++++++++++++++- .../selenium/webdriver/remote/response.rbs | 2 ++ .../selenium/webdriver/error_spec.rb | 9 +++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/response.rb b/rb/lib/selenium/webdriver/remote/response.rb index 453a04a2c0695..5e47b39b5e101 100644 --- a/rb/lib/selenium/webdriver/remote/response.rb +++ b/rb/lib/selenium/webdriver/remote/response.rb @@ -58,12 +58,30 @@ def assert_ok def add_cause(ex, error, backtrace) cause = Error::WebDriverError.new + backtrace = backtrace.is_a?(Array) ? backtrace_from_remote(backtrace) : backtrace 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'] + meth = frame['methodName'] + + class_name = frame['className'] + file = "#{class_name}(#{file})" if class_name + + meth = 'unknown' if meth.nil? || meth.empty? + + "[remote server] #{file}:#{line}:in `#{meth}'" + end + end + def process_error return unless self['value'].is_a?(Hash) @@ -73,7 +91,9 @@ def process_error self['value']['stacktrace'] ] end - end # Response + end + + # Response end # Remote end # WebDriver end # Selenium diff --git a/rb/sig/lib/selenium/webdriver/remote/response.rbs b/rb/sig/lib/selenium/webdriver/remote/response.rbs index c2955447fa993..29c806ff74283 100644 --- a/rb/sig/lib/selenium/webdriver/remote/response.rbs +++ b/rb/sig/lib/selenium/webdriver/remote/response.rbs @@ -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 diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 936b2186e6491..c9835a74f37ce 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -21,7 +21,7 @@ module Selenium module WebDriver - describe Error, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do + describe Error, exclusive: { bidi: false, reason: 'Not yet implemented with BiDi' } do it 'raises an appropriate error' do driver.navigate.to url_for('xhtmlTest.html') @@ -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 + Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', options: options + rescue WebDriver::Error::SessionNotCreatedError => e + expect(e.cause).to be_a(WebDriver::Error::WebDriverError) + end end end # WebDriver end # Selenium From c7fd4861ac9689544f78b8cd218e6f66a3a7f780 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 24 Aug 2024 07:53:30 +0200 Subject: [PATCH 02/17] Test ready --- rb/lib/selenium/webdriver/remote/response.rb | 2 +- rb/spec/integration/selenium/webdriver/error_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/response.rb b/rb/lib/selenium/webdriver/remote/response.rb index 5e47b39b5e101..799e2947395f1 100644 --- a/rb/lib/selenium/webdriver/remote/response.rb +++ b/rb/lib/selenium/webdriver/remote/response.rb @@ -58,7 +58,7 @@ def assert_ok def add_cause(ex, error, backtrace) cause = Error::WebDriverError.new - backtrace = backtrace.is_a?(Array) ? backtrace_from_remote(backtrace) : backtrace + backtrace = backtrace_from_remote(backtrace) if backtrace.is_a?(Array) cause.set_backtrace(backtrace) raise ex, cause: cause rescue Error.for_error(error) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index c9835a74f37ce..e61e72ebe8cb5 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -21,7 +21,7 @@ module Selenium module WebDriver - describe Error, exclusive: { bidi: false, reason: 'Not yet implemented with BiDi' } do + describe Error, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do it 'raises an appropriate error' do driver.navigate.to url_for('xhtmlTest.html') From f4dd6d65796f66e9158b9424d59267a6f9058273 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 24 Aug 2024 07:58:32 +0200 Subject: [PATCH 03/17] Fix identation --- rb/lib/selenium/webdriver/remote/response.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/response.rb b/rb/lib/selenium/webdriver/remote/response.rb index 799e2947395f1..426dfafb82925 100644 --- a/rb/lib/selenium/webdriver/remote/response.rb +++ b/rb/lib/selenium/webdriver/remote/response.rb @@ -91,9 +91,7 @@ def process_error self['value']['stacktrace'] ] end - end - - # Response + end # Response end # Remote end # WebDriver end # Selenium From 95603332db41d7b04d0d0f8390d9d44a5f0aa9d7 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 24 Aug 2024 09:40:03 +0200 Subject: [PATCH 04/17] Add only driver remote --- rb/lib/selenium/webdriver/remote/response.rb | 6 +++--- rb/spec/integration/selenium/webdriver/error_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/response.rb b/rb/lib/selenium/webdriver/remote/response.rb index 426dfafb82925..ce544b948964e 100644 --- a/rb/lib/selenium/webdriver/remote/response.rb +++ b/rb/lib/selenium/webdriver/remote/response.rb @@ -71,14 +71,14 @@ def backtrace_from_remote(server_trace) file = frame['fileName'] line = frame['lineNumber'] - meth = frame['methodName'] + method = frame['methodName'] class_name = frame['className'] file = "#{class_name}(#{file})" if class_name - meth = 'unknown' if meth.nil? || meth.empty? + method = 'unknown' if method.nil? || method.empty? - "[remote server] #{file}:#{line}:in `#{meth}'" + "[remote server] #{file}:#{line}:in `#{method}'" end end diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index e61e72ebe8cb5..2dce9e697cb31 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -48,7 +48,7 @@ module WebDriver expect(e.backtrace).not_to be_empty end - it 'has backtrace when using a remote server' do + it 'has backtrace when using a remote server', only: {driver: :remote} do options = Selenium::WebDriver::Options.chrome Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', options: options rescue WebDriver::Error::SessionNotCreatedError => e From 5479861f2924a8c714511781375b33b1367dd1bd Mon Sep 17 00:00:00 2001 From: aguspe Date: Sun, 25 Aug 2024 17:52:29 +0200 Subject: [PATCH 05/17] Produce session error --- rb/spec/integration/selenium/webdriver/error_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 2dce9e697cb31..430a3ce90c81d 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -48,8 +48,8 @@ module WebDriver expect(e.backtrace).not_to be_empty end - it 'has backtrace when using a remote server', only: {driver: :remote} do - options = Selenium::WebDriver::Options.chrome + 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 rescue WebDriver::Error::SessionNotCreatedError => e expect(e.cause).to be_a(WebDriver::Error::WebDriverError) From c53cf43df1d3485b691719a579f98a2274acee81 Mon Sep 17 00:00:00 2001 From: aguspe Date: Tue, 27 Aug 2024 20:25:16 +0200 Subject: [PATCH 06/17] Update test --- rb/spec/integration/selenium/webdriver/error_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 430a3ce90c81d..fefc734716322 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -48,11 +48,10 @@ module WebDriver 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 + it 'has backtrace when using a remote server', only: {driver: :remote} do + create_driver!(binary: '/path/to/nonexistent/chrome') rescue WebDriver::Error::SessionNotCreatedError => e - expect(e.cause).to be_a(WebDriver::Error::WebDriverError) + expect(e.backtrace).to be_a(WebDriver::Error::WebDriverError) end end end # WebDriver From 9c8998f63bbb7dda9df123eb9060603b70201165 Mon Sep 17 00:00:00 2001 From: aguspe Date: Tue, 27 Aug 2024 20:28:45 +0200 Subject: [PATCH 07/17] Update backtrace test --- rb/spec/integration/selenium/webdriver/error_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index fefc734716322..5e1694a206c0e 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -48,10 +48,10 @@ module WebDriver expect(e.backtrace).not_to be_empty end - it 'has backtrace when using a remote server', only: {driver: :remote} do + it 'has backtrace when using a remote server' do create_driver!(binary: '/path/to/nonexistent/chrome') rescue WebDriver::Error::SessionNotCreatedError => e - expect(e.backtrace).to be_a(WebDriver::Error::WebDriverError) + expect(e.backtrace).not_to be_empty end end end # WebDriver From 7d589f8b9e0b950066bd7b5c5d84d3e3851d46b7 Mon Sep 17 00:00:00 2001 From: aguspe Date: Tue, 27 Aug 2024 23:11:10 +0200 Subject: [PATCH 08/17] Update to exclude firefox --- rb/spec/integration/selenium/webdriver/error_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 5e1694a206c0e..23031f2c98ceb 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -48,7 +48,10 @@ module WebDriver expect(e.backtrace).not_to be_empty end - it 'has backtrace when using a remote server' do + it 'has backtrace when using a remote server', + except: {browser: :firefox, + reason: 'Firefox throws Selenium::WebDriver::Error::InvalidArgumentError'}, + only: {driver: :remote} do create_driver!(binary: '/path/to/nonexistent/chrome') rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty From 9b8551001308640fa98e60be9eca22b42e2f34fb Mon Sep 17 00:00:00 2001 From: aguspe Date: Fri, 30 Aug 2024 13:36:25 +0200 Subject: [PATCH 09/17] Force error to be risen so failure does not appear due to guard --- rb/spec/integration/selenium/webdriver/error_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 23031f2c98ceb..a02036490f9db 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -51,7 +51,12 @@ module WebDriver it 'has backtrace when using a remote server', except: {browser: :firefox, reason: 'Firefox throws Selenium::WebDriver::Error::InvalidArgumentError'}, - only: {driver: :remote} do + 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 + create_driver!(binary: '/path/to/nonexistent/chrome') rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty From 2a11e3e2d5b0a32755645a5036fff1ff6a23bf4e Mon Sep 17 00:00:00 2001 From: aguspe Date: Fri, 30 Aug 2024 16:24:55 +0200 Subject: [PATCH 10/17] Update error to no such element --- rb/spec/integration/selenium/webdriver/error_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index a02036490f9db..e59f50200920c 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -57,8 +57,8 @@ module WebDriver raise 'This error needs to be risen for the pending test not to fail on local drivers' end - create_driver!(binary: '/path/to/nonexistent/chrome') - rescue WebDriver::Error::SessionNotCreatedError => e + driver.find_element(id: 'nonexistent') + rescue WebDriver::Error::NoSuchElementError => e expect(e.backtrace).not_to be_empty end end From dc536924451f78c26d41af5e155a9f6c564564e0 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 31 Aug 2024 08:53:35 +0200 Subject: [PATCH 11/17] Remove firefox guard --- rb/spec/integration/selenium/webdriver/error_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index e59f50200920c..3d6adf1acf1c6 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -48,11 +48,8 @@ module WebDriver expect(e.backtrace).not_to be_empty end - it 'has backtrace when using a remote server', - except: {browser: :firefox, - reason: 'Firefox throws Selenium::WebDriver::Error::InvalidArgumentError'}, - only: {driver: :remote, - reason: 'This test should only apply to remote drivers'} do + 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 From 0566e395333e2691fb9e378972774b95c2ce778e Mon Sep 17 00:00:00 2001 From: aguspe Date: Mon, 2 Sep 2024 07:07:49 +0200 Subject: [PATCH 12/17] Go back to use session error for spec --- rb/spec/integration/selenium/webdriver/error_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 3d6adf1acf1c6..744155c629a15 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -54,8 +54,9 @@ module WebDriver raise 'This error needs to be risen for the pending test not to fail on local drivers' end + driver.quit driver.find_element(id: 'nonexistent') - rescue WebDriver::Error::NoSuchElementError => e + rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty end end From 8c29ae848776b41ccbbe08490566da085738152c Mon Sep 17 00:00:00 2001 From: aguspe Date: Tue, 3 Sep 2024 21:11:13 +0200 Subject: [PATCH 13/17] Update the test to cause session error without quit --- rb/spec/integration/selenium/webdriver/error_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 744155c629a15..31a77c49a0a34 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -54,8 +54,9 @@ module WebDriver raise 'This error needs to be risen for the pending test not to fail on local drivers' end - driver.quit - driver.find_element(id: 'nonexistent') + # Navigate away to simulate session inactivity + driver.execute_script('window.location.href = "about:blank";') + driver.url rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty end From 4a682cbb456fac24d95d17ff94c870dfe1139cab Mon Sep 17 00:00:00 2001 From: aguspe Date: Tue, 3 Sep 2024 21:35:21 +0200 Subject: [PATCH 14/17] Update to use title --- rb/spec/integration/selenium/webdriver/error_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 31a77c49a0a34..9294277acd81b 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -56,7 +56,7 @@ module WebDriver # Navigate away to simulate session inactivity driver.execute_script('window.location.href = "about:blank";') - driver.url + driver.title rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty end From d2ea6f8c059deff49a30309057454ee3adcbfdfa Mon Sep 17 00:00:00 2001 From: aguspe Date: Wed, 4 Sep 2024 21:27:32 +0200 Subject: [PATCH 15/17] Avoid window location inactivity --- rb/spec/integration/selenium/webdriver/error_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 9294277acd81b..5b0667d0e9e8d 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -56,7 +56,7 @@ module WebDriver # Navigate away to simulate session inactivity driver.execute_script('window.location.href = "about:blank";') - driver.title + driver.window_handle rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty end From a0d3f757b2a40a3e52a26065e88cbb5a5407202c Mon Sep 17 00:00:00 2001 From: aguspe Date: Fri, 6 Sep 2024 07:48:15 +0200 Subject: [PATCH 16/17] Update test to not use any script --- rb/spec/integration/selenium/webdriver/error_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index 5b0667d0e9e8d..f62f522e90234 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -54,8 +54,7 @@ module WebDriver raise 'This error needs to be risen for the pending test not to fail on local drivers' end - # Navigate away to simulate session inactivity - driver.execute_script('window.location.href = "about:blank";') + driver.send(:bridge).instance_variable_set(:@session_id, 'fake_session_id') driver.window_handle rescue WebDriver::Error::SessionNotCreatedError => e expect(e.backtrace).not_to be_empty From 02b49377dc09ef30cee051d75355f518f73f45a1 Mon Sep 17 00:00:00 2001 From: aguspe Date: Fri, 6 Sep 2024 11:14:17 +0200 Subject: [PATCH 17/17] Change test to capture the invalid session id error --- rb/spec/integration/selenium/webdriver/error_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/error_spec.rb b/rb/spec/integration/selenium/webdriver/error_spec.rb index f62f522e90234..7a72860c0340c 100644 --- a/rb/spec/integration/selenium/webdriver/error_spec.rb +++ b/rb/spec/integration/selenium/webdriver/error_spec.rb @@ -56,7 +56,7 @@ module WebDriver driver.send(:bridge).instance_variable_set(:@session_id, 'fake_session_id') driver.window_handle - rescue WebDriver::Error::SessionNotCreatedError => e + rescue WebDriver::Error::InvalidSessionIdError => e expect(e.backtrace).not_to be_empty end end