Skip to content

Commit

Permalink
[rb] match other bindings by defaulting debugger_address and accept_i…
Browse files Browse the repository at this point in the history
…nsecure_certs to true for Firefox
  • Loading branch information
titusfortner committed Sep 26, 2022
1 parent 04e1dfc commit 58f5833
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/firefox/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class Options < WebDriver::Options
#

def initialize(log_level: nil, **opts)
@debugger_address = opts.delete(:debugger_address)
@debugger_address = opts.delete(:debugger_address) { true }
opts[:accept_insecure_certs] = true unless opts.key?(:accept_insecure_certs)

super(**opts)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def create_remote_driver(**opts)
def create_firefox_driver(**opts)
WebDriver::Firefox.path = ENV.fetch('FIREFOX_BINARY', nil) if ENV.key?('FIREFOX_BINARY')
options = opts.delete(:options) { WebDriver::Options.firefox }
options.debugger_address = true
options.web_socket_url = true
options.add_argument('--headless') if ENV['HEADLESS']
WebDriver::Driver.for(:firefox, options: options, **opts)
Expand Down
19 changes: 13 additions & 6 deletions rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def expect_request(body: nil, endpoint: nil)

it 'accepts provided Options as sole parameter' do
opts = {invalid: 'foobar', args: ['-f']}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "firefox", 'moz:firefoxOptions': opts}}})

expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true,
browserName: "firefox",
'moz:firefoxOptions': opts,
'moz:debuggerAddress': true}}})
expect { Driver.new(options: Options.new(**opts)) }.not_to raise_exception
end

Expand Down Expand Up @@ -99,9 +101,10 @@ def as_json(*)

it 'with Options instance' do
options = Options.new(args: ['-f'])
expect_request(body: {capabilities: {alwaysMatch: {browserName: "firefox",
'moz:firefoxOptions': {args: ['-f']}}}})

expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true,
browserName: "firefox",
'moz:firefoxOptions': {args: ['-f']},
'moz:debuggerAddress': true}}})
expect { Driver.new(capabilities: [options]) }.not_to raise_exception
end

Expand All @@ -113,8 +116,10 @@ def as_json(*)
end

it 'with Options instance and an instance of a custom object responding to #as_json' do
expect_request(body: {capabilities: {alwaysMatch: {browserName: "firefox",
expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true,
browserName: "firefox",
'moz:firefoxOptions': {},
'moz:debuggerAddress': true,
'company:key': 'value'}}})
expect { Driver.new(capabilities: [Options.new, as_json_object.new]) }.not_to raise_exception
end
Expand All @@ -123,7 +128,9 @@ def as_json(*)
capabilities = Remote::Capabilities.new(browser_name: 'firefox', invalid: 'foobar')
options = Options.new(args: ['-f'])
expect_request(body: {capabilities: {alwaysMatch: {browserName: "firefox", invalid: 'foobar',
acceptInsecureCerts: true,
'moz:firefoxOptions': {args: ['-f']},
'moz:debuggerAddress': true,
'company:key': 'value'}}})

expect { Driver.new(capabilities: [capabilities, options, as_json_object.new]) }.not_to raise_exception
Expand Down
10 changes: 8 additions & 2 deletions rb/spec/unit/selenium/webdriver/firefox/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,19 @@ module Firefox

describe '#as_json' do
it 'returns empty options by default' do
expect(options.as_json).to eq("browserName" => "firefox", "moz:firefoxOptions" => {})
expect(options.as_json).to eq("browserName" => "firefox",
"acceptInsecureCerts" => true,
"moz:firefoxOptions" => {},
"moz:debuggerAddress" => true)
end

it 'returns added options' do
options.add_option(:foo, 'bar')
options.add_option('foo:bar', {foo: 'bar'})
expect(options.as_json).to eq("browserName" => "firefox",
expect(options.as_json).to eq("acceptInsecureCerts" => true,
"browserName" => "firefox",
"foo:bar" => {"foo" => "bar"},
"moz:debuggerAddress" => true,
"moz:firefoxOptions" => {"foo" => "bar"})
end

Expand Down Expand Up @@ -241,6 +246,7 @@ module Firefox
'implicit' => 1},
'setWindowRect' => false,
'custom:options' => {'foo' => 'bar'},
'moz:debuggerAddress' => true,
key => {'args' => %w[foo bar],
'binary' => '/foo/bar',
'prefs' => {'foo' => 'bar'},
Expand Down

0 comments on commit 58f5833

Please sign in to comment.