Skip to content

Commit fb21cac

Browse files
committed
[rb] add links to documentation for error messages
1 parent dc9ab40 commit fb21cac

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

rb/lib/selenium/webdriver/common/error.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ def self.for_error(error)
3434
WebDriverError
3535
end
3636

37+
SUPPORT_MSG = 'For documentation on this error, please visit:'
38+
ERROR_URL = 'https://www.selenium.dev/documentation/webdriver/troubleshooting/errors'
39+
3740
class WebDriverError < StandardError; end
3841

3942
#
4043
# An element could not be located on the page using the given search parameters.
4144
#
4245

43-
class NoSuchElementError < WebDriverError; end
46+
class NoSuchElementError < WebDriverError
47+
def initialize(msg = '')
48+
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}#no-such-element-exception")
49+
end
50+
end
4451

4552
#
4653
# A command to switch to a frame could not be satisfied because the frame could not be found.
@@ -58,7 +65,11 @@ class UnknownCommandError < WebDriverError; end
5865
# A command failed because the referenced element is no longer attached to the DOM.
5966
#
6067

61-
class StaleElementReferenceError < WebDriverError; end
68+
class StaleElementReferenceError < WebDriverError
69+
def initialize(msg = '')
70+
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}#stale-element-reference-exception")
71+
end
72+
end
6273

6374
#
6475
# A command failed because the referenced shadow root is no longer attached to the DOM.
@@ -132,7 +143,11 @@ class ScriptTimeoutError < WebDriverError; end
132143
# Argument was an invalid selector.
133144
#
134145

135-
class InvalidSelectorError < WebDriverError; end
146+
class InvalidSelectorError < WebDriverError
147+
def initialize(msg = '')
148+
super("#{msg}; #{SUPPORT_MSG} #{ERROR_URL}#invalid-selector-exception")
149+
end
150+
end
136151

137152
#
138153
# A new session could not be created.

rb/spec/integration/selenium/webdriver/driver_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ module WebDriver
139139
expect(driver[:id1]).to be_a(WebDriver::Element)
140140
expect(driver[xpath: '//h1']).to be_a(WebDriver::Element)
141141
end
142+
143+
it 'raises if element not found' do
144+
driver.navigate.to url_for('xhtmlTest.html')
145+
expect {
146+
driver.find_element(id: 'not-there')
147+
}.to raise_error(Error::NoSuchElementError, /errors#no-such-element-exception/)
148+
end
149+
150+
it 'raises if invalid locator' do
151+
driver.navigate.to url_for('xhtmlTest.html')
152+
expect {
153+
driver.find_element(xpath: '*?//-')
154+
}.to raise_error(Error::InvalidSelectorError, /errors#invalid-selector-exception/)
155+
end
142156
end
143157

144158
describe 'many elements' do

rb/spec/integration/selenium/webdriver/element_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ module WebDriver
4040
expect { driver.find_element(id: 'other_contents').click }.to raise_error(Error::ElementClickInterceptedError)
4141
end
4242

43+
it 'raises if element stale' do
44+
driver.navigate.to url_for('formPage.html')
45+
button = driver.find_element(id: 'imageButton')
46+
driver.navigate.refresh
47+
48+
expect { button.click }.to raise_exception(Error::StaleElementReferenceError,
49+
/errors#stale-element-reference-exception/)
50+
51+
reset_driver!(time: 1) if %i[safari safari_preview].include? GlobalTestEnv.browser
52+
end
53+
4354
describe '#submit' do
4455
it 'valid submit button' do
4556
driver.navigate.to url_for('formPage.html')

0 commit comments

Comments
 (0)