Skip to content

Commit

Permalink
Conditionally handle removed error types
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Apr 18, 2019
1 parent e137980 commit 6423f16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
28 changes: 22 additions & 6 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def no_such_window_error

private

def selenium_4?
defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)
end

def native_args(args)
args.map { |arg| arg.is_a?(Capybara::Selenium::Node) ? arg.native : arg }
end
Expand All @@ -278,15 +282,23 @@ def clear_browser_state
end

def clear_browser_state_errors
::Selenium::WebDriver.logger.suppress_deprecations do
[Selenium::WebDriver::Error::UnhandledError, Selenium::WebDriver::Error::UnknownError]
errors = [Selenium::WebDriver::Error::UnknownError]
unless selenium_4?
::Selenium::WebDriver.logger.suppress_deprecations do
errors << Selenium::WebDriver::Error::UnhandledError
end
end
errors
end

def unhandled_alert_errors
::Selenium::WebDriver.logger.suppress_deprecations do
[Selenium::WebDriver::Error::UnhandledAlertError, Selenium::WebDriver::Error::UnexpectedAlertOpenError]
errors = [Selenium::WebDriver::Error::UnexpectedAlertOpenError]
unless selenium_4?
::Selenium::WebDriver.logger.suppress_deprecations do
errors << Selenium::WebDriver::Error::UnhandledAlertError
end
end
errors
end

def delete_all_cookies
Expand Down Expand Up @@ -367,9 +379,13 @@ def find_modal(text: nil, **options)
end

def find_modal_errors
::Selenium::WebDriver.logger.suppress_deprecations do
[Selenium::WebDriver::Error::TimeoutError, Selenium::WebDriver::Error::TimeOutError]
errors = [Selenium::WebDriver::Error::TimeoutError]
unless selenium_4?
::Selenium::WebDriver.logger.suppress_deprecations do
errors << Selenium::WebDriver::Error::TimeOutError
end
end
errors
end

def silenced_unknown_error_message?(msg)
Expand Down
8 changes: 6 additions & 2 deletions lib/capybara/selenium/driver_specializations/chrome_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def delete_all_cookies
end

def cdp_unsupported_errors
::Selenium::WebDriver.logger.suppress_deprecations do
[Selenium::WebDriver::Error::UnhandledError, Selenium::WebDriver::Error::WebDriverError]
errors = [Selenium::WebDriver::Error::WebDriverError]
unless selenium_4?
::Selenium::WebDriver.logger.suppress_deprecations do
errors << Selenium::WebDriver::Error::UnhandledError
end
end
errors
end

def execute_cdp(cmd, params = {})
Expand Down

0 comments on commit 6423f16

Please sign in to comment.