class Selenium::WebDriver::Options
Constants
- GRID_OPTIONS
- W3C_OPTIONS
Attributes
driver_path[R]
options[RW]
Public Class Methods
chrome(**)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 32 def chrome(**) Chrome::Options.new(**) end
edge(**)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 45 def edge(**) Edge::Options.new(**) end
Also aliased as: microsoftedge
firefox(**)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 36 def firefox(**) Firefox::Options.new(**) end
ie(**)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 40 def ie(**) IE::Options.new(**) end
Also aliased as: internet_explorer
new(**opts)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 71 def initialize(**opts) self.class.set_capabilities opts[:web_socket_url] = opts.delete(:bidi) if opts.key?(:bidi) @options = opts @options[:browser_name] = self.class::BROWSER end
safari(**)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 50 def safari(**) Safari::Options.new(**) end
set_capabilities()
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 54 def set_capabilities (W3C_OPTIONS + GRID_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
Public Instance Methods
==(other)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 104 def ==(other) return false unless other.is_a? self.class as_json == other.as_json end
Also aliased as: eql?
add_option(name, value = nil)
click to toggle source
Add a new option not yet handled by bindings.
@example Leave Chrome open when chromedriver is killed
options = Selenium::WebDriver::Chrome::Options.new options.add_option(:detach, true)
@param [String, Symbol] name Name of the option @param [Boolean, String, Integer] value Value of the option
# File lib/selenium/webdriver/common/options.rb, line 91 def add_option(name, value = nil) name, value = name.first if value.nil? && name.is_a?(Hash) @options[name] = value end
as_json(*)
click to toggle source
@api private
# File lib/selenium/webdriver/common/options.rb, line 116 def as_json(*) options = @options.dup downloads = options.delete(:enable_downloads) options['se:downloadsEnabled'] = downloads unless downloads.nil? w3c_options = process_w3c_options(options) browser_options = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash| capability_value = options.delete(capability_alias) hash[capability_name] = capability_value unless capability_value.nil? end raise Error::WebDriverError, "These options are not w3c compliant: #{options}" unless options.empty? browser_options = {self.class::KEY => browser_options} if defined?(self.class::KEY) process_browser_options(browser_options) generate_as_json(w3c_options.merge(browser_options)) end
bidi?()
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 100 def bidi? !!@options[:web_socket_url] end
enable_bidi!()
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 96 def enable_bidi! @options[:web_socket_url] = true end
Private Instance Methods
camel_case(str)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 198 def camel_case(str) str.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase } end
camelize?(_key)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 162 def camelize?(_key) true end
convert_json_key(key, camelize: true)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 190 def convert_json_key(key, camelize: true) key = key.to_s if key.is_a?(Symbol) key = camel_case(key) if camelize return key if key.is_a?(String) raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}" end
generate_as_json(value, camelize_keys: true)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 166 def generate_as_json(value, camelize_keys: true) if value.is_a?(Hash) process_json_hash(value, camelize_keys) elsif value.respond_to?(:as_json) value.as_json elsif value.is_a?(Array) value.map { |val| generate_as_json(val, camelize_keys: camelize_keys) } elsif value.is_a?(Symbol) value.to_s else value end end
process_browser_options(_browser_options)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 158 def process_browser_options(_browser_options) nil end
process_json_hash(value, camelize_keys)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 180 def process_json_hash(value, camelize_keys) value.each_with_object({}) do |(key, val), hash| next if val.respond_to?(:empty?) && val.empty? camelize = camelize_keys ? camelize?(key) : false key = convert_json_key(key, camelize: camelize) hash[key] = generate_as_json(val, camelize_keys: camelize) end end
process_unhandled_prompt_behavior_value(value)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 150 def process_unhandled_prompt_behavior_value(value) if value.is_a?(Hash) value.transform_values { |v| process_unhandled_prompt_behavior_value(v) } else value&.to_s&.tr('_', ' ') end end
process_w3c_options(options)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 142 def process_w3c_options(options) w3c_options = options.select { |key, val| w3c?(key) && !val.nil? } w3c_options[:unhandled_prompt_behavior] &&= process_unhandled_prompt_behavior_value(w3c_options[:unhandled_prompt_behavior]) options.delete_if { |key, _val| w3c?(key) } w3c_options end
w3c?(key)
click to toggle source
# File lib/selenium/webdriver/common/options.rb, line 138 def w3c?(key) W3C_OPTIONS.include?(key) || key.to_s.include?(':') end