Skip to content

Commit b2cfa18

Browse files
committed
add page url and source if some element was not found
1 parent 607d912 commit b2cfa18

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

rb/lib/selenium/webdriver/common/wait.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def initialize(opts = {})
3737
@timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT)
3838
@interval = opts.fetch(:interval, DEFAULT_INTERVAL)
3939
@message = opts[:message]
40-
@ignored = Array(opts[:ignore] || Error::NoSuchElementError)
40+
@message_provider = opts[:message_provider]
41+
@ignored = Array(opts[:ignore] || Error::NoSuchElementError)
4142
end
4243

4344
#
@@ -64,6 +65,8 @@ def until
6465

6566
msg = if @message
6667
@message.dup
68+
elsif @message_provider
69+
@message_provider.call
6770
else
6871
"timed out after #{@timeout} seconds"
6972
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module WebDriver
3232
# Safari returns "click intercepted" error instead of "element click intercepted"
3333
it 'raises if different element receives click', except: {browser: %i[safari safari_preview]} do
3434
driver.navigate.to url_for('click_tests/overlapping_elements.html')
35-
element = wait_for_element(id: 'contents')
35+
element = wait_for_element(id: 'contents', timeout: 10)
3636
expect { element.click }.to raise_error(Error::ElementClickInterceptedError)
3737
end
3838

rb/spec/integration/selenium/webdriver/spec_support/helpers.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ def wait_for_no_alert
8484
wait.until { driver.title }
8585
end
8686

87-
def wait_for_element(locator)
88-
wait = Wait.new(timeout: 25, ignore: Error::NoSuchElementError)
87+
def wait_for_element(locator, timeout = 25)
88+
wait = Wait.new(timeout: timeout, ignore: Error::NoSuchElementError, message_provider: lambda {
89+
url = "page url: #{driver.current_url};\n"
90+
source = "page source: #{driver.find_element(css: 'body').attribute('innerHTML')}\n"
91+
"could not find element #{locator} in #{timeout} seconds;\n#{url}#{source}"
92+
})
8993
wait.until { driver.find_element(locator) }
9094
end
9195

0 commit comments

Comments
 (0)