Class: Selenium::WebDriver::Remote::W3CCapabilities Private

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/remote/w3c_capabilities.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Specification of the desired and/or actual capabilities of the browser that the server is being asked to create.

Constant Summary collapse

DEFAULTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  :browser_name => '',
  :browser_version => :any,
  :platform_name => :any,
  :platform_version => :any,
  :accept_ssl_certs => false,
  :takes_screenshot => false,
  :takes_element_screenshot => false,
  :page_load_strategy => 'normal',
  :proxy => nil
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ W3CCapabilities

Returns a new instance of W3CCapabilities.

Parameters:

  • opts (Hash) (defaults to: {})
  • :browser_name (Hash)

    a customizable set of options

  • :browser_version (Hash)

    a customizable set of options

  • :platform_name (Hash)

    a customizable set of options

  • :platform_version (Hash)

    a customizable set of options

  • :accept_ssl_certs (Hash)

    a customizable set of options

  • :takes_screenshot (Hash)

    a customizable set of options

  • :takes_element_screenshot (Hash)

    a customizable set of options

  • :proxy (Hash)

    a customizable set of options



120
121
122
123
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 120

def initialize(opts = {})
  @capabilities = DEFAULTS.merge(opts)
  self.proxy = opts.delete(:proxy)
end

Class Method Details

.edge(opts = {}) ⇒ 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.



59
60
61
62
63
64
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 59

def edge(opts = {})
  new({
    :browser_name => "MicrosoftEdge",
    :platform => :windows,
      }.merge(opts))
end

.firefox(opts = {}) ⇒ Object Also known as: ff

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.



66
67
68
69
70
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 66

def firefox(opts = {})
  new({
    :browser_name => "firefox"
      }.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.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 86

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").downcase.to_sym if data.has_key?('platform')
  caps.platform_version = data.delete("platformVersion")
  caps.accept_ssl_certs = data.delete("acceptSslCerts")
  caps.takes_screenshot = data.delete("takesScreenshot  ")
  caps.takes_element_screenshot = data.delete("takesElementScreenshot")
  caps.page_load_strategy = data.delete("pageLoadStrategy")
  caps.proxy = Proxy.json_create(data['proxy']) if data.has_key?('proxy')

  # any remaining pairs will be added as is, with no conversion
  caps.merge!(data)

  caps
end

.w3c?(opts = {}) ⇒ Boolean

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.

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 74

def w3c?(opts = {})
  return false unless opts[:desired_capabilities].is_a?(W3CCapabilities) || opts.delete(:marionette)
  Firefox::Binary.path = ENV['MARIONETTE_PATH'] if ENV['MARIONETTE_PATH']
  firefox_version = Firefox::Binary.version
  raise ArgumentError, "Firefox Version #{firefox_version} does not support W3CCapabilities" if firefox_version < 43
  true
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

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.



186
187
188
189
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 186

def ==(other)
  return false unless other.kind_of? self.class
  as_json == other.as_json
end

#[](key) ⇒ 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.



133
134
135
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 133

def [](key)
  @capabilities[key]
end

#[]=(key, value) ⇒ 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.

Allows setting arbitrary capabilities.



129
130
131
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 129

def []=(key, value)
  @capabilities[key] = value
end

#as_json(opts = nil) ⇒ 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.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 161

def as_json(opts = nil)
  hash = {}

  @capabilities.each do |key, value|
    case key
    when :platform
      hash['platform'] = value.to_s.upcase
    when :proxy
      hash['proxy'] = value.as_json if value
    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) ⇒ 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.



137
138
139
140
141
142
143
144
145
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 137

def merge!(other)
  if other.respond_to?(:capabilities, true) && other.capabilities.kind_of?(Hash)
    @capabilities.merge! other.capabilities
  elsif other.kind_of? Hash
    @capabilities.merge! other
  else
    raise ArgumentError, "argument should be a Hash or implement #capabilities"
  end
end

#proxy=(proxy) ⇒ 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.



147
148
149
150
151
152
153
154
155
156
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 147

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(*args) ⇒ 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.



182
183
184
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 182

def to_json(*args)
  WebDriver.json_dump as_json
end