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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Options.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 42

def initialize(options: nil, **opts)
  self.class.set_capabilities

  @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.



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

def options
  @options
end

Class Method Details

.set_capabilitiesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 26

def self.set_capabilities
  (W3C_OPTIONS + self::CAPABILITIES.keys).each do |key|
    next if method_defined? key

    define_method key do
      @options[key]
    end

    define_method "#{key}=" do |value|
      @options[key] = value
    end
  end
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



67
68
69
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 67

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.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'build/rb/lib/selenium/webdriver/common/options.rb', line 75

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)
  generate_as_json(w3c_options.merge(browser_options))
end