Class: Selenium::WebDriver::Remote::Capabilities Private

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/remote/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

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          => "",
  :version               => "",
  :platform              => :any,
  :javascript_enabled    => false,
  :css_selectors_enabled => false,
  :takes_screenshot      => false,
  :native_events         => false,
  :rotatable             => false,
  :firefox_profile       => nil,
  :proxy                 => nil
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Capabilities) initialize(opts = {})

Firefox-specific options:

Parameters:

  • :browser_name (Hash)

    a customizable set of options

  • :version (Hash)

    a customizable set of options

  • :platform (Hash)

    a customizable set of options

  • :javascript_enabled (Hash)

    a customizable set of options

  • :css_selectors_enabled (Hash)

    a customizable set of options

  • :takes_screenshot (Hash)

    a customizable set of options

  • :native_events (Hash)

    a customizable set of options

  • :proxy (Hash)

    a customizable set of options

  • :firefox_profile (Hash)

    a customizable set of options



161
162
163
164
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 161

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

Class Method Details

+ (Object) android(opts = {})

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.



44
45
46
47
48
49
50
51
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 44

def android(opts = {})
  new({
    :browser_name     => "android",
    :platform         => :android,
    :rotatable        => true,
    :takes_screenshot => true
  }.merge(opts))
end

+ (Object) chrome(opts = {})

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.



53
54
55
56
57
58
59
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 53

def chrome(opts = {})
  new({
    :browser_name          => "chrome",
    :javascript_enabled    => true,
    :css_selectors_enabled => true
  }.merge(opts))
end

+ (Object) firefox(opts = {})

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.



61
62
63
64
65
66
67
68
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 61

def firefox(opts = {})
  new({
    :browser_name          => "firefox",
    :javascript_enabled    => true,
    :takes_screenshot      => true,
    :css_selectors_enabled => true
  }.merge(opts))
end

+ (Object) htmlunit(opts = {})

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.



70
71
72
73
74
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 70

def htmlunit(opts = {})
  new({
    :browser_name => "htmlunit"
  }.merge(opts))
end

+ (Object) internet_explorer(opts = {}) Also known as: ie

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.



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

def internet_explorer(opts = {})
  new({
    :browser_name          => "internet explorer",
    :platform              => :windows,
    :takes_screenshot      => true,
    :css_selectors_enabled => true
  }.merge(opts))
end

+ (Object) ipad(opts = {})

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.



94
95
96
97
98
99
100
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 94

def ipad(opts = {})
  new({
    :browser_name       => "iPad",
    :platform           => :mac,
    :javascript_enabled => true
  }.merge(opts))
end

+ (Object) iphone(opts = {})

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
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 86

def iphone(opts = {})
  new({
    :browser_name       => "iPhone",
    :platform           => :mac,
    :javascript_enabled => true
  }.merge(opts))
end

+ (Object) json_create(data)

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
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 124

def json_create(data)
  data = data.dup

  caps = new
  caps.browser_name          = data.delete("browserName")
  caps.version               = data.delete("version")
  caps.platform              = data.delete("platform").downcase.to_sym
  caps.javascript_enabled    = data.delete("javascriptEnabled")
  caps.css_selectors_enabled = data.delete("cssSelectorsEnabled")
  caps.takes_screenshot      = data.delete("takesScreenshot")
  caps.native_events         = data.delete("nativeEvents")
  caps.rotatable             = data.delete("rotatable")
  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

+ (Object) opera(opts = {})

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.



102
103
104
105
106
107
108
109
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 102

def opera(opts = {})
  new({
    :browser_name          => "opera",
    :javascript_enabled    => true,
    :takes_screenshot      => true,
    :css_selectors_enabled => true
  }.merge(opts))
end

+ (Object) safari(opts = {})

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.



111
112
113
114
115
116
117
118
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 111

def safari(opts = {})
  new({
    :browser_name          => "safari",
    :javascript_enabled    => true,
    :takes_screenshot      => true,
    :css_selectors_enabled => true
  }.merge(opts))
end

Instance Method Details

- (Object) ==(other) 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.



229
230
231
232
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 229

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

- (Object) [](key)

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.



174
175
176
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 174

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

- (Object) []=(key, value)

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.



170
171
172
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 170

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

- (Object) as_json(opts = nil)

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.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 202

def as_json(opts = nil)
  hash = {}

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

- (Object) merge!(other)

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.



178
179
180
181
182
183
184
185
186
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 178

def merge!(other)
  if other.respond_to?(:capabilities) && 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

- (Object) proxy=(proxy)

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.



188
189
190
191
192
193
194
195
196
197
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 188

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

- (Object) to_json(*args)

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.



225
226
227
# File 'rb/lib/selenium/webdriver/remote/capabilities.rb', line 225

def to_json(*args)
  WebDriver.json_dump as_json
end