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,
  page_load_strategy: 'normal',
  proxy: nil
}.freeze
KNOWN =

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.

[
  :remote_session_id,
  :xul_app_id,
  :raise_accessibility_exceptions,
  :rotatable,
  :app_build_id,
  :device
].freeze

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

  • :proxy (Hash)

    a customizable set of options



143
144
145
146
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 143

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.



71
72
73
74
75
76
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 71

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.



78
79
80
81
82
83
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 78

def firefox(opts = {})
  opts[:browser_version] = opts.delete :version
  opts[:platform_name] = opts.delete :platform

  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.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 95

def json_create(data)
  data = data.dup

  # Convert due to Remote Driver implementation
  data['browserVersion'] = data.delete('version') if data.key? 'version'
  data['platformName'] = data.delete('platform') if data.key? 'platform'

  caps = new
  caps.browser_name = data.delete('browserName')
  caps.browser_version = data.delete('browserVersion')
  caps.platform_name = data.delete('platformName')
  caps.platform_version = data.delete('platformVersion')
  caps.accept_ssl_certs = data.delete('acceptSslCerts')
  caps.page_load_strategy = data.delete('pageLoadStrategy')
  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')

  # Obsolete capabilities returned by Remote Server
  data.delete('javascriptEnabled')
  data.delete('cssSelectorsEnabled')

  # Marionette Specific
  caps[:xul_app_id] = data.delete('XULappId')
  caps[:raise_accessibility_exceptions] = data.delete('raisesAccessibilityExceptions')
  caps[:rotatable] = data.delete('rotatable')
  caps[:app_build_id] = data.delete('appBuildId')
  caps[:device] = data.delete('device')

  # 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)


87
88
89
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 87

def w3c?(opts = {})
  !opts[:desired_capabilities].is_a?(Capabilities)
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.



211
212
213
214
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 211

def ==(other)
  return false unless other.is_a? 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.



156
157
158
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 156

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.



152
153
154
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 152

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

#as_jsonObject

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.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 184

def as_json(*)
  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 :firefox_options
      hash['moz:firefoxOptions'] = 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.



160
161
162
163
164
165
166
167
168
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 160

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) ⇒ 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.



170
171
172
173
174
175
176
177
178
179
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 170

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_jsonObject

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.



207
208
209
# File 'lib/selenium/webdriver/remote/w3c_capabilities.rb', line 207

def to_json(*)
  JSON.generate as_json
end