diff --git a/rb/lib/selenium/webdriver/chrome/driver.rb b/rb/lib/selenium/webdriver/chrome/driver.rb index 8fa4b1bb78365..46a0b1e321a91 100644 --- a/rb/lib/selenium/webdriver/chrome/driver.rb +++ b/rb/lib/selenium/webdriver/chrome/driver.rb @@ -30,8 +30,8 @@ module Chrome class Driver < Chromium::Driver include LocalDriver - def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts) - caps, url = initialize_local_driver(capabilities, options, service, url) + def initialize(options: nil, service: nil, url: nil, **opts) + caps, url = initialize_local_driver(options, service, url) super(caps: caps, url: url, **opts) end diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index d03fe939d19dc..a917a2fde07c3 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -318,18 +318,6 @@ def create_bridge(caps:, url:, http_client: nil) end end - def generate_capabilities(capabilities) - Array(capabilities).map { |cap| - if cap.is_a? Symbol - cap = WebDriver::Options.send(cap) - elsif !cap.respond_to? :as_json - msg = ":capabilities parameter only accepts objects responding to #as_json which #{cap.class} does not" - raise ArgumentError, msg - end - cap.as_json - }.inject(:merge) - end - def service_url(service) @service_manager = service.launch @service_manager.uri diff --git a/rb/lib/selenium/webdriver/common/local_driver.rb b/rb/lib/selenium/webdriver/common/local_driver.rb index 79f22afc9d62f..f2f48d3c5aba8 100644 --- a/rb/lib/selenium/webdriver/common/local_driver.rb +++ b/rb/lib/selenium/webdriver/common/local_driver.rb @@ -20,35 +20,26 @@ module Selenium module WebDriver module LocalDriver - def initialize_local_driver(capabilities, options, service, url) + def initialize_local_driver(options, service, url) raise ArgumentError, "Can't initialize #{self.class} with :url" if url service ||= Service.send(browser) - caps = process_options(options, capabilities, service) + caps = process_options(options, service) url = service_url(service) [caps, url] end - def process_options(options, capabilities, service) + def process_options(options, service) default_options = Options.send(browser) + options ||= default_options - if options && capabilities - msg = "Don't use both :options and :capabilities when initializing #{self.class}, prefer :options" - raise ArgumentError, msg - elsif options && !options.is_a?(default_options.class) + unless options.is_a?(default_options.class) raise ArgumentError, ":options must be an instance of #{default_options.class}" - elsif capabilities - WebDriver.logger.deprecate("The :capabilities parameter for #{self.class}", - "an :options parameter instead to create a local #{self.class}", - id: :capabilities) - service.executable_path ||= WebDriver::DriverFinder.path(capabilities, service.class) - generate_capabilities(capabilities) - else - options ||= default_options - service.executable_path ||= WebDriver::DriverFinder.path(options, service.class) - options.as_json end + + service.executable_path ||= WebDriver::DriverFinder.path(options, service.class) + options.as_json end end end diff --git a/rb/lib/selenium/webdriver/edge/driver.rb b/rb/lib/selenium/webdriver/edge/driver.rb index 839ba54976992..7ab091b9d5f6f 100644 --- a/rb/lib/selenium/webdriver/edge/driver.rb +++ b/rb/lib/selenium/webdriver/edge/driver.rb @@ -30,8 +30,8 @@ module Edge class Driver < Chromium::Driver include LocalDriver - def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts) - caps, url = initialize_local_driver(capabilities, options, service, url) + def initialize(options: nil, service: nil, url: nil, **opts) + caps, url = initialize_local_driver(options, service, url) super(caps: caps, url: url, **opts) end diff --git a/rb/lib/selenium/webdriver/firefox/driver.rb b/rb/lib/selenium/webdriver/firefox/driver.rb index 093918d7a20b2..717eea5ba711c 100644 --- a/rb/lib/selenium/webdriver/firefox/driver.rb +++ b/rb/lib/selenium/webdriver/firefox/driver.rb @@ -38,8 +38,8 @@ class Driver < WebDriver::Driver include LocalDriver - def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts) - caps, url = initialize_local_driver(capabilities, options, service, url) + def initialize(options: nil, service: nil, url: nil, **opts) + caps, url = initialize_local_driver(options, service, url) super(caps: caps, url: url, **opts) end diff --git a/rb/lib/selenium/webdriver/ie/driver.rb b/rb/lib/selenium/webdriver/ie/driver.rb index 4bb24f9bcde6b..88295e92a82cc 100644 --- a/rb/lib/selenium/webdriver/ie/driver.rb +++ b/rb/lib/selenium/webdriver/ie/driver.rb @@ -31,8 +31,8 @@ class Driver < WebDriver::Driver include LocalDriver - def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts) - caps, url = initialize_local_driver(capabilities, options, service, url) + def initialize(options: nil, service: nil, url: nil, **opts) + caps, url = initialize_local_driver(options, service, url) super(caps: caps, url: url, **opts) end diff --git a/rb/lib/selenium/webdriver/remote/driver.rb b/rb/lib/selenium/webdriver/remote/driver.rb index 24ba5fc788573..2a6b55697a523 100644 --- a/rb/lib/selenium/webdriver/remote/driver.rb +++ b/rb/lib/selenium/webdriver/remote/driver.rb @@ -60,6 +60,18 @@ def process_options(options, capabilities) end options ? options.as_json : generate_capabilities(capabilities) end + + def generate_capabilities(capabilities) + Array(capabilities).map { |cap| + if cap.is_a? Symbol + cap = WebDriver::Options.send(cap) + elsif !cap.respond_to? :as_json + msg = ":capabilities parameter only accepts objects responding to #as_json which #{cap.class} does not" + raise ArgumentError, msg + end + cap.as_json + }.inject(:merge) + end end # Driver end # Remote end # WebDriver diff --git a/rb/lib/selenium/webdriver/safari/driver.rb b/rb/lib/selenium/webdriver/safari/driver.rb index e98179fad966a..cc6c04a3b5be4 100644 --- a/rb/lib/selenium/webdriver/safari/driver.rb +++ b/rb/lib/selenium/webdriver/safari/driver.rb @@ -32,8 +32,8 @@ class Driver < WebDriver::Driver include LocalDriver - def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts) - caps, url = initialize_local_driver(capabilities, options, service, url) + def initialize(options: nil, service: nil, url: nil, **opts) + caps, url = initialize_local_driver(options, service, url) super(caps: caps, url: url, **opts) end diff --git a/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb index 9d30ea478490e..d81dc0080bcc3 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb @@ -88,116 +88,6 @@ def expect_request(body: nil, endpoint: nil) described_class.new(options: Options.firefox) }.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Chrome::Options') end - - it 'does not allow both Options and Capabilities' do - msg = "Don't use both :options and :capabilities when initializing Selenium::WebDriver::Chrome::Driver, " \ - 'prefer :options' - expect { - described_class.new(options: Options.new, capabilities: Remote::Capabilities.new(browser_name: 'chrome')) - }.to raise_exception(ArgumentError, msg) - end - - context 'with :capabilities' do - before { allow(DriverFinder).to receive(:path) } - - it 'accepts value as a Symbol' do - expect_request - expect { described_class.new(capabilities: :chrome) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Snake Case as Symbols' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', invalid: 'foobar'}}}) - - expect { - capabilities = Remote::Capabilities.new(browser_name: 'chrome', invalid: 'foobar') - expect { described_class.new(capabilities: capabilities) }.not_to raise_exception - }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Symbols' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', invalid: 'foobar'}}}) - - expect { - capabilities = Remote::Capabilities.new(browserName: 'chrome', invalid: 'foobar') - expect { described_class.new(capabilities: capabilities) }.not_to raise_exception - }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Strings' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', invalid: 'foobar'}}}) - - expect { - capabilities = Remote::Capabilities.new('browserName' => 'chrome', 'invalid' => 'foobar') - expect { described_class.new(capabilities: capabilities) }.not_to raise_exception - }.to have_deprecated(:capabilities) - end - - context 'when value is an Array' do - let(:as_json_object) do - Class.new do - def as_json(*) - {'company:key': 'value'} - end - end - end - - it 'with Options instance' do - options = Options.new(args: ['-f']) - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', - 'goog:chromeOptions': {args: ['-f']}}}}) - - expect { - expect { - described_class.new(capabilities: [options]) - }.not_to raise_exception - }.to have_deprecated(:capabilities) - end - - it 'with Options instance with profile' do - profile = Profile.new.tap(&:layout_on_disk) - allow(profile).to receive(:directory).and_return('PROF_DIR') - options = Options.new(profile: profile) - - expect_request(body: {capabilities: - {alwaysMatch: {browserName: 'chrome', - 'goog:chromeOptions': {args: ['--user-data-dir=PROF_DIR']}}}}) - - expect { - expect { - described_class.new(capabilities: [options]) - }.not_to raise_exception - }.to have_deprecated(:capabilities) - end - - it 'with Capabilities instance' do - capabilities = Remote::Capabilities.new(browser_name: 'chrome', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: [capabilities]) }.to have_deprecated(:capabilities) - end - - it 'with Options instance and an instance of a custom object responding to #as_json' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', - 'goog:chromeOptions': {}, - 'company:key': 'value'}}}) - expect { - described_class.new(capabilities: [Options.new, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - - it 'with Options instance, Capabilities instance and instance of a custom object responding to #as_json' do - capabilities = Remote::Capabilities.new(browser_name: 'chrome', invalid: 'foobar') - options = Options.new(args: ['-f']) - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'chrome', invalid: 'foobar', - 'goog:chromeOptions': {args: ['-f']}, - 'company:key': 'value'}}}) - - expect { - described_class.new(capabilities: [capabilities, options, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - end - end end end # Chrome end # WebDriver diff --git a/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb b/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb index 02447b516706d..bbf3fd7219a17 100644 --- a/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb @@ -94,105 +94,6 @@ def expect_request(body: nil, endpoint: nil) described_class.new(options: Options.chrome) }.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Edge::Options') end - - it 'does not allow both Options and Capabilities' do - msg = "Don't use both :options and :capabilities when initializing Selenium::WebDriver::Edge::Driver, " \ - 'prefer :options' - expect { - described_class.new(options: Options.new, capabilities: Remote::Capabilities.new(browser_name: 'msedge')) - }.to raise_exception(ArgumentError, msg) - end - - context 'with :capabilities' do - before { allow(DriverFinder).to receive(:path) } - - it 'accepts value as a Symbol' do - expect_request - expect { - expect { - described_class.new(capabilities: :edge) - }.to have_deprecated(:capabilities) - }.not_to raise_exception - end - - it 'accepts constructed Capabilities with Snake Case as Symbols' do - capabilities = Remote::Capabilities.new(browser_name: 'MicrosoftEdge', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Symbols' do - capabilities = Remote::Capabilities.new(browserName: 'MicrosoftEdge', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Strings' do - capabilities = Remote::Capabilities.new('browserName' => 'MicrosoftEdge', 'invalid' => 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - context 'when value is an Array' do - let(:as_json_object) do - Class.new do - def as_json(*) - {'company:key': 'value'} - end - end - end - - it 'with Options instance' do - options = Options.new(args: ['-f']) - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', - 'ms:edgeOptions': {args: ['-f']}}}}) - - expect { described_class.new(capabilities: [options]) }.to have_deprecated(:capabilities) - end - - it 'with Options instance with profile' do - profile = Profile.new.tap(&:layout_on_disk) - allow(profile).to receive(:directory).and_return('PROF_DIR') - options = Options.new(profile: profile) - expect_request(body: {capabilities: - {alwaysMatch: {browserName: 'MicrosoftEdge', - 'ms:edgeOptions': {args: ['--user-data-dir=PROF_DIR']}}}}) - - expect { described_class.new(capabilities: [options]) }.to have_deprecated(:capabilities) - end - - it 'with Capabilities instance' do - capabilities = Remote::Capabilities.new(browser_name: 'MicrosoftEdge', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: [capabilities]) }.to have_deprecated(:capabilities) - end - - it 'with Options instance and an instance of a custom object responding to #as_json' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', - 'ms:edgeOptions': {}, - 'company:key': 'value'}}}) - expect { - described_class.new(capabilities: [Options.new, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - - it 'with Options instance, Capabilities instance and instance of a custom object responding to #as_json' do - capabilities = Remote::Capabilities.new(browser_name: 'MicrosoftEdge', invalid: 'foobar') - options = Options.new(args: ['-f']) - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', invalid: 'foobar', - 'ms:edgeOptions': {args: ['-f']}, - 'company:key': 'value'}}}) - - expect { - described_class.new(capabilities: [capabilities, options, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - end - end end end # Chrome end # WebDriver diff --git a/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb index 46851b56ddf15..e04a0de6ab72f 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb @@ -92,95 +92,6 @@ def expect_request(body: nil, endpoint: nil) described_class.new(options: Options.chrome) }.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Firefox::Options') end - - it 'does not allow both Options and Capabilities' do - msg = "Don't use both :options and :capabilities when initializing Selenium::WebDriver::Firefox::Driver, " \ - 'prefer :options' - expect { - described_class.new(options: Options.new, capabilities: Remote::Capabilities.new(browser_name: 'firefox')) - }.to raise_exception(ArgumentError, msg) - end - - context 'with :capabilities' do - before { allow(DriverFinder).to receive(:path) } - - it 'accepts value as a Symbol' do - expect_request - expect { described_class.new(capabilities: :firefox) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Snake Case as Symbols' do - capabilities = Remote::Capabilities.new(browser_name: 'firefox', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'firefox', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Symbols' do - capabilities = Remote::Capabilities.new(browserName: 'firefox', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'firefox', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Strings' do - capabilities = Remote::Capabilities.new('browserName' => 'firefox', 'invalid' => 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'firefox', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - context 'when value is an Array' do - let(:as_json_object) do - Class.new do - def as_json(*) - {'company:key': 'value'} - end - end - end - - it 'with Options instance' do - options = Options.new(args: ['-f']) - expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true, - browserName: 'firefox', - 'moz:firefoxOptions': {args: ['-f']}, - 'moz:debuggerAddress': true}}}) - expect { described_class.new(capabilities: [options]) }.to have_deprecated(:capabilities) - end - - it 'with Capabilities instance' do - capabilities = Remote::Capabilities.new(browser_name: 'firefox', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'firefox', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: [capabilities]) }.to have_deprecated(:capabilities) - end - - it 'with Options instance and an instance of a custom object responding to #as_json' do - expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true, - browserName: 'firefox', - 'moz:firefoxOptions': {}, - 'moz:debuggerAddress': true, - 'company:key': 'value'}}}) - expect { - described_class.new(capabilities: [Options.new, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - - it 'with Options instance, Capabilities instance and instance of a custom object responding to #as_json' do - 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 { - described_class.new(capabilities: [capabilities, options, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - end - end end end # Firefox end # WebDriver diff --git a/rb/spec/unit/selenium/webdriver/ie/driver_spec.rb b/rb/spec/unit/selenium/webdriver/ie/driver_spec.rb index 9921a9a433e10..d3698eb13bc26 100644 --- a/rb/spec/unit/selenium/webdriver/ie/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/ie/driver_spec.rb @@ -89,97 +89,6 @@ def expect_request(body: nil, endpoint: nil) described_class.new(options: Options.chrome) }.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::IE::Options') end - - it 'does not allow both Options and Capabilities' do - msg = "Don't use both :options and :capabilities when initializing Selenium::WebDriver::IE::Driver, " \ - 'prefer :options' - expect { - described_class.new(options: Options.new, - capabilities: Remote::Capabilities.new(browser_name: 'internet explorer')) - }.to raise_exception(ArgumentError, msg) - end - - context 'with :capabilities' do - before { allow(DriverFinder).to receive(:path) } - - it 'accepts value as a Symbol' do - expect_request - expect { described_class.new(capabilities: :ie) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Snake Case as Symbols' do - capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Symbols' do - capabilities = Remote::Capabilities.new(browserName: 'internet explorer', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Strings' do - capabilities = Remote::Capabilities.new('browserName' => 'internet explorer', 'invalid' => 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - context 'when value is an Array' do - let(:as_json_object) do - Class.new do - def as_json(*) - {'company:key': 'value'} - end - end - end - - it 'with Options instance' do - browser_opts = {initial_browser_url: 'http://selenium.dev'} - expect_request(body: {capabilities: {alwaysMatch: {'browserName' => 'internet explorer', - 'se:ieOptions' => {'initialBrowserUrl' => 'http://selenium.dev', - 'nativeEvents' => true}}}}) - - expect { - described_class.new(capabilities: [Options.new(**browser_opts)]) - }.to have_deprecated(:capabilities) - end - - it 'with Capabilities instance' do - capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: [capabilities]) }.to have_deprecated(:capabilities) - end - - it 'with Options instance and an instance of a custom object responding to #as_json' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer', - 'se:ieOptions': {nativeEvents: true}, - 'company:key': 'value'}}}) - - expect { - described_class.new(capabilities: [Options.new, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - - it 'with Options instance, Capabilities instance and instance of a custom object responding to #as_json' do - capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar') - options = Options.new(initial_browser_url: 'http://selenium.dev') - expect_request(body: {capabilities: {alwaysMatch: {'browserName' => 'internet explorer', - 'invalid' => 'foobar', - 'se:ieOptions' => {'initialBrowserUrl' => 'http://selenium.dev', - 'nativeEvents' => true}, - 'company:key' => 'value'}}}) - - expect { - described_class.new(capabilities: [capabilities, options, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - end - end end end # IE end # WebDriver diff --git a/rb/spec/unit/selenium/webdriver/safari/driver_spec.rb b/rb/spec/unit/selenium/webdriver/safari/driver_spec.rb index 4da0e7884da05..f88f8cacdf483 100644 --- a/rb/spec/unit/selenium/webdriver/safari/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/safari/driver_spec.rb @@ -87,93 +87,6 @@ def expect_request(body: nil, endpoint: nil) described_class.new(options: Options.chrome) }.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Safari::Options') end - - it 'does not allow both Options and Capabilities' do - msg = "Don't use both :options and :capabilities when initializing Selenium::WebDriver::Safari::Driver, " \ - 'prefer :options' - expect { - described_class.new(options: Options.new, capabilities: Remote::Capabilities.new(browser_name: 'safari')) - }.to raise_exception(ArgumentError, msg) - end - - context 'with :capabilities' do - before { allow(DriverFinder).to receive(:path) } - - it 'accepts value as a Symbol' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari'}}}) - expect { described_class.new(capabilities: :safari) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Snake Case as Symbols' do - capabilities = Remote::Capabilities.new(browser_name: 'safari', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Symbols' do - capabilities = Remote::Capabilities.new(browserName: 'safari', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - it 'accepts constructed Capabilities with Camel Case as Strings' do - capabilities = Remote::Capabilities.new('browserName' => 'safari', 'invalid' => 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: capabilities) }.to have_deprecated(:capabilities) - end - - context 'when value is an Array' do - let(:as_json_object) do - Class.new do - def as_json(*) - {'company:key': 'value'} - end - end - end - - it 'with Options instance' do - browser_opts = {automatic_inspection: true} - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', - 'safari:automaticInspection': true}}}) - - expect { - described_class.new(capabilities: [Options.new(**browser_opts)]) - }.to have_deprecated(:capabilities) - end - - it 'with Capabilities instance' do - capabilities = Remote::Capabilities.new(browser_name: 'safari', invalid: 'foobar') - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', invalid: 'foobar'}}}) - - expect { described_class.new(capabilities: [capabilities]) }.to have_deprecated(:capabilities) - end - - it 'with Options instance and an instance of a custom object responding to #as_json' do - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', - 'company:key': 'value'}}}) - - expect { - described_class.new(capabilities: [Options.new, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - - it 'with Options instance, Capabilities instance and instance of a custom object responding to #as_json' do - capabilities = Remote::Capabilities.new(browser_name: 'safari', invalid: 'foobar') - options = Options.new(automatic_inspection: true) - expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari', - invalid: 'foobar', - 'safari:automaticInspection': true, - 'company:key': 'value'}}}) - - expect { - described_class.new(capabilities: [capabilities, options, as_json_object.new]) - }.to have_deprecated(:capabilities) - end - end - end end end # Safari end # WebDriver