Skip to content

Commit

Permalink
memoize error arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Apr 18, 2019
1 parent 2b2daf7 commit f3d83de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
67 changes: 34 additions & 33 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,27 @@ def quit
end

def invalid_element_errors
errors = [
::Selenium::WebDriver::Error::StaleElementReferenceError,
::Selenium::WebDriver::Error::ElementNotInteractableError,
::Selenium::WebDriver::Error::InvalidSelectorError, # Work around chromedriver go_back/go_forward race condition
::Selenium::WebDriver::Error::ElementClickInterceptedError,
::Selenium::WebDriver::Error::NoSuchElementError, # IE
::Selenium::WebDriver::Error::InvalidArgumentError # IE
]

unless selenium_4?
::Selenium::WebDriver.logger.suppress_deprecations do
errors.concat [
::Selenium::WebDriver::Error::UnhandledError,
::Selenium::WebDriver::Error::ElementNotVisibleError,
::Selenium::WebDriver::Error::InvalidElementStateError,
::Selenium::WebDriver::Error::ElementNotSelectableError
]
@invalid_element_errors ||= begin
[
::Selenium::WebDriver::Error::StaleElementReferenceError,
::Selenium::WebDriver::Error::ElementNotInteractableError,
::Selenium::WebDriver::Error::InvalidSelectorError, # Work around chromedriver go_back/go_forward race condition
::Selenium::WebDriver::Error::ElementClickInterceptedError,
::Selenium::WebDriver::Error::NoSuchElementError, # IE
::Selenium::WebDriver::Error::InvalidArgumentError # IE
].tap do |errors|
unless selenium_4?
::Selenium::WebDriver.logger.suppress_deprecations do
errors.concat [
::Selenium::WebDriver::Error::UnhandledError,
::Selenium::WebDriver::Error::ElementNotVisibleError,
::Selenium::WebDriver::Error::InvalidElementStateError,
::Selenium::WebDriver::Error::ElementNotSelectableError
]
end
end
end
end
errors
end

def no_such_window_error
Expand All @@ -282,23 +283,23 @@ def clear_browser_state
end

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

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

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

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

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

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

def execute_cdp(cmd, params = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/selenium/nodes/chrome_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def drag_to(element)
private

def file_errors
::Selenium::WebDriver.logger.suppress_deprecations do
@file_errors = ::Selenium::WebDriver.logger.suppress_deprecations do
[::Selenium::WebDriver::Error::ExpectedError]
end
end
Expand Down

0 comments on commit f3d83de

Please sign in to comment.