Skip to content

Commit

Permalink
[rb] remove deprecated code (#12417)
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jul 25, 2023
1 parent 0267b0f commit 0fa6c3f
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 471 deletions.
4 changes: 1 addition & 3 deletions rb/lib/selenium/webdriver/chrome/service.rb
Expand Up @@ -17,12 +17,10 @@
# specific language governing permissions and limitations
# under the License.

require 'selenium/webdriver/chromium/service'

module Selenium
module WebDriver
module Chrome
class Service < Chromium::Service
class Service < WebDriver::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'chromedriver'
SHUTDOWN_SUPPORTED = true
Expand Down
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/chromium.rb
Expand Up @@ -26,7 +26,6 @@ module Chromium
autoload :Driver, 'selenium/webdriver/chromium/driver'
autoload :Profile, 'selenium/webdriver/chromium/profile'
autoload :Options, 'selenium/webdriver/chromium/options'
autoload :Service, 'selenium/webdriver/chromium/service'
end # Chromium
end # WebDriver
end # Selenium
18 changes: 0 additions & 18 deletions rb/lib/selenium/webdriver/chromium/options.rb
Expand Up @@ -159,24 +159,6 @@ def add_preference(name, value)
@options[:prefs][name] = value
end

#
# Run Chrome in headless mode.
# Old headless uses a non-production browser and is set with `--headless`
# Native headless from v86 - v108 is set with `--headless=chrome`
# Native headless from v109+ is set with `--headless=new`
#
# @example Enable headless mode
# options = Selenium::WebDriver::Chrome::Options.new
# options.headless!
#

def headless!
WebDriver.logger.deprecate('`Options#headless!`',
"`Options#add_argument('--headless=new')`",
id: :headless)
add_argument '--headless'
end

#
# Add emulation device information
#
Expand Down
42 changes: 0 additions & 42 deletions rb/lib/selenium/webdriver/chromium/service.rb

This file was deleted.

23 changes: 2 additions & 21 deletions rb/lib/selenium/webdriver/common/options.rb
Expand Up @@ -86,12 +86,6 @@ def initialize(**opts)

def add_option(name, value = nil)
name, value = name.first if value.nil? && name.is_a?(Hash)

unless name.to_s.include?(':')
WebDriver.logger.deprecate('Options#add_option for w3c or browser specific capabilities',
'applicable attribute accessors or pass into constructor',
id: :add_option)
end
@options[name] = value
end

Expand All @@ -113,24 +107,11 @@ def as_json(*)
w3c_options = process_w3c_options(options)

browser_options = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash|
from_name = options.delete(capability_name)
from_alias = options.delete(capability_alias)
capability_value = if !from_name.nil? && capability_alias != capability_name
WebDriver.logger.deprecate("#{capability_name} as option",
capability_alias.to_s, id: :option_symbols)
from_name
elsif !from_alias.nil?
from_alias
end

capability_value = options.delete(capability_alias)
hash[capability_name] = capability_value unless capability_value.nil?
end

unless options.empty?
msg = 'These options are not w3c compliant and will result in failures in a future release'
WebDriver.logger.warn("#{msg}: #{options}", id: :w3c_options)
browser_options.merge!(options)
end
raise Error::WebDriverError, "These options are not w3c compliant: #{options}" unless options.empty?

browser_options = {self.class::KEY => browser_options} if defined?(self.class::KEY)

Expand Down
12 changes: 1 addition & 11 deletions rb/lib/selenium/webdriver/common/service.rb
Expand Up @@ -81,8 +81,7 @@ def initialize(path: nil, port: nil, log: nil, args: nil)
else
log
end

@args = args.is_a?(Hash) ? extract_service_args(args) : args
@args = args

raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
end
Expand All @@ -94,15 +93,6 @@ def launch
def shutdown_supported
self.class::SHUTDOWN_SUPPORTED
end

protected

def extract_service_args(driver_opts)
WebDriver.logger.deprecate('initializing Service class with :args using Hash',
':args parameter with an Array of String values',
id: :driver_opts)
driver_opts.key?(:args) ? driver_opts.delete(:args) : []
end
end # Service
end # WebDriver
end # Selenium
4 changes: 1 addition & 3 deletions rb/lib/selenium/webdriver/edge/service.rb
Expand Up @@ -17,12 +17,10 @@
# specific language governing permissions and limitations
# under the License.

require 'selenium/webdriver/chromium/service'

module Selenium
module WebDriver
module Edge
class Service < Chromium::Service
class Service < WebDriver::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'msedgedriver'
SHUTDOWN_SUPPORTED = true
Expand Down
15 changes: 0 additions & 15 deletions rb/lib/selenium/webdriver/firefox/options.rb
Expand Up @@ -99,21 +99,6 @@ def add_preference(name, value)
@options[:prefs][name] = value
end

#
# Run Firefox in headless mode.
#
# @example Enable headless mode
# options = Selenium::WebDriver::Firefox::Options.new
# options.headless!
#

def headless!
WebDriver.logger.deprecate('`Options#headless!`',
"`Options#add_argument('-headless')`",
id: :headless)
add_argument '-headless'
end

#
# Sets Firefox profile.
#
Expand Down
12 changes: 0 additions & 12 deletions rb/lib/selenium/webdriver/firefox/service.rb
Expand Up @@ -24,18 +24,6 @@ class Service < WebDriver::Service
DEFAULT_PORT = 4444
EXECUTABLE = 'geckodriver'
SHUTDOWN_SUPPORTED = false

private

def extract_service_args(driver_opts)
driver_args = super
driver_opts = driver_opts.dup
driver_args << "--binary=#{driver_opts[:binary]}" if driver_opts.key?(:binary)
driver_args << "--log=#{driver_opts[:log]}" if driver_opts.key?(:log)
driver_args << "--marionette-port=#{driver_opts[:marionette_port]}" if driver_opts.key?(:marionette_port)
driver_args << "--host=#{driver_opts[:host]}" if driver_opts.key?(:host)
driver_args
end
end # Service
end # Firefox
end # WebDriver
Expand Down
16 changes: 0 additions & 16 deletions rb/lib/selenium/webdriver/ie/service.rb
Expand Up @@ -24,22 +24,6 @@ class Service < WebDriver::Service
DEFAULT_PORT = 5555
EXECUTABLE = 'IEDriverServer'
SHUTDOWN_SUPPORTED = true

private

def extract_service_args(driver_opts)
driver_args = super
driver_opts = driver_opts.dup
driver_args << "--log-level=#{driver_opts[:log_level].to_s.upcase}" if driver_opts.key?(:log_level)
driver_args << "--log-file=#{driver_opts[:log_file]}" if driver_opts.key?(:log_file)
if driver_opts.key?(:implementation)
driver_args << "--implementation=#{driver_opts[:implementation].to_s.upcase}"
end
driver_args << "--host=#{driver_opts[:host]}" if driver_opts.key?(:host)
driver_args << "--extract_path=#{driver_opts[:extract_path]}" if driver_opts.key?(:extract_path)
driver_args << '--silent' if driver_opts[:silent] == true
driver_args
end
end # Server
end # IE
end # WebDriver
Expand Down
72 changes: 0 additions & 72 deletions rb/lib/selenium/webdriver/remote/capabilities.rb
Expand Up @@ -53,83 +53,11 @@ class Capabilities
end
end

#
# Backward compatibility
#

def version
WebDriver.logger.deprecate('`Capabilities#version`', '`Capabilities#browser_version`', id: :jwp_caps)
browser_version
end

def version=(value)
WebDriver.logger.deprecate('`Capabilities#version=`', '`Capabilities#browser_version=`', id: :jwp_caps)
self.browser_version = value
end

def platform
WebDriver.logger.deprecate('`Capabilities#platform`', '`Capabilities#platform_name`', id: :jwp_caps)
platform_name
end

def platform=(value)
WebDriver.logger.deprecate('`Capabilities#platform=`', '`Capabilities#platform_name=`', id: :jwp_caps)
self.platform_name = value
end

#
# Convenience methods for the common choices.
#

class << self
def chrome(opts = {})
WebDriver.logger.deprecate('Remote::Capabilities.chrome', 'Options.chrome', id: :caps_browsers)
new({
browser_name: 'chrome'
}.merge(opts))
end

def edge(opts = {})
WebDriver.logger.deprecate('Remote::Capabilities.edge', 'Options.edge', id: :caps_browsers)
new({
browser_name: 'MicrosoftEdge'
}.merge(opts))
end
alias microsoftedge edge

def firefox(opts = {})
WebDriver.logger.deprecate('Remote::Capabilities.firefox', 'Options.firefox', id: :caps_browsers)
new({
browser_name: 'firefox'
}.merge(opts))
end
alias ff firefox

def safari(opts = {})
WebDriver.logger.deprecate('Remote::Capabilities.safari', 'Options.safari', id: :caps_browsers)
new({
browser_name: Selenium::WebDriver::Safari.technology_preview? ? 'Safari Technology Preview' : 'safari'
}.merge(opts))
end

def htmlunit(opts = {})
WebDriver.logger.deprecate('Remote::Capabilities.htmlunit',
'as argument in constructor',
id: :caps_browsers)
new({
browser_name: 'htmlunit'
}.merge(opts))
end

def internet_explorer(opts = {})
WebDriver.logger.deprecate('Remote::Capabilities.ie', 'Options.ie', id: :caps_browsers)
new({
browser_name: 'internet explorer',
platform_name: :windows
}.merge(opts))
end
alias ie internet_explorer

def always_match(capabilities)
new(always_match: capabilities)
end
Expand Down
1 change: 0 additions & 1 deletion rb/spec/BUILD.bazel
Expand Up @@ -61,7 +61,6 @@ rb_library(
"//rb/spec/unit/selenium/webdriver/common:action_builder",
"//rb/spec/unit/selenium/webdriver/common:credentials",
"//rb/spec/unit/selenium/webdriver/common:logger",
"//rb/spec/unit/selenium/webdriver/common:options",
"//rb/spec/unit/selenium/webdriver/common:selenium_manager",
"//rb/spec/unit/selenium/webdriver/common:service",
"//rb/spec/unit/selenium/webdriver/common:virtual_authenticator_options",
Expand Down
Expand Up @@ -69,6 +69,8 @@ def reset_driver!(time: 0, **opts, &block)

def quit_driver
@driver_instance&.quit
rescue StandardError
# good riddance
ensure
@driver_instance = nil
end
Expand Down
36 changes: 4 additions & 32 deletions rb/spec/unit/selenium/webdriver/chrome/options_spec.rb
Expand Up @@ -179,30 +179,7 @@ module Chrome
end
end

describe '#headless!' do
it 'adds necessary command-line arguments' do
expect {
options.headless!
}.to have_deprecated(:headless)
expect(options.args).to eql(['--headless'])
end
end

describe '#add_option' do
it 'adds an option with ordered pairs' do
expect {
options.add_option(:foo, 'bar')
}.to have_deprecated(:add_option)
expect(options.instance_variable_get(:@options)[:foo]).to eq('bar')
end

it 'adds an option with Hash' do
expect {
options.add_option(foo: 'bar')
}.to have_deprecated(:add_option)
expect(options.instance_variable_get(:@options)[:foo]).to eq('bar')
end

it 'adds vendor namespaced options with ordered pairs' do
options.add_option('foo:bar', {bar: 'foo'})
expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})
Expand Down Expand Up @@ -265,24 +242,19 @@ module Chrome
expect(options.as_json).to eq('browserName' => 'chrome', 'goog:chromeOptions' => {})
end

it 'warns when unrecognized capability is passed' do
expect {
options.add_option(:foo, 'bar')
}.to have_deprecated(:add_option)
it 'errors when unrecognized capability is passed' do
options.add_option(:foo, 'bar')

expect {
options.as_json
}.to have_warning(:w3c_options)
}.to raise_error(Error::WebDriverError, 'These options are not w3c compliant: {:foo=>"bar"}')
end

it 'returns added options' do
expect {
options.add_option(:detach, true)
}.to have_deprecated(:add_option)
options.add_option('foo:bar', {foo: 'bar'})
expect(options.as_json).to eq('browserName' => 'chrome',
'foo:bar' => {'foo' => 'bar'},
'goog:chromeOptions' => {'detach' => true})
'goog:chromeOptions' => {})
end

it 'converts profile' do
Expand Down

0 comments on commit 0fa6c3f

Please sign in to comment.