Skip to content

Commit

Permalink
[rb] fix: setting w3c: false throws error (SeleniumHQ#10918)
Browse files Browse the repository at this point in the history
* [ruby] fix: setting w3c: false throws error

* [ruby] replaced Capabilities class test with Options class test
  • Loading branch information
TamsilAmani authored Aug 3, 2022
1 parent 5e5f729 commit 5325315
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def initialize(url:, http_client: nil)
#

def create_session(capabilities)
check_chrome_w3c_false(capabilities)
response = execute(:new_session, {}, prepare_capabilities_payload(capabilities))

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

string
end

#
# Checks if w3c key is set to false and raises error for the same.
#
def check_chrome_w3c_false(capabilities)
return unless capabilities['browserName'] == 'chrome' && capabilities.key?('goog:chromeOptions')

capability = capabilities['goog:chromeOptions']
w3c = true

if capability.instance_of?(Hash)
raw_w3c = capability['w3c']
w3c = raw_w3c.nil? || raw_w3c
end

return if w3c

raise Error::WebDriverError, "Setting 'w3c: false' is not allowed.\n"\
"Please update to W3C Syntax: https://www"\
".selenium.dev/blog/2022/legacy-protocol-support/"
end
end # Bridge
end # Remote
end # WebDriver
Expand Down
5 changes: 5 additions & 0 deletions rb/spec/integration/selenium/webdriver/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ module WebDriver
end
end

it 'should raise error when w3c is false', exclusive: {browser: %i[chrome]} do
options = Selenium::WebDriver::Chrome::Options.new(w3c: false)
expect { Selenium::WebDriver.for :chrome, capabilities: options }.to raise_error(Error::WebDriverError)
end

it 'should get driver status' do
status = driver.status
expect(status).to include('ready', 'message')
Expand Down

0 comments on commit 5325315

Please sign in to comment.