Class: Selenium::WebDriver::Remote::Capabilities
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/remote/capabilities.rb |
Overview
Specification of the desired and/or actual capabilities of the browser that the server is being asked to create.
Constant Summary
-
KNOWN =
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 29[ :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, # remote-specific (webdriver.remote.sessionid) :remote_session_id ].freeze
Class Method Summary
- .always_match(capabilities)
- .camel_case(str_or_sym)
- .first_match(*capabilities)
- .new(opts = {}) ⇒ Capabilities constructor
- .process_timeouts(caps, timeouts) private
- .json_create(data) Internal use only Internal use only
Instance Attribute Summary
Instance Method Summary
- #==(other) (also: #eql?)
- #[](key)
-
#[]=(key, value)
Allows setting arbitrary capabilities.
-
#eql?(other)
Alias for #==.
- #merge!(other)
- #to_json
- #convert_key(key) private
- #convert_value(key, value) private
- #process_capabilities(key, value, hash) private
- #as_json Internal use only Internal use only
Constructor Details
.new(opts = {}) ⇒ Capabilities
Class Method Details
.always_match(capabilities)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 61
def always_match(capabilities) new(always_match: capabilities) end
.camel_case(str_or_sym)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 101
def camel_case(str_or_sym) str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase } end
.first_match(*capabilities)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 65
def first_match(*capabilities) new(first_match: capabilities) end
.json_create(data)
This method is for internal use only.
[ GitHub ]
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 73
def json_create(data) data = data.dup caps = new process_timeouts(caps, data.delete('timeouts')) if data.key?('proxy') proxy = data.delete('proxy') caps.proxy = Proxy.json_create(proxy) unless proxy.nil? || proxy.empty? end # Remote Server Specific if data.key?('webdriver.remote.sessionid') caps[:remote_session_id] = data.delete('webdriver.remote.sessionid') end KNOWN.each do |cap| data_value = camel_case(cap) caps[cap] = data.delete(data_value) if data.key?(data_value) end # any remaining pairs will be added as is, with no conversion caps.merge!(data) caps end
.process_timeouts(caps, timeouts) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 107
def process_timeouts(caps, timeouts) return if timeouts.nil? caps.implicit_timeout = timeouts['implicit'] caps.page_load_timeout = timeouts['pageLoad'] caps.script_timeout = timeouts['script'] end
Instance Attribute Details
#implicit_timeout (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 178
def implicit_timeout timeouts[:implicit] end
#implicit_timeout=(timeout) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 182
def implicit_timeout=(timeout) timeouts[:implicit] = timeout end
#page_load_timeout (rw)
[ GitHub ]#page_load_timeout=(timeout) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 190
def page_load_timeout=(timeout) timeouts[:page_load] = timeout end
#proxy (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 155
def proxy @capabilities[:proxy] end
#proxy=(proxy) (rw)
[ GitHub ]#script_timeout (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 194
def script_timeout timeouts[:script] end
#script_timeout=(timeout) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 198
def script_timeout=(timeout) timeouts[:script] = timeout end
#timeouts (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 170
def timeouts @capabilities[:timeouts] ||= {} end
#timeouts=(timeouts) (rw)
[ GitHub ]Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]#[](key)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 141
def [](key) @capabilities[key] end
#[]=(key, value)
Allows setting arbitrary capabilities.
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 137
def []=(key, value) @capabilities[key] = value end
#as_json
This method is for internal use only.
[ GitHub ]
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 206
def as_json(*) @capabilities.each_with_object({}) do |(key, value), hash| hash[convert_key(key)] = process_capabilities(key, value, hash) end end
#convert_key(key) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 245
def convert_key(key) case key when String key.to_s when Symbol self.class.camel_case(key) else raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}" end end
#convert_value(key, value) (private)
[ GitHub ]#eql?(other)
Alias for #==.
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 222
alias eql? ==
#merge!(other)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 145
def merge!(other) if other.respond_to?(:capabilities, true) && other.capabilities.is_a?(Hash) @capabilities.merge! other.capabilities elsif other.is_a? Hash @capabilities.merge! other else raise ArgumentError, 'argument should be a Hash or implement #capabilities' end end
#process_capabilities(key, value, hash) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 230
def process_capabilities(key, value, hash) case value when Array value.map { |v| process_capabilities(key, v, hash) } when Hash value.each_with_object({}) do |(k, v), h| h[convert_key(k)] = process_capabilities(k, v, h) end when Capabilities, Options value.as_json else convert_value(key, value) end end
#to_json
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 212
def to_json(*) JSON.generate as_json end