Class: Selenium::WebDriver::Remote::Capabilities
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Remote::Capabilities
- Defined in:
- 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 collapse
- KNOWN =
[ :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 collapse
- .always_match(capabilities) ⇒ Object
- .camel_case(str_or_sym) ⇒ Object
- .chrome(opts = {}) ⇒ Object
- .edge(opts = {}) ⇒ Object (also: microsoftedge)
- .firefox(opts = {}) ⇒ Object (also: ff)
- .first_match(*capabilities) ⇒ Object
- .htmlunit(opts = {}) ⇒ Object
- .internet_explorer(opts = {}) ⇒ Object (also: ie)
- .json_create(data) ⇒ Object private
- .safari(opts = {}) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
Allows setting arbitrary capabilities.
- #as_json ⇒ Object private
- #implicit_timeout ⇒ Object
- #implicit_timeout=(timeout) ⇒ Object
-
#initialize(opts = {}) ⇒ Capabilities
constructor
A new instance of Capabilities.
- #merge!(other) ⇒ Object
- #page_load_timeout ⇒ Object
- #page_load_timeout=(timeout) ⇒ Object
- #proxy ⇒ Object
- #proxy=(proxy) ⇒ Object
- #script_timeout ⇒ Object
- #script_timeout=(timeout) ⇒ Object
- #timeouts ⇒ Object
- #timeouts=(timeouts) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Capabilities
Returns a new instance of Capabilities.
177 178 179 180 181 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 177 def initialize(opts = {}) @capabilities = {} self.proxy = opts.delete(:proxy) if opts[:proxy] @capabilities.merge!(opts) end |
Class Method Details
.always_match(capabilities) ⇒ Object
112 113 114 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 112 def always_match(capabilities) new(always_match: capabilities) end |
.camel_case(str_or_sym) ⇒ Object
151 152 153 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 151 def camel_case(str_or_sym) str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase } end |
.chrome(opts = {}) ⇒ Object
72 73 74 75 76 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 72 def chrome(opts = {}) new({ browser_name: 'chrome' }.merge(opts)) end |
.edge(opts = {}) ⇒ Object Also known as: microsoftedge
78 79 80 81 82 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 78 def edge(opts = {}) new({ browser_name: 'MicrosoftEdge' }.merge(opts)) end |
.firefox(opts = {}) ⇒ Object Also known as: ff
85 86 87 88 89 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 85 def firefox(opts = {}) new({ browser_name: 'firefox' }.merge(opts)) end |
.first_match(*capabilities) ⇒ Object
116 117 118 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 116 def first_match(*capabilities) new(first_match: capabilities) end |
.htmlunit(opts = {}) ⇒ Object
98 99 100 101 102 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 98 def htmlunit(opts = {}) new({ browser_name: 'htmlunit' }.merge(opts)) end |
.internet_explorer(opts = {}) ⇒ Object Also known as: ie
104 105 106 107 108 109 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 104 def internet_explorer(opts = {}) new({ browser_name: 'internet explorer', platform_name: :windows }.merge(opts)) end |
.json_create(data) ⇒ Object
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.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 124 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 |
.safari(opts = {}) ⇒ Object
92 93 94 95 96 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 92 def safari(opts = {}) new({ browser_name: Selenium::WebDriver::Safari.technology_preview? ? "Safari Technology Preview" : 'safari' }.merge(opts)) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
266 267 268 269 270 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 266 def ==(other) return false unless other.is_a? self.class as_json == other.as_json end |
#[](key) ⇒ Object
191 192 193 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 191 def [](key) @capabilities[key] end |
#[]=(key, value) ⇒ Object
Allows setting arbitrary capabilities.
187 188 189 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 187 def []=(key, value) @capabilities[key] = value end |
#as_json ⇒ Object
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.
256 257 258 259 260 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 256 def as_json(*) @capabilities.each_with_object({}) do |(key, value), hash| hash[convert_key(key)] = process_capabilities(key, value, hash) end end |
#implicit_timeout ⇒ Object
228 229 230 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 228 def implicit_timeout timeouts[:implicit] end |
#implicit_timeout=(timeout) ⇒ Object
232 233 234 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 232 def implicit_timeout=(timeout) timeouts[:implicit] = timeout end |
#merge!(other) ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 195 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 |
#page_load_timeout ⇒ Object
236 237 238 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 236 def page_load_timeout timeouts[:page_load] || timeouts[:pageLoad] end |
#page_load_timeout=(timeout) ⇒ Object
240 241 242 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 240 def page_load_timeout=(timeout) timeouts[:page_load] = timeout end |
#proxy ⇒ Object
205 206 207 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 205 def proxy @capabilities[:proxy] end |
#proxy=(proxy) ⇒ Object
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 209 def proxy=(proxy) case proxy when Hash @capabilities[:proxy] = Proxy.new(proxy) when Proxy, nil @capabilities[:proxy] = proxy else raise TypeError, "expected Hash or #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}" end end |
#script_timeout ⇒ Object
244 245 246 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 244 def script_timeout timeouts[:script] end |
#script_timeout=(timeout) ⇒ Object
248 249 250 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 248 def script_timeout=(timeout) timeouts[:script] = timeout end |
#timeouts ⇒ Object
220 221 222 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 220 def timeouts @capabilities[:timeouts] ||= {} end |
#timeouts=(timeouts) ⇒ Object
224 225 226 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 224 def timeouts=(timeouts) @capabilities[:timeouts] = timeouts end |
#to_json ⇒ Object
262 263 264 |
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 262 def to_json(*) JSON.generate as_json end |