Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Add URLs constant to update error messages #14174

Merged
merged 12 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions rb/lib/selenium/webdriver/common/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,29 @@ def self.for_error(error)
SUPPORT_MSG = 'For documentation on this error, please visit:'
ERROR_URL = 'https://www.selenium.dev/documentation/webdriver/troubleshooting/errors'

class WebDriverError < StandardError; end
URLS = {
NoSuchElementError: "#{ERROR_URL}#no-such-element-exception",
StaleElementReferenceError: "#{ERROR_URL}#stale-element-reference-exception",
InvalidSelectorError: "#{ERROR_URL}#invalid-selector-exception",
NoSuchDriverError: "#{ERROR_URL}/driver_location"
}.freeze

class WebDriverError < StandardError
def initialize(msg = '')
# Remove this conditional when all the error pages have been documented
super(URLS[class_name] ? "#{msg}; #{SUPPORT_MSG} #{URLS[class_name]}" : msg)
end

def class_name
self.class.name&.split('::')&.last&.to_sym
end
end

#
# An element could not be located on the page using the given search parameters.
#

class NoSuchElementError < WebDriverError
def initialize(msg = '')
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}#no-such-element-exception")
end
end
class NoSuchElementError < WebDriverError; end

#
# A command to switch to a frame could not be satisfied because the frame could not be found.
Expand All @@ -67,7 +79,7 @@ class UnknownCommandError < WebDriverError; end

class StaleElementReferenceError < WebDriverError
def initialize(msg = '')
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}#stale-element-reference-exception")
super("#{msg}; #{SUPPORT_MSG} #{URLS[:StaleElementReferenceError]}")
end
end

Expand Down Expand Up @@ -143,11 +155,7 @@ class ScriptTimeoutError < WebDriverError; end
# Argument was an invalid selector.
#

class InvalidSelectorError < WebDriverError
def initialize(msg = '')
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}#invalid-selector-exception")
end
end
class InvalidSelectorError < WebDriverError; end

#
# A new session could not be created.
Expand Down Expand Up @@ -232,11 +240,7 @@ class UnsupportedOperationError < WebDriverError; end
# Indicates that driver was not specified and could not be located.
#

class NoSuchDriverError < WebDriverError
def initialize(msg = '')
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}/driver_location")
end
end
class NoSuchDriverError < WebDriverError; end
end # Error
end # WebDriver
end # Selenium
3 changes: 3 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/error.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module Selenium

ERROR_URL: String

URLS: Hash[Symbol, String]

class WebDriverError < StandardError
def class_name: -> Symbol?
end

class NoSuchElementError < WebDriverError
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module WebDriver

expect {
driver.find_element(id: 'nonexistent')
}.to raise_error(WebDriver::Error::NoSuchElementError)
}.to raise_error(WebDriver::Error::NoSuchElementError, /#no-such-element-exception/)
end
end
end # WebDriver
Expand Down
3 changes: 1 addition & 2 deletions rb/spec/unit/selenium/webdriver/common/driver_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ module WebDriver
expect {
described_class.new(Options.chrome, Service.chrome).driver_path
}.to output(/Exception occurred: this error/).to_stderr_from_any_process
}.to raise_error(WebDriver::Error::NoSuchDriverError,
/Unable to obtain chromedriver; For documentation on this error/)
}.to raise_error(WebDriver::Error::NoSuchDriverError, /driver_location/)
end

it 'creates arguments' do
Expand Down
Loading