Skip to content

Commit

Permalink
[rb] remove deprecated functionality from capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 23, 2022
1 parent 05c2a5a commit b40ddeb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 683 deletions.
48 changes: 8 additions & 40 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,55 +307,23 @@ def ref

attr_reader :bridge

def create_bridge(**opts)
opts[:url] ||= service_url(opts.delete(:service))
caps = opts.delete(:capabilities)
# NOTE: This is deprecated
cap_array = caps.is_a?(Hash) ? [caps] : Array(caps)

desired_capabilities = opts.delete(:desired_capabilities)
if desired_capabilities
WebDriver.logger.deprecate(':desired_capabilities as a parameter for driver initialization',
':capabilities with an Array value of capabilities/options if necessary',
id: :desired_capabilities)
desired_capabilities = Remote::Capabilities.new(desired_capabilities) if desired_capabilities.is_a?(Hash)
cap_array << desired_capabilities
def create_bridge(capabilities: nil, options: nil, url: nil, service: nil, http_client: nil)
Remote::Bridge.new(http_client: http_client,
url: url || service_url(service)).tap do |bridge|
generated_caps = options ? options.as_json : generate_capabilities(capabilities)
bridge.create_session(generated_caps)
end

options = opts.delete(:options)
if options
WebDriver.logger.deprecate(':options as a parameter for driver initialization',
':capabilities with an Array of value capabilities/options if necessary',
id: :browser_options)
cap_array << options
end

capabilities = generate_capabilities(cap_array)

bridge_opts = {http_client: opts.delete(:http_client), url: opts.delete(:url)}
raise ArgumentError, "Unable to create a driver with parameters: #{opts}" unless opts.empty?

bridge = Remote::Bridge.new(**bridge_opts)

bridge.create_session(capabilities)
bridge
end

def generate_capabilities(cap_array)
cap_array.map { |cap|
def generate_capabilities(capabilities)
Array(capabilities).map { |cap|
if cap.is_a? Symbol
cap = Remote::Capabilities.send(cap)
elsif cap.is_a? Hash
new_message = 'Capabilities instance initialized with the Hash, or build values with Options class'
WebDriver.logger.deprecate("passing a Hash value to :capabilities",
new_message,
id: :capabilities_hash)
cap = Remote::Capabilities.new(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
cap.as_json
}.inject(:merge) || Remote::Capabilities.send(browser || :new)
end

Expand Down
105 changes: 1 addition & 104 deletions rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,96 +47,11 @@ def expect_request(body: nil, endpoint: nil)
expect { Driver.new }.not_to raise_exception
end

context 'with :desired capabilities' do
it 'accepts value as a Symbol' do
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome"}}})

expect {
expect { Driver.new(desired_capabilities: :chrome) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts Capabilities.chrome' do
capabilities = Remote::Capabilities.chrome(invalid: 'foobar')
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts constructed Capabilities with Snake Case as Symbols' do
capabilities = Remote::Capabilities.new(browser_name: 'chrome', invalid: 'foobar')
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts constructed Capabilities with Camel Case as Symbols' do
capabilities = Remote::Capabilities.new(browserName: 'chrome', invalid: 'foobar')
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts constructed Capabilities with Camel Case as Strings' do
capabilities = Remote::Capabilities.new('browserName' => 'chrome', 'invalid' => 'foobar')
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Symbols' do
capabilities = {browserName: 'chrome', invalid: 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Strings' do
capabilities = {"browserName" => 'chrome', "invalid" => 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end
end

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

expect {
expect { Driver.new(options: Options.new(**opts)) }.to have_deprecated(:browser_options)
}.not_to raise_exception
end

it 'accepts combination of Options and Capabilities' do
caps = Remote::Capabilities.chrome(invalid: 'foobar')
browser_opts = {args: ['-f']}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome",
invalid: "foobar",
'goog:chromeOptions': browser_opts}}})

expect {
expect {
Driver.new(options: Options.new(**browser_opts), desired_capabilities: caps)
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
end

it 'raises an ArgumentError if parameter is not recognized' do
msg = 'Unable to create a driver with parameters: {:invalid=>"foo"}'
expect { Driver.new(invalid: 'foo') }.to raise_error(ArgumentError, msg)
expect { Driver.new(options: Options.new(**opts)) }.not_to raise_exception
end

context 'with :capabilities' do
Expand Down Expand Up @@ -173,24 +88,6 @@ def expect_request(body: nil, endpoint: nil)
expect { Driver.new(capabilities: capabilities) }.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Symbols but is deprecated' do
capabilities = {browserName: 'chrome', invalid: 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(capabilities: capabilities) }.to have_deprecated(:capabilities_hash)
}.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Strings but is deprecated' do
capabilities = {"browserName" => 'chrome', "invalid" => 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "chrome", invalid: 'foobar'}}})

expect {
expect { Driver.new(capabilities: capabilities) }.to have_deprecated(:capabilities_hash)
}.not_to raise_exception
end

context 'when value is an Array' do
let(:as_json_object) do
Class.new do
Expand Down
102 changes: 2 additions & 100 deletions rb/spec/unit/selenium/webdriver/edge/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,95 +47,15 @@ def expect_request(body: nil, endpoint: nil)
expect { Driver.new }.not_to raise_exception
end

context 'with :desired capabilities' do
it 'accepts value as a Symbol' do
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge"}}})

expect {
expect { Driver.new(desired_capabilities: :edge) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts Capabilities.edge' do
capabilities = Remote::Capabilities.edge(invalid: 'foobar')
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_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 {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
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 {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
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 {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Symbols' do
capabilities = {browserName: 'MicrosoftEdge', invalid: 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Strings' do
capabilities = {"browserName" => 'MicrosoftEdge', "invalid" => 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge", invalid: 'foobar'}}})

expect {
expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)
}.not_to raise_exception
end
end

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

expect {
expect { Driver.new(options: Options.new(**opts)) }.to have_deprecated(:browser_options)
}.not_to raise_exception
end

it 'accepts combination of Options and Capabilities' do
caps = Remote::Capabilities.edge(invalid: 'foobar')
browser_opts = {args: ['-f']}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge",
invalid: "foobar",
'ms:edgeOptions': browser_opts}}})

expect {
expect {
Driver.new(options: Options.new(**browser_opts), desired_capabilities: caps)
}.to have_deprecated(%i[browser_options desired_capabilities])
}.not_to raise_exception
expect { Driver.new(options: Options.new(**opts)) }.not_to raise_exception
end

it 'raises an ArgumentError if parameter is not recognized' do
msg = 'Unable to create a driver with parameters: {:invalid=>"foo"}'
msg = 'unknown keyword: :invalid'
expect { Driver.new(invalid: 'foo') }.to raise_error(ArgumentError, msg)
end

Expand Down Expand Up @@ -173,24 +93,6 @@ def expect_request(body: nil, endpoint: nil)
expect { Driver.new(capabilities: capabilities) }.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Symbols but is deprecated' do
capabilities = {browserName: 'MicrosoftEdge', invalid: 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge", invalid: 'foobar'}}})

expect {
expect { Driver.new(capabilities: capabilities) }.to have_deprecated(:capabilities_hash)
}.not_to raise_exception
end

it 'accepts Hash with Camel Case keys as Strings but is deprecated' do
capabilities = {"browserName" => 'MicrosoftEdge', "invalid" => 'foobar'}
expect_request(body: {capabilities: {alwaysMatch: {browserName: "MicrosoftEdge", invalid: 'foobar'}}})

expect {
expect { Driver.new(capabilities: capabilities) }.to have_deprecated(:capabilities_hash)
}.not_to raise_exception
end

context 'when value is an Array' do
let(:as_json_object) do
Class.new do
Expand Down
Loading

0 comments on commit b40ddeb

Please sign in to comment.