Skip to content

Commit 994ab87

Browse files
committed
[rb] move w3c checks to Options class
1 parent cd3e9ae commit 994ab87

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

rb/lib/selenium/webdriver/chrome/options.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ def process_browser_options(browser_options)
227227

228228
options = browser_options[self.class::KEY]
229229
options['binary'] ||= binary_path if binary_path
230+
231+
check_w3c(options[:w3c]) if options.key?(:w3c)
232+
230233
if @profile
231234
options['args'] ||= []
232235
options['args'] << "--user-data-dir=#{@profile.directory}"
@@ -237,6 +240,17 @@ def process_browser_options(browser_options)
237240
options['extensions'] = @encoded_extensions + @extensions.map { |ext| encode_extension(ext) }
238241
end
239242

243+
def check_w3c(w3c)
244+
if w3c
245+
WebDriver.logger.warn("Setting 'w3c: true' is redundant and will no longer be allowed", id: :w3c)
246+
return
247+
end
248+
249+
raise Error::InvalidArgumentError,
250+
"Setting 'w3c: false' is not allowed.\n" \
251+
"Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/"
252+
end
253+
240254
def binary_path
241255
Chrome.path
242256
end

rb/lib/selenium/webdriver/remote/bridge.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def initialize(url:, http_client: nil)
4949
#
5050

5151
def create_session(capabilities)
52-
check_chrome_w3c_false(capabilities)
5352
response = execute(:new_session, {}, prepare_capabilities_payload(capabilities))
5453

5554
@session_id = response['sessionId']
@@ -667,27 +666,6 @@ def escape_css(string)
667666

668667
string
669668
end
670-
671-
#
672-
# Checks if w3c key is set to false and raises error for the same.
673-
#
674-
def check_chrome_w3c_false(capabilities)
675-
return unless capabilities['browserName'] == 'chrome' && capabilities.key?('goog:chromeOptions')
676-
677-
capability = capabilities['goog:chromeOptions']
678-
w3c = true
679-
680-
if capability.instance_of?(Hash)
681-
raw_w3c = capability['w3c']
682-
w3c = raw_w3c.nil? || raw_w3c
683-
end
684-
685-
return if w3c
686-
687-
raise Error::WebDriverError, "Setting 'w3c: false' is not allowed.\n"\
688-
"Please update to W3C Syntax: https://www"\
689-
".selenium.dev/blog/2022/legacy-protocol-support/"
690-
end
691669
end # Bridge
692670
end # Remote
693671
end # WebDriver

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ module WebDriver
3939
end
4040
end
4141

42-
it 'should raise error when w3c is false', exclusive: {browser: %i[chrome]} do
43-
options = Selenium::WebDriver::Chrome::Options.new(w3c: false)
44-
expect { Selenium::WebDriver.for :chrome, capabilities: options }.to raise_error(Error::WebDriverError)
45-
end
46-
4742
it 'should get driver status' do
4843
status = driver.status
4944
expect(status).to include('ready', 'message')

rb/spec/unit/selenium/webdriver/chrome/options_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ module Chrome
247247
expect(options.as_json).to eq("browserName" => "chrome", "goog:chromeOptions" => {})
248248
end
249249

250+
it 'should raise error when w3c is false' do
251+
options.add_option(:w3c, false)
252+
expect { options.as_json }.to raise_error(Error::InvalidArgumentError)
253+
end
254+
255+
it 'should raise error when w3c is true' do
256+
msg = /WARN Selenium \[:w3c\]/
257+
options.add_option(:w3c, true)
258+
expect { options.as_json }.to output(msg).to_stdout_from_any_process
259+
end
260+
250261
it 'returns added options' do
251262
options.add_option(:foo, 'bar')
252263
options.add_option('foo:bar', {foo: 'bar'})

rb/spec/unit/selenium/webdriver/edge/options_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ module Edge
203203
expect(options.as_json).to eq("browserName" => "MicrosoftEdge", "ms:edgeOptions" => {})
204204
end
205205

206+
it 'should raise error when w3c is false' do
207+
options.add_option(:w3c, false)
208+
expect { options.as_json }.to raise_error(Error::InvalidArgumentError)
209+
end
210+
211+
it 'should raise error when w3c is true' do
212+
msg = /WARN Selenium \[:w3c\]/
213+
options.add_option(:w3c, true)
214+
expect { options.as_json }.to output(msg).to_stdout_from_any_process
215+
end
216+
206217
it 'returns added options' do
207218
options.add_option(:foo, 'bar')
208219
options.add_option('foo:bar', {foo: 'bar'})

0 commit comments

Comments
 (0)