-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathselenium_error_patch.rb
More file actions
37 lines (34 loc) · 1.44 KB
/
selenium_error_patch.rb
File metadata and controls
37 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Taken from https://github.com/alphagov/forms-admin/commit/5ea98767d765a396ed06cf2cba8f9afb1b10fc0e#diff-c36c07a0c7f499b1b95634f9dce1a10ebf4d10a9dee872f39f746a9efa555ddbR1-R34
# Monkey patch for a specific intermittent Selenium error.
#
# Intermittently, Selenium/Chromedriver raises `Selenium::WebDriver::Error::UnknownError`
# with the message "Node with given id does not belong to the document".
# Capybara's automatic waiting/retrying mechanism doesn't catch it,
# leading to failure.
#
# We intercept the initialization of `UnknownError`. If the message matches this specific
# case, we raise a `StaleElementReferenceError` instead. This uses Capybara's
# retry logic which makes doesn't fail the test
#
# This can be removed once the following issue is resolved:
# https://github.com/teamcapybara/capybara/issues/2800
#
# taken from the following issue:
# https://github.com/teamcapybara/capybara/issues/2800#issuecomment-3049956982
# rubocop:disable Style/Alias, Style/IfUnlessModifier, Style/StringLiterals
module Selenium
module WebDriver
module Error
class UnknownError
alias_method :old_initialize, :initialize
def initialize(msg = nil)
if msg&.include?("Node with given id does not belong to the document")
raise StaleElementReferenceError, msg
end
old_initialize(msg)
end
end
end
end
end
# rubocop:enable Style/Alias, Style/IfUnlessModifier, Style/StringLiterals