Class: Selenium::WebDriver::Options

Inherits:
Object
  • Object
show all
Defined in:
build/rb/lib/selenium/webdriver/common/options.rb

Constant Summary collapse

W3C_OPTIONS =
%i[browser_name browser_version platform_name accept_insecure_certs page_load_strategy proxy
set_window_rect timeouts unhandled_prompt_behavior strict_file_interactability].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Options.



38
39
40
41
42
43
44
45
46
47
48
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 38

def initialize(options: nil, **opts)
  @options = if options
               WebDriver.logger.deprecate(":options as keyword for initializing #{self.class}",
                                          "custom values directly in #new constructor",
                                          id: :options_options)
               opts.merge(options)
             else
               opts
             end
  @options[:browser_name] = self.class::BROWSER
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



36
37
38
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 36

def options
  @options
end

Instance Method Details

#add_option(name, value) ⇒ Object

Add a new option not yet handled by bindings.

Examples:

Leave Chrome open when chromedriver is killed

options = Selenium::WebDriver::Chrome::Options.new
options.add_option(:detach, true)

Parameters:

  • name (String, Symbol)

    Name of the option

  • value (Boolean, String, Integer)

    Value of the option



61
62
63
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 61

def add_option(name, value)
  @options[name] = value
end

#as_jsonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 69

def as_json(*)
  options = @options.dup

  w3c_options = options.select { |key, _val| W3C_OPTIONS.include?(key) }
  options.delete_if { |key, _val| W3C_OPTIONS.include?(key) }

  self.class::CAPABILITIES.each do |capability_alias, capability_name|
    capability_value = options.delete(capability_alias)
    options[capability_name] = capability_value unless capability_value.nil?
  end
  browser_options = defined?(self.class::KEY) ? {self.class::KEY => options} : options

  process_browser_options(browser_options) if private_methods(false).include?(:process_browser_options)
  generate_as_json(w3c_options.merge(browser_options))
end