Class: Selenium::WebDriver::Remote::Bridge
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Remote::Bridge
show all
- Includes:
- BridgeHelper, Find
- Defined in:
- lib/selenium/webdriver/remote/bridge.rb,
lib/selenium/webdriver/remote/commands.rb
Constant Summary
collapse
- QUIT_ERRORS =
[IOError]
Constants included
from Find
Find::FINDERS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#addCookie(cookie) ⇒ Object
-
#browser ⇒ Object
-
#clearElement(element) ⇒ Object
-
#clickElement(element) ⇒ Object
-
#close ⇒ Object
-
#create_session(desired_capabilities) ⇒ Object
-
#deleteAllCookies ⇒ Object
-
#deleteCookie(name) ⇒ Object
-
#dragElement(element, rigth_by, down_by) ⇒ Object
-
#driver_extensions ⇒ Object
-
#elementEquals(element, other) ⇒ Object
-
#executeScript(script, *args) ⇒ Object
-
#findElementByClassName(parent, class_name) ⇒ Object
-
#findElementById(parent, id) ⇒ Object
-
#findElementByLinkText(parent, link_text) ⇒ Object
-
#findElementByName(parent, name) ⇒ Object
-
#findElementByPartialLinkText(parent, link_text) ⇒ Object
-
#findElementByTagName(parent, tag_name) ⇒ Object
-
#findElementByXpath(parent, xpath) ⇒ Object
-
#findElementsByClassName(parent, class_name) ⇒ Object
-
#findElementsById(parent, id) ⇒ Object
-
#findElementsByLinkText(parent, link_text) ⇒ Object
-
#findElementsByName(parent, name) ⇒ Object
-
#findElementsByPartialLinkText(parent, link_text) ⇒ Object
-
#findElementsByTagName(parent, tag_name) ⇒ Object
-
#findElementsByXpath(parent, xpath) ⇒ Object
-
#get(url) ⇒ Object
-
#getActiveElement ⇒ Object
(also: #switchToActiveElement)
-
#getAllCookies ⇒ Object
-
#getCapabilities ⇒ Object
-
#getCurrentUrl ⇒ Object
-
#getCurrentWindowHandle ⇒ Object
-
#getElementAttribute(element, name) ⇒ Object
-
#getElementLocation(element) ⇒ Object
-
#getElementSize(element) ⇒ Object
-
#getElementTagName(element) ⇒ Object
-
#getElementText(element) ⇒ Object
-
#getElementValue(element) ⇒ Object
-
#getElementValueOfCssProperty(element, prop) ⇒ Object
-
#getPageSource ⇒ Object
-
#getSpeed ⇒ Object
-
#getTitle ⇒ Object
-
#getVisible ⇒ Object
-
#getWindowHandles ⇒ Object
-
#goBack ⇒ Object
-
#goForward ⇒ Object
-
#hoverOverElement(element) ⇒ Object
-
#initialize(opts = {}) ⇒ Bridge
constructor
Initializes the bridge with the given server URL.
-
#isElementDisplayed(element) ⇒ Object
-
#isElementEnabled(element) ⇒ Object
-
#isElementSelected(element) ⇒ Object
-
#quit ⇒ Object
-
#refresh ⇒ Object
-
#sendKeysToElement(element, string) ⇒ Object
-
#session_id ⇒ Object
Returns the current session ID.
-
#setElementSelected(element) ⇒ Object
-
#setImplicitWaitTimeout(milliseconds) ⇒ Object
-
#setSpeed(value) ⇒ Object
-
#setVisible(bool) ⇒ Object
-
#submitElement(element) ⇒ Object
-
#switchToDefaultContent ⇒ Object
-
#switchToFrame(id) ⇒ Object
-
#switchToWindow(name) ⇒ Object
-
#toggleElement(element) ⇒ Object
#element_id_from, #parse_cookie_string, #unwrap_script_result
Methods included from Find
#find_element, #find_elements
Constructor Details
#initialize(opts = {}) ⇒ Bridge
Initializes the bridge with the given server URL.
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 44
def initialize(opts = {})
opts = default_options.merge(opts)
http_client_class = opts.delete(:http_client)
desired_capabilities = opts.delete(:desired_capabilities)
url = opts.delete(:url)
unless opts.empty?
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
end
if desired_capabilities.kind_of?(Symbol)
unless Capabilities.respond_to?(desired_capabilities)
raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
end
desired_capabilities = Capabilities.send(desired_capabilities)
end
uri = URI.parse(url)
uri.path += "/" unless uri.path =~ /\/$/
@http = http_client_class.new uri
@capabilities = create_session(desired_capabilities)
end
|
Instance Attribute Details
#capabilities ⇒ Object
Returns the value of attribute capabilities.
34
35
36
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 34
def capabilities
@capabilities
end
|
#context ⇒ Object
Returns the value of attribute context.
33
34
35
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 33
def context
@context
end
|
#http ⇒ Object
Returns the value of attribute http.
33
34
35
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 33
def http
@http
end
|
Class Method Details
.command(name, verb, url) ⇒ Object
Defines a wrapper method for a command, which ultimately calls #execute.
29
30
31
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 29
def self.command(name, verb, url)
COMMANDS[name] = [verb, url.freeze]
end
|
Instance Method Details
#addCookie(cookie) ⇒ Object
184
185
186
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 184
def addCookie(cookie)
execute :addCookie, {}, :cookie => cookie
end
|
#browser ⇒ Object
69
70
71
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 69
def browser
@browser ||= @capabilities.browser_name.gsub(" ", "_").to_sym
end
|
#clearElement(element) ⇒ Object
297
298
299
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 297
def clearElement(element)
execute :clearElement, :id => element
end
|
#clickElement(element) ⇒ Object
261
262
263
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 261
def clickElement(element)
execute :clickElement, :id => element
end
|
#close ⇒ Object
151
152
153
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 151
def close
execute :close
end
|
#create_session(desired_capabilities) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 85
def create_session(desired_capabilities)
resp = raw_execute :newSession, {}, :desiredCapabilities => desired_capabilities
@session_id = resp['sessionId'] || raise(Error::WebDriverError, 'no sessionId in returned payload')
Capabilities.json_create resp['value']
end
|
#deleteAllCookies ⇒ Object
196
197
198
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 196
def deleteAllCookies
execute :deleteAllCookies
end
|
#deleteCookie(name) ⇒ Object
188
189
190
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 188
def deleteCookie(name)
execute :deleteCookieNamed, :name => name
end
|
#dragElement(element, rigth_by, down_by) ⇒ Object
338
339
340
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 338
def dragElement(element, rigth_by, down_by)
execute :dragElement, {:id => element}, :x => rigth_by, :y => down_by
end
|
#driver_extensions ⇒ Object
73
74
75
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 73
def driver_extensions
[]
end
|
#elementEquals(element, other) ⇒ Object
342
343
344
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 342
def elementEquals(element, other)
execute :elementEquals, :id => element.ref, :other => other.ref
end
|
#executeScript(script, *args) ⇒ Object
175
176
177
178
179
180
181
182
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 175
def executeScript(script, *args)
unless capabilities.javascript?
raise Error::UnsupportedOperationError, "underlying webdriver instance does not support javascript"
end
result = execute :executeScript, {}, :script => script, :args => args
unwrap_script_result result
end
|
#findElementByClassName(parent, class_name) ⇒ Object
200
201
202
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 200
def findElementByClassName(parent, class_name)
find_element_by 'class name', class_name, parent
end
|
#findElementById(parent, id) ⇒ Object
208
209
210
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 208
def findElementById(parent, id)
find_element_by 'id', id, parent
end
|
#findElementByLinkText(parent, link_text) ⇒ Object
216
217
218
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 216
def findElementByLinkText(parent, link_text)
find_element_by 'link text', link_text, parent
end
|
#findElementByName(parent, name) ⇒ Object
232
233
234
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 232
def findElementByName(parent, name)
find_element_by 'name', name, parent
end
|
#findElementByPartialLinkText(parent, link_text) ⇒ Object
224
225
226
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 224
def findElementByPartialLinkText(parent, link_text)
find_element_by 'partial link text', link_text, parent
end
|
#findElementByTagName(parent, tag_name) ⇒ Object
240
241
242
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 240
def findElementByTagName(parent, tag_name)
find_element_by 'tag name', tag_name, parent
end
|
#findElementByXpath(parent, xpath) ⇒ Object
248
249
250
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 248
def findElementByXpath(parent, xpath)
find_element_by 'xpath', xpath, parent
end
|
#findElementsByClassName(parent, class_name) ⇒ Object
204
205
206
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 204
def findElementsByClassName(parent, class_name)
find_elements_by 'class name', class_name, parent
end
|
#findElementsById(parent, id) ⇒ Object
212
213
214
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 212
def findElementsById(parent, id)
find_elements_by 'id', id, parent
end
|
#findElementsByLinkText(parent, link_text) ⇒ Object
220
221
222
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 220
def findElementsByLinkText(parent, link_text)
find_elements_by 'link text', link_text, parent
end
|
#findElementsByName(parent, name) ⇒ Object
236
237
238
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 236
def findElementsByName(parent, name)
find_elements_by 'name', name, parent
end
|
#findElementsByPartialLinkText(parent, link_text) ⇒ Object
228
229
230
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 228
def findElementsByPartialLinkText(parent, link_text)
find_elements_by 'partial link text', link_text, parent
end
|
#findElementsByTagName(parent, tag_name) ⇒ Object
244
245
246
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 244
def findElementsByTagName(parent, tag_name)
find_elements_by 'tag name', tag_name, parent
end
|
#findElementsByXpath(parent, xpath) ⇒ Object
252
253
254
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 252
def findElementsByXpath(parent, xpath)
find_elements_by 'xpath', xpath, parent
end
|
#get(url) ⇒ Object
92
93
94
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 92
def get(url)
execute :get, {}, :url => url
end
|
#getActiveElement ⇒ Object
Also known as:
switchToActiveElement
329
330
331
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 329
def getActiveElement
Element.new self, element_id_from(execute(:getActiveElement))
end
|
#getAllCookies ⇒ Object
192
193
194
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 192
def getAllCookies
execute :getAllCookies
end
|
#getCapabilities ⇒ Object
96
97
98
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 96
def getCapabilities
Capabilities.json_create execute(:getCapabilities)
end
|
#getCurrentUrl ⇒ Object
112
113
114
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 112
def getCurrentUrl
execute :getCurrentUrl
end
|
#getCurrentWindowHandle ⇒ Object
163
164
165
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 163
def getCurrentWindowHandle
execute :getCurrentWindowHandle
end
|
#getElementAttribute(element, name) ⇒ Object
269
270
271
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 269
def getElementAttribute(element, name)
execute :getElementAttribute, :id => element, :name => name
end
|
#getElementLocation(element) ⇒ Object
281
282
283
284
285
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 281
def getElementLocation(element)
data = execute :getElementLocation, :id => element
Point.new data['x'], data['y']
end
|
#getElementSize(element) ⇒ Object
287
288
289
290
291
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 287
def getElementSize(element)
data = execute :getElementSize, :id => element
Dimension.new data['width'], data['height']
end
|
#getElementTagName(element) ⇒ Object
265
266
267
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 265
def getElementTagName(element)
execute :getElementTagName, :id => element
end
|
#getElementText(element) ⇒ Object
277
278
279
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 277
def getElementText(element)
execute :getElementText, :id => element
end
|
#getElementValue(element) ⇒ Object
273
274
275
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 273
def getElementValue(element)
execute :getElementValue, :id => element
end
|
#getElementValueOfCssProperty(element, prop) ⇒ Object
325
326
327
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 325
def getElementValueOfCssProperty(element, prop)
execute :getElementValueOfCssProperty, :id => element, :property_name => prop
end
|
#getPageSource ⇒ Object
120
121
122
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 120
def getPageSource
execute :getPageSource
end
|
#getSpeed ⇒ Object
171
172
173
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 171
def getSpeed
execute :getSpeed
end
|
#getTitle ⇒ Object
116
117
118
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 116
def getTitle
execute :getTitle
end
|
#getVisible ⇒ Object
124
125
126
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 124
def getVisible
execute :getVisible
end
|
#getWindowHandles ⇒ Object
159
160
161
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 159
def getWindowHandles
execute :getWindowHandles
end
|
#goBack ⇒ Object
104
105
106
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 104
def goBack
execute :goBack
end
|
#goForward ⇒ Object
108
109
110
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 108
def goForward
execute :goForward
end
|
#hoverOverElement(element) ⇒ Object
334
335
336
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 334
def hoverOverElement(element)
execute :hoverOverElement, :id => element
end
|
#isElementDisplayed(element) ⇒ Object
309
310
311
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 309
def isElementDisplayed(element)
execute :isElementDisplayed, :id => element
end
|
#isElementEnabled(element) ⇒ Object
301
302
303
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 301
def isElementEnabled(element)
execute :isElementEnabled, :id => element
end
|
#isElementSelected(element) ⇒ Object
305
306
307
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 305
def isElementSelected(element)
execute :isElementSelected, :id => element
end
|
#quit ⇒ Object
146
147
148
149
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 146
def quit
execute :quit
rescue *QUIT_ERRORS
end
|
#refresh ⇒ Object
155
156
157
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 155
def refresh
execute :refresh
end
|
#sendKeysToElement(element, string) ⇒ Object
293
294
295
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 293
def sendKeysToElement(element, string)
execute :sendKeysToElement, {:id => element}, {:value => string.split(//u)}
end
|
#session_id ⇒ Object
Returns the current session ID.
81
82
83
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 81
def session_id
@session_id || raise(Error::WebDriverError, "no current session exists")
end
|
#setElementSelected(element) ⇒ Object
321
322
323
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 321
def setElementSelected(element)
execute :setElementSelected, :id => element
end
|
#setImplicitWaitTimeout(milliseconds) ⇒ Object
100
101
102
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 100
def setImplicitWaitTimeout(milliseconds)
execute :setImplicitWaitTimeout, {}, :ms => milliseconds
end
|
#setSpeed(value) ⇒ Object
167
168
169
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 167
def setSpeed(value)
execute :setSpeed, {}, :speed => value
end
|
#setVisible(bool) ⇒ Object
128
129
130
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 128
def setVisible(bool)
execute :setVisible, {}, bool
end
|
#submitElement(element) ⇒ Object
313
314
315
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 313
def submitElement(element)
execute :submitElement, :id => element
end
|
#switchToDefaultContent ⇒ Object
140
141
142
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 140
def switchToDefaultContent
execute :switchToFrame, {}, :id => nil
end
|
#switchToFrame(id) ⇒ Object
136
137
138
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 136
def switchToFrame(id)
execute :switchToFrame, {}, :id => id
end
|
#switchToWindow(name) ⇒ Object
132
133
134
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 132
def switchToWindow(name)
execute :switchToWindow, {}, :name => name
end
|
#toggleElement(element) ⇒ Object
317
318
319
|
# File 'lib/selenium/webdriver/remote/bridge.rb', line 317
def toggleElement(element)
execute :toggleElement, :id => element
end
|