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',
android_package: 'androidPackage',
android_activity: 'androidActivity',
android_device_serial: 'androidDeviceSerial',
android_intent_arguments: 'androidIntentArguments'}.freeze
BROWSER =
'firefox'

Constants inherited from 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, capabilities: 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


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/selenium/webdriver/firefox/options.rb', line 58

def initialize(log_level: nil, **opts)
  @debugger_address = opts.delete(:debugger_address)

  super(**opts)

  @options[:args] ||= []
  @options[:prefs] ||= {}
  @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


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

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


80
81
82
# File 'lib/selenium/webdriver/firefox/options.rb', line 80

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


95
96
97
# File 'lib/selenium/webdriver/firefox/options.rb', line 95

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:


150
151
152
153
154
155
# File 'lib/selenium/webdriver/firefox/options.rb', line 150

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

#headless!Object

Run Firefox in headless mode.

Examples:

Enable headless mode

options = Selenium::WebDriver::Firefox::Options.new
options.headless!

107
108
109
# File 'lib/selenium/webdriver/firefox/options.rb', line 107

def headless!
  add_argument '-headless'
end

#log_levelObject


130
131
132
# File 'lib/selenium/webdriver/firefox/options.rb', line 130

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

#log_level=(level) ⇒ Object


134
135
136
# File 'lib/selenium/webdriver/firefox/options.rb', line 134

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