Class: Selenium::WebDriver::Firefox::Options

Inherits:
Options
  • Object
show all
Defined in:
lib/selenium/webdriver/firefox/options.rb

Constant Summary collapse

KEY =
'moz:firefoxOptions'
CAPABILITIES =
{binary: 'binary',
args: 'args',
log: 'log',
prefs: 'prefs',
env: 'env',
android_package: 'androidPackage',
android_activity: 'androidActivity',
android_device_serial: 'androidDeviceSerial',
android_intent_arguments: 'androidIntentArguments'}.freeze
BROWSER =
'firefox'

Constants inherited from Options

Options::GRID_OPTIONS, Options::W3C_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Options

#options

Instance Method Summary collapse

Methods inherited from Options

#==, #add_option, #as_json, chrome, edge, firefox, ie, safari, set_capabilities

Constructor Details

#initialize(log_level: nil, **opts) ⇒ Options

Create a new Options instance, only for W3C-capable versions of Firefox.

Examples:

options = Selenium::WebDriver::Firefox::Options.new(args: ['--host=127.0.0.1'])
driver = Selenium::WebDriver.for :firefox, options: options

Parameters:

  • opts (Hash)

    the pre-defined options to create the Firefox::Options with

Options Hash (**opts):

  • :binary (String)

    Path to the Firefox executable to use

  • :args (Array<String>)

    List of command-line arguments to use when starting geckodriver

  • :profile (Profile, String)

    Encoded profile string or Profile instance

  • :log_level (String, Symbol)

    Log level for geckodriver

  • :prefs (Hash)

    A hash with each entry consisting of the key of the preference and its value

  • :options (Hash)

    A hash for raw options



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/selenium/webdriver/firefox/options.rb', line 59

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

  super(**opts)

  @options[:args] ||= []
  @options[:prefs] ||= {}
  # Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it.
  # https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/.
  @options[:prefs]['remote.active-protocols'] = 3
  @options[:env] ||= {}
  @options[:log] ||= {level: log_level} if log_level

  process_profile(@options.delete(:profile))
end

Instance Attribute Details

#debugger_addressObject

Returns the value of attribute debugger_address.



24
25
26
# File 'lib/selenium/webdriver/firefox/options.rb', line 24

def debugger_address
  @debugger_address
end

#profileObject

NOTE: special handling of ‘profile’ to validate when set instead of when used



41
42
43
# File 'lib/selenium/webdriver/firefox/options.rb', line 41

def profile
  @profile
end

Instance Method Details

#add_argument(arg) ⇒ Object

Add a command-line argument to use when starting Firefox.

Examples:

Start geckodriver on a specific host

options = Selenium::WebDriver::Firefox::Options.new
options.add_argument('--host=127.0.0.1')

Parameters:

  • arg (String)

    The command-line argument to add



86
87
88
# File 'lib/selenium/webdriver/firefox/options.rb', line 86

def add_argument(arg)
  @options[:args] << arg
end

#add_preference(name, value) ⇒ Object

Add a preference that is only applied to the user profile in use.

Examples:

Set the default homepage

options = Selenium::WebDriver::Firefox::Options.new
options.add_preference('browser.startup.homepage', 'http://www.seleniumhq.com/')

Parameters:

  • name (String)

    Key of the preference

  • value (Boolean, String, Integer)

    Value of the preference



101
102
103
# File 'lib/selenium/webdriver/firefox/options.rb', line 101

def add_preference(name, value)
  @options[:prefs][name] = value
end

#enable_android(package: 'org.mozilla.firefox', serial_number: nil, activity: nil, intent_arguments: nil) ⇒ Object

Enables mobile browser use on Android.

Parameters:

  • package (String) (defaults to: 'org.mozilla.firefox')

    The package name of the Chrome or WebView app.

  • serial_number (String) (defaults to: nil)

    The serial number of the device on which to launch the application. If not specified and multiple devices are attached, an error will be returned.

  • activity (String) (defaults to: nil)

    The fully qualified class name of the activity to be launched.

  • intent_arguments (Array) (defaults to: nil)

    Arguments to launch the intent with.

See Also:



144
145
146
147
148
149
# File 'lib/selenium/webdriver/firefox/options.rb', line 144

def enable_android(package: 'org.mozilla.firefox', serial_number: nil, activity: nil, intent_arguments: nil)
  @options[:android_package] = package
  @options[:android_activity] = activity unless activity.nil?
  @options[:android_device_serial] = serial_number unless serial_number.nil?
  @options[:android_intent_arguments] = intent_arguments unless intent_arguments.nil?
end

#log_levelObject



124
125
126
# File 'lib/selenium/webdriver/firefox/options.rb', line 124

def log_level
  @options.dig(:log, :level)
end

#log_level=(level) ⇒ Object



128
129
130
# File 'lib/selenium/webdriver/firefox/options.rb', line 128

def log_level=(level)
  @options[:log] = {level: level}
end