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.

API:

  • private

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.

API:

  • private

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ W3CCapabilities

Returns a new instance of W3CCapabilities.

Parameters:

  • (defaults to: {})
  • a customizable set of options

  • a customizable set of options

  • a customizable set of options

  • a customizable set of options

  • a customizable set of options

  • a customizable set of options

  • a customizable set of options

  • a customizable set of options

API:

  • public



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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:

Raises:

API:

  • private



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(:wires)
  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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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

def to_json(*args)
  WebDriver.json_dump as_json
end