Class: Selenium::WebDriver::Options
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/options.rb |
Constant Summary
-
GRID_OPTIONS =
# File 'rb/lib/selenium/webdriver/common/options.rb', line 27%i[enable_downloads].freeze
-
W3C_OPTIONS =
# File 'rb/lib/selenium/webdriver/common/options.rb', line 23%i[browser_name browser_version platform_name accept_insecure_certs page_load_strategy proxy set_window_rect timeouts unhandled_prompt_behavior strict_file_interactability web_socket_url].freeze
Class Attribute Summary
- .driver_path readonly
Class Method Summary
- .chrome(**opts)
- .edge(**opts) (also: .microsoftedge)
- .firefox(**opts)
- .ie(**opts) (also: .internet_explorer)
-
.internet_explorer(**opts)
Alias for .ie.
-
.microsoftedge(**opts)
Alias for .edge.
- .new(**opts) ⇒ Options constructor
- .safari(**opts)
- .set_capabilities
Instance Attribute Summary
- #options rw
Instance Method Summary
- #==(other) (also: #eql?)
-
#add_option(name, value = nil)
Add a new option not yet handled by bindings.
-
#eql?(other)
Alias for #==.
- #camel_case(str) private
- #camelize?(_key) ⇒ Boolean private
- #convert_json_key(key, camelize: true) private
- #generate_as_json(value, camelize_keys: true) private
- #process_browser_options(_browser_options) private
- #process_json_hash(value, camelize_keys) private
- #process_w3c_options(options) private
- #w3c?(key) ⇒ Boolean private
- #as_json Internal use only Internal use only
Constructor Details
.new(**opts) ⇒ Options
# File 'rb/lib/selenium/webdriver/common/options.rb', line 71
def initialize(**opts) self.class.set_capabilities @options = opts @options[:browser_name] = self.class::BROWSER end
Class Attribute Details
.driver_path (readonly)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 30
attr_reader :driver_path
Class Method Details
.chrome(**opts)
[ GitHub ].edge(**opts) Also known as: .microsoftedge
[ GitHub ].firefox(**opts)
[ GitHub ].ie(**opts) Also known as: .internet_explorer
[ GitHub ].internet_explorer(**opts)
Alias for .ie.
# File 'rb/lib/selenium/webdriver/common/options.rb', line 43
alias internet_explorer ie
.microsoftedge(**opts)
Alias for .edge.
# File 'rb/lib/selenium/webdriver/common/options.rb', line 48
alias microsoftedge edge
.safari(**opts)
[ GitHub ].set_capabilities
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 54
def 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 Attribute Details
#options (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 69
attr_accessor :
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]#add_option(name, value = nil)
Add a new option not yet handled by bindings.
# File 'rb/lib/selenium/webdriver/common/options.rb', line 89
def add_option(name, value = nil) name, value = name.first if value.nil? && name.is_a?(Hash) @options[name] = value end
#as_json
This method is for internal use only.
# File 'rb/lib/selenium/webdriver/common/options.rb', line 106
def as_json(*) = @options.dup downloads = .delete(:enable_downloads) ['se:downloadsEnabled'] = downloads unless downloads.nil? = ( ) = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash| capability_value = .delete(capability_alias) hash[capability_name] = capability_value unless capability_value.nil? end raise Error::WebDriverError, "These options are not w3c compliant: #{}" unless .empty? = {self.class::KEY => } if defined?(self.class::KEY) ( ) generate_as_json( .merge( )) end
#camel_case(str) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 179
def camel_case(str) str.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase } end
#camelize?(_key) ⇒ Boolean
(private)
# File 'rb/lib/selenium/webdriver/common/options.rb', line 143
def camelize?(_key) true end
#convert_json_key(key, camelize: true) (private)
# File 'rb/lib/selenium/webdriver/common/options.rb', line 171
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
#eql?(other)
Alias for #==.
# File 'rb/lib/selenium/webdriver/common/options.rb', line 100
alias eql? ==
#generate_as_json(value, camelize_keys: true) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 147
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) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 139
def ( ) nil end
#process_json_hash(value, camelize_keys) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/options.rb', line 161
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_w3c_options(options) (private)
[ GitHub ]
#w3c?(key) ⇒ Boolean
(private)
# File 'rb/lib/selenium/webdriver/common/options.rb', line 128
def w3c?(key) W3C_OPTIONS.include?(key) || key.to_s.include?(':') end