Skip to content

Commit

Permalink
Deprecate errors which are not compliant to the specification
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Apr 17, 2019
1 parent 95ccb82 commit 6f6af6e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
65 changes: 56 additions & 9 deletions rb/lib/selenium/webdriver/common/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module Selenium
module WebDriver
module Error
module Error # rubocop:disable Metrics/ModuleLength

#
# Returns exception from code (Integer - OSS, String - W3C).
Expand All @@ -31,7 +31,7 @@ def self.for_code(code)
when nil, 0
nil
when Integer
ERRORS.fetch(code)
Object.const_get(ERRORS.fetch(code).to_s)
when String
klass_name = code.split(' ').map(&:capitalize).join.sub(/Error$/, '')
const_get("#{klass_name}Error", false)
Expand Down Expand Up @@ -272,15 +272,15 @@ class ElementClickInterceptedError < WebDriverError; end
class UnsupportedOperationError < WebDriverError; end

# Aliases for OSS dialect.
ScriptTimeoutError = ScriptTimeOutError
TimeoutError = TimeOutError
NoAlertOpenError = NoAlertPresentError
ScriptTimeoutError = Class.new(ScriptTimeOutError)
TimeoutError = Class.new(TimeOutError)
NoAlertOpenError = Class.new(NoAlertPresentError)

# Aliases for backwards compatibility.
ObsoleteElementError = StaleElementReferenceError
UnhandledError = UnknownError
UnexpectedJavascriptError = JavascriptError
ElementNotDisplayedError = ElementNotVisibleError
ObsoleteElementError = Class.new(StaleElementReferenceError)
UnhandledError = Class.new(UnknownError)
UnexpectedJavascriptError = Class.new(JavascriptError)
ElementNotDisplayedError = Class.new(ElementNotVisibleError)

#
# @api private
Expand Down Expand Up @@ -331,6 +331,53 @@ class UnsupportedOperationError < WebDriverError; end
63 => UnableToCaptureScreenError
}.freeze

DEPRECATED_ERRORS = {
IndexOutOfBoundsError: nil,
NoCollectionError: nil,
NoStringError: nil,
NoStringLengthError: nil,
NoStringWrapperError: nil,
NoSuchDriverError: nil,
ElementNotVisibleError: ElementNotInteractableError,
InvalidElementStateError: ElementNotInteractableError,
ElementNotSelectableError: ElementNotInteractableError,
ExpectedError: nil,
NoSuchDocumentError: nil,
NoScriptResultError: nil,
XPathLookupError: InvalidSelectorError,
NoSuchCollectionError: nil,
UnhandledAlertError: UnexpectedAlertOpenError,
NoAlertPresentError: NoSuchAlertError,
NoAlertOpenError: NoSuchAlertError,
ScriptTimeOutError: ScriptTimeoutError,
InvalidElementCoordinatesError: nil,
IMENotAvailableError: nil,
IMEEngineActivationFailedError: nil,
InvalidXpathSelectorError: InvalidSelectorError,
InvalidXpathSelectorReturnTyperError: InvalidSelectorError,
TimeOutError: TimeoutError,
ObsoleteElementError: StaleElementReferenceError,
UnhandledError: UnknownError,
UnexpectedJavascriptError: JavascriptError,
ElementNotDisplayedError: ElementNotInteractableError
}.freeze

DEPRECATED_ERRORS.keys.each do |oss_error|
remove_const oss_error
end

def self.const_missing(const_name)
super unless DEPRECATED_ERRORS.key?(const_name)
if DEPRECATED_ERRORS[const_name]
WebDriver.logger.deprecate("Selenium::WebDriver::Error::#{const_name}",
"#{DEPRECATED_ERRORS[const_name]} (ensure the driver supports W3C WebDriver specification)")
DEPRECATED_ERRORS[const_name]
else
WebDriver.logger.deprecate("Selenium::WebDriver::Error::#{const_name}")
WebDriverError
end
end

end # Error
end # WebDriver
end # Selenium
10 changes: 1 addition & 9 deletions rb/spec/integration/selenium/webdriver/target_locator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,7 @@ module WebDriver
context 'unhandled alert error', except: {browser: %i[safari safari_preview]} do
after { reset_driver! }

it 'raises an UnhandledAlertError if an alert has not been dealt with', except: {browser: %i[ie firefox]} do
driver.navigate.to url_for('alerts.html')
driver.find_element(id: 'alert').click
wait_for_alert

expect { driver.title }.to raise_error(Selenium::WebDriver::Error::UnhandledAlertError)
end

it 'raises an UnexpectedAlertOpenError if an alert has not been dealt with', only: {browser: %i[ie firefox]} do
it 'raises an UnexpectedAlertOpenError if an alert has not been dealt with', only: {browser: %i[chrome ie firefox]} do
driver.navigate.to url_for('alerts.html')
driver.find_element(id: 'alert').click
wait_for_alert
Expand Down

0 comments on commit 6f6af6e

Please sign in to comment.