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

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

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Capabilities

Returns a new instance of Capabilities.

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



105
106
107
108
109
110
111
112
113
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 105

def initialize(opts = {})
  @browser_name          = opts[:browser_name]          || ""
  @version               = opts[:version]               || ""
  @platform              = opts[:platform]              || :any
  @javascript_enabled    = opts[:javascript_enabled]    || false
  @css_selectors_enabled = opts[:css_selectors_enabled] || false
  @takes_screenshot      = opts[:takes_screenshot]      || false
  @native_events         = opts[:native_events]         || false
end

Instance Attribute Details

#browser_nameObject

Returns the value of attribute browser_name.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def browser_name
  @browser_name
end

#css_selectors_enabledObject Also known as: css_selectors_enabled?

Returns the value of attribute css_selectors_enabled.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def css_selectors_enabled
  @css_selectors_enabled
end

#javascript_enabledObject Also known as: javascript_enabled?

Returns the value of attribute javascript_enabled.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def javascript_enabled
  @javascript_enabled
end

#native_eventsObject Also known as: native_events?

Returns the value of attribute native_events.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def native_events
  @native_events
end

#platformObject

Returns the value of attribute platform.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def platform
  @platform
end

#takes_screenshotObject Also known as: takes_screenshot?

Returns the value of attribute takes_screenshot.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def takes_screenshot
  @takes_screenshot
end

#versionObject

Returns the value of attribute version.



11
12
13
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 11

def version
  @version
end

Class Method Details

.android(opts = {}) ⇒ Object



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

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

.chrome(opts = {}) ⇒ Object



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

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

.firefox(opts = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 29

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

.htmlunit(opts = {}) ⇒ Object



43
44
45
46
47
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 43

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

.internet_explorer(opts = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 36

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

.iphone(opts = {}) ⇒ Object



56
57
58
59
60
61
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 56

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



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 81

def json_create(data)
  new(
    :browser_name          => data["browserName"],
    :version               => data["version"],
    :platform              => data["platform"].downcase.to_sym,
    :javascript_enabled    => data["javascriptEnabled"],
    :css_selectors_enabled => data["cssSelectorsEnabled"],
    :takes_screenshot      => data["takesScreenshot"],
    :native_events         => data["nativeEvents"]
  )
end

.safari(opts = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 49

def safari(opts = {})
  new({
    :browser_name => "safari",
    :platform     => :mac
  }.merge(opts))
end

Instance Method Details

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



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 119

def as_json(opts = nil)
  {
    "browserName"         => browser_name,
    "version"             => version,
    "platform"            => platform.to_s.upcase,
    "javascriptEnabled"   => javascript_enabled?,
    "cssCelectorsEnabled" => css_selectors_enabled?,
    "takesScreenshot"     => takes_screenshot?,
    "nativeEvents"        => native_events?
  }
end

#to_json(*args) ⇒ Object



131
132
133
# File 'lib/selenium/webdriver/remote/capabilities.rb', line 131

def to_json(*args)
  as_json.to_json(*args)
end