class Selenium::WebDriver::Remote::W3C::Capabilities
Specification of the desired and/or actual capabilities of the browser that the server is being asked to create.
@api private
Constants
- EXTENSION_CAPABILITY_PATTERN
- KNOWN
Attributes
capabilities[R]
Public Class Methods
edge(opts = {})
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 92 def edge(opts = {}) WebDriver.logger.deprecate('Selenium::WebDriver::Remote::W3C::Capabilities.edge', 'Selenium::WebDriver::Remote::Capabilities.edge') Remote::Capabilities.edge(opts) end
firefox(opts = {})
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 98 def firefox(opts = {}) WebDriver.logger.deprecate('Selenium::WebDriver::Remote::W3C::Capabilities.firefox', 'Selenium::WebDriver::Remote::Capabilities.firefox') Remote::Capabilities.firefox(opts) end
Also aliased as: ff
from_oss(oss_capabilities)
click to toggle source
Creates W3C compliant capabilities from OSS ones. @param oss_capabilities [Hash, Remote::Capabilities]
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 147 def from_oss(oss_capabilities) # rubocop:disable Metrics/MethodLength w3c_capabilities = new # TODO: (alex) make capabilities enumerable? oss_capabilities = oss_capabilities.__send__(:capabilities) unless oss_capabilities.is_a?(Hash) oss_capabilities.each do |name, value| next if value.nil? next if value.is_a?(String) && value.empty? capability_name = name.to_s snake_cased_capability_names = KNOWN.map(&:to_s) camel_cased_capability_names = snake_cased_capability_names.map(&w3c_capabilities.method(:camel_case)) next unless snake_cased_capability_names.include?(capability_name) || camel_cased_capability_names.include?(capability_name) || capability_name.match(EXTENSION_CAPABILITY_PATTERN) w3c_capabilities[name] = value end # User can pass :firefox_options or :firefox_profile. # # TODO: (alex) Refactor this whole method into converter class. firefox_options = oss_capabilities['firefoxOptions'] || oss_capabilities['firefox_options'] || oss_capabilities[:firefox_options] firefox_profile = oss_capabilities['firefox_profile'] || oss_capabilities[:firefox_profile] firefox_binary = oss_capabilities['firefox_binary'] || oss_capabilities[:firefox_binary] if firefox_options WebDriver.logger.deprecate(':firefox_options capabilitiy', 'Selenium::WebDriver::Firefox::Options') end if firefox_profile WebDriver.logger.deprecate(':firefox_profile capabilitiy', 'Selenium::WebDriver::Firefox::Options#profile') end if firefox_binary WebDriver.logger.deprecate(':firefox_binary capabilitiy', 'Selenium::WebDriver::Firefox::Options#binary') end if firefox_profile && firefox_options second_profile = firefox_options['profile'] || firefox_options[:profile] if second_profile && firefox_profile != second_profile raise Error::WebDriverError, 'You cannot pass 2 different Firefox profiles' end end if firefox_options || firefox_profile || firefox_binary options = WebDriver::Firefox::Options.new(firefox_options || {}) options.binary = firefox_binary if firefox_binary options.profile = firefox_profile if firefox_profile w3c_capabilities.merge!(options.as_json) end w3c_capabilities end
json_create(data)
click to toggle source
@api private
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 110 def json_create(data) data = data.dup caps = new caps.browser_name = data.delete('browserName') caps.browser_version = data.delete('browserVersion') caps.platform_name = data.delete('platformName') caps.accept_insecure_certs = data.delete('acceptInsecureCerts') if data.key?('acceptInsecureCerts') caps.page_load_strategy = data.delete('pageLoadStrategy') timeouts = data.delete('timeouts') caps.implicit_timeout = timeouts['implicit'] if timeouts caps.page_load_timeout = timeouts['pageLoad'] if timeouts caps.script_timeout = timeouts['script'] if timeouts proxy = data.delete('proxy') caps.proxy = Proxy.json_create(proxy) unless proxy.nil? || proxy.empty? # Remote Server Specific caps[:remote_session_id] = data.delete('webdriver.remote.sessionid') # Marionette Specific caps[:accessibility_checks] = data.delete('moz:accessibilityChecks') caps[:profile] = data.delete('moz:profile') caps[:rotatable] = data.delete('rotatable') caps[:device] = data.delete('device') # any remaining pairs will be added as is, with no conversion caps.merge!(data) caps end
new(opts = {})
click to toggle source
@param [Hash] opts @option :browser_name [String] required browser name @option :browser_version [String] required browser version number @option :platform_name [Symbol] one of :any, :win, :mac, or :x @option :accept_insecure_certs [Boolean] does the driver accept insecure SSL certifications? @option :proxy [Selenium::WebDriver::Proxy, Hash] proxy configuration
@api public
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 216 def initialize(opts = {}) @capabilities = opts self.proxy = opts.delete(:proxy) end
Public Instance Methods
==(other)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 287 def ==(other) return false unless other.is_a? self.class as_json == other.as_json end
Also aliased as: eql?
[](key)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 229 def [](key) @capabilities[key] end
[]=(key, value)
click to toggle source
Allows setting arbitrary capabilities.
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 225 def []=(key, value) @capabilities[key] = value end
as_json(*)
click to toggle source
@api private
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 258 def as_json(*) hash = {} @capabilities.each do |key, value| case key when :platform hash['platform'] = value.to_s.upcase when :proxy if value hash['proxy'] = value.as_json hash['proxy']['proxyType'] &&= hash['proxy']['proxyType'].downcase hash['proxy']['noProxy'] = hash['proxy']['noProxy'].split(', ') if hash['proxy']['noProxy'].is_a?(String) end when String, :firefox_binary hash[key.to_s] = value when Symbol hash[camel_case(key.to_s)] = value else raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class} / #{value.inspect}" end end hash end
merge!(other)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 233 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
proxy=(proxy)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 243 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
to_json(*)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 283 def to_json(*) JSON.generate as_json end
Private Instance Methods
camel_case(str)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/capabilities.rb, line 301 def camel_case(str) str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase } end