Skip to content

Commit 0745668

Browse files
authored
[ruby] Fix devtools version fallback (#11869)
Fix ruby devtools version fallback When using the feature added in #11827 that loads devtools methods possibly a version or two earlier than was necessary asked for, i was seeing this error: ``` NoMethodError: undefined method `get_targets' for nil:NilClass ./rb/lib/selenium/webdriver/devtools.rb:75:in `start_session' ./rb/lib/selenium/webdriver/devtools.rb:34:in `initialize' ./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `new' ./rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb:35:in `devtools' ``` because `target` was nil because it was trying to load a class named: ``` Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize} ``` which resolved to: ``` Selenium::DevTools::V112::Target ``` even though the falling-back code had already given up on 112 and loaded 111 instead. The simplest way to fix this seems to be ensure that `Selenium::DevTools.version` matches what was loaded. Also now there's a test
1 parent a9fd3cf commit 0745668

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

rb/lib/selenium/devtools.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def load_older_version
4040

4141
def load_old_version(version)
4242
require "selenium/devtools/v#{version}"
43+
self.version = version
4344
Kernel.warn "Using selenium-devtools version v#{version}, some features may not work as expected."
4445
end
4546
end

rb/spec/integration/selenium/webdriver/devtools_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ module WebDriver
2929
expect(driver.title).to eq('XHTML Test Page')
3030
end
3131

32+
context 'when the devtools version is too high' do
33+
let(:existing_devtools_version) { driver.send(:devtools_version) }
34+
let(:imaginary_devtools_version) { existing_devtools_version + 1 }
35+
36+
before do
37+
# set the devtools version to a newer one than exists
38+
allow(driver).to receive(:devtools_version).and_return(imaginary_devtools_version)
39+
40+
# forget what the actual version was
41+
Selenium::DevTools.remove_instance_variable(:@version)
42+
end
43+
44+
it 'can fall back to an older devtools if necessary' do
45+
expect { driver.devtools }
46+
.to output(
47+
a_string_matching(
48+
/
49+
Could\ not\ load\ selenium-devtools\ v#{imaginary_devtools_version}.\ Trying\ older\ versions.\n
50+
Using\ selenium-devtools\ version\ v\d+,\ some\ features\ may\ not\ work\ as\ expected.\n
51+
/x
52+
)
53+
).to_stderr
54+
end
55+
end
56+
3257
it 'supports events', except: {browser: :firefox,
3358
reason: 'https://bugzilla.mozilla.org/show_bug.cgi?id=1819965'} do
3459
expect { |block|

0 commit comments

Comments
 (0)