class Selenium::WebDriver::Firefox::Options

Constants

BROWSER
CAPABILITIES

see: firefox-source-docs.mozilla.org/testing/geckodriver/Capabilities.html

KEY

Attributes

debugger_address[RW]
profile[R]

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

Public Class Methods

new(log_level: nil, **opts) click to toggle source

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

@example

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

@param [Hash] opts the pre-defined options to create the Firefox::Options with @option opts [String] :binary Path to the Firefox executable to use @option opts [Array<String>] :args List of command-line arguments to use when starting geckodriver @option opts [Profile, String] :profile Encoded profile string or Profile instance @option opts [String, Symbol] :log_level Log level for geckodriver @option opts [Hash] :prefs A hash with each entry consisting of the key of the preference and its value @option opts [Hash] :options A hash for raw options

Calls superclass method Selenium::WebDriver::Options::new
# 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

Public Instance Methods

add_argument(arg) click to toggle source

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

@example Start geckodriver on a specific host

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

@param [String] arg The command-line argument to add

# File lib/selenium/webdriver/firefox/options.rb, line 80
def add_argument(arg)
  @options[:args] << arg
end
add_preference(name, value) click to toggle source

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

@example Set the default homepage

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

@param [String] name Key of the preference @param [Boolean, String, Integer] value Value of the preference

# 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) click to toggle source

Enables mobile browser use on Android.

@see developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions#android

@param [String] package The package name of the Chrome or WebView app. @param [String] serial_number 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.

@param [String] activity The fully qualified class name of the activity to be launched. @param [Array] intent_arguments Arguments to launch the intent with.

# 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!() click to toggle source

Run Firefox in headless mode.

@example Enable headless mode

options = Selenium::WebDriver::Firefox::Options.new
options.headless!
# File lib/selenium/webdriver/firefox/options.rb, line 107
def headless!
  add_argument '-headless'
end
log_level() click to toggle source
# File lib/selenium/webdriver/firefox/options.rb, line 130
def log_level
  @options.dig(:log, :level)
end
log_level=(level) click to toggle source
# File lib/selenium/webdriver/firefox/options.rb, line 134
def log_level=(level)
  @options[:log] = {level: level}
end
profile=(profile) click to toggle source

Sets Firefox profile.

@example Set the custom profile

profile = Selenium::WebDriver::Firefox::Profile.new
options = Selenium::WebDriver::Firefox::Options.new
options.profile = profile

@example Use existing profile

options = Selenium::WebDriver::Firefox::Options.new
options.profile = 'myprofile'

@param [Profile, String] profile Profile to be used

# File lib/selenium/webdriver/firefox/options.rb, line 126
def profile=(profile)
  process_profile(profile)
end

Private Instance Methods

camelize?(key) click to toggle source
# File lib/selenium/webdriver/firefox/options.rb, line 177
def camelize?(key)
  key != "prefs"
end
process_browser_options(browser_options) click to toggle source
# File lib/selenium/webdriver/firefox/options.rb, line 159
def process_browser_options(browser_options)
  browser_options['moz:debuggerAddress'] = true if @debugger_address
  options = browser_options[KEY]
  options['binary'] ||= Firefox.path if Firefox.path
  options['profile'] = @profile if @profile
end
process_profile(profile) click to toggle source
# File lib/selenium/webdriver/firefox/options.rb, line 166
def process_profile(profile)
  @profile = case profile
             when nil
               nil
             when Profile
               profile
             else
               Profile.from_name(profile)
             end
end