selenium-webdriver 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
- data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
- data/chrome/src/extension/background.js +64 -48
- data/chrome/src/extension/content_script.js +253 -132
- data/chrome/src/extension/manifest-nonwin.json +1 -1
- data/chrome/src/extension/manifest-win.json +1 -1
- data/chrome/src/extension/utils.js +8 -8
- data/chrome/src/rb/lib/selenium/webdriver/chrome.rb +9 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/bridge.rb +38 -280
- data/chrome/src/rb/lib/selenium/webdriver/chrome/command_executor.rb +119 -117
- data/chrome/src/rb/lib/selenium/webdriver/chrome/launcher.rb +36 -26
- data/common/src/js/abstractcommandprocessor.js +9 -11
- data/common/src/js/command.js +159 -83
- data/common/src/js/core/RemoteRunner.html +2 -2
- data/common/src/js/core/TestRunner-splash.html +3 -3
- data/common/src/js/core/TestRunner.html +5 -17
- data/common/src/js/core/scripts/htmlutils.js +4208 -2506
- data/common/src/js/core/scripts/selenium-api.js +2 -2
- data/common/src/js/core/scripts/selenium-browserbot.js +66 -58
- data/common/src/js/core/scripts/selenium-version.js +1 -1
- data/common/src/js/localcommandprocessor.js +5 -19
- data/common/src/js/testcase.js +2 -0
- data/common/src/js/webdriver.js +63 -93
- data/common/src/js/webelement.js +40 -42
- data/common/src/rb/lib/selenium/webdriver.rb +23 -14
- data/common/src/rb/lib/selenium/webdriver/bridge_helper.rb +8 -35
- data/common/src/rb/lib/selenium/webdriver/child_process.rb +2 -0
- data/common/src/rb/lib/selenium/webdriver/core_ext/dir.rb +1 -0
- data/common/src/rb/lib/selenium/webdriver/core_ext/string.rb +5 -0
- data/common/src/rb/lib/selenium/webdriver/driver.rb +20 -15
- data/common/src/rb/lib/selenium/webdriver/driver_extensions/takes_screenshot.rb +7 -2
- data/common/src/rb/lib/selenium/webdriver/element.rb +11 -2
- data/common/src/rb/lib/selenium/webdriver/error.rb +9 -5
- data/common/src/rb/lib/selenium/webdriver/keys.rb +1 -2
- data/common/src/rb/lib/selenium/webdriver/navigation.rb +16 -0
- data/common/src/rb/lib/selenium/webdriver/options.rb +32 -0
- data/common/src/rb/lib/selenium/webdriver/platform.rb +17 -1
- data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
- data/firefox/src/extension/components/dispatcher.js +492 -0
- data/firefox/src/extension/components/driver-component.js +4 -1
- data/firefox/src/extension/components/errorcode.js +70 -0
- data/firefox/src/extension/components/firefoxDriver.js +173 -154
- data/firefox/src/extension/components/nsCommandProcessor.js +171 -132
- data/firefox/src/extension/components/promptService.js +5 -5
- data/firefox/src/extension/components/request.js +219 -0
- data/firefox/src/extension/components/response.js +276 -0
- data/firefox/src/extension/components/session.js +281 -0
- data/firefox/src/extension/components/sessionstore.js +226 -0
- data/firefox/src/extension/components/socketListener.js +350 -100
- data/firefox/src/extension/components/utils.js +166 -98
- data/firefox/src/extension/components/webdriverserver.js +9 -5
- data/firefox/src/extension/components/wrappedElement.js +189 -166
- data/firefox/src/extension/install.rdf +1 -1
- data/firefox/src/rb/lib/selenium/webdriver/firefox.rb +2 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/binary.rb +39 -33
- data/firefox/src/rb/lib/selenium/webdriver/firefox/bridge.rb +7 -421
- data/firefox/src/rb/lib/selenium/webdriver/firefox/extension_connection.rb +7 -64
- data/firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb +2 -3
- data/firefox/src/rb/lib/selenium/webdriver/firefox/profile.rb +54 -10
- data/firefox/src/rb/lib/selenium/webdriver/firefox/profiles_ini.rb +2 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/util.rb +6 -0
- data/jobbie/prebuilt/Win32/Release/InternetExplorerDriver.dll +0 -0
- data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie.rb +2 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/bridge.rb +38 -13
- data/jobbie/src/rb/lib/selenium/webdriver/ie/lib.rb +9 -2
- data/jobbie/src/rb/lib/selenium/webdriver/ie/util.rb +5 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote.rb +2 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb +42 -38
- data/remote/client/src/rb/lib/selenium/webdriver/remote/commands.rb +56 -47
- data/remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb +26 -26
- data/remote/client/src/rb/lib/selenium/webdriver/remote/patron_http_client.rb +58 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/response.rb +10 -12
- data/remote/client/src/rb/lib/selenium/webdriver/remote/server_error.rb +2 -17
- metadata +44 -23
- data/common/src/js/context.js +0 -58
- data/firefox/src/extension/components/context.js +0 -37
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<Description about="urn:mozilla:install-manifest">
|
|
5
5
|
<em:id>fxdriver@googlecode.com</em:id>
|
|
6
6
|
<em:name>Firefox WebDriver</em:name>
|
|
7
|
-
<em:version>2.
|
|
7
|
+
<em:version>2.0a3</em:version>
|
|
8
8
|
<em:description>WebDriver implementation for Firefox</em:description>
|
|
9
9
|
<em:creator>Simon Stewart</em:creator>
|
|
10
10
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
module Selenium
|
|
2
2
|
module WebDriver
|
|
3
3
|
module Firefox
|
|
4
|
+
|
|
5
|
+
# @private
|
|
4
6
|
class Binary
|
|
5
7
|
|
|
6
8
|
def initialize
|
|
7
9
|
ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
|
|
8
|
-
check_binary_exists
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def create_base_profile(name)
|
|
@@ -16,7 +17,6 @@ module Selenium
|
|
|
16
17
|
_, status = wait
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
|
|
20
20
|
if status && status.to_i != 0
|
|
21
21
|
raise Error::WebDriverError, "could not create base profile: (exit status: #{status})"
|
|
22
22
|
end
|
|
@@ -29,7 +29,7 @@ module Selenium
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def execute(*extra_args)
|
|
32
|
-
args = [path, "-no-remote", "--verbose"] + extra_args
|
|
32
|
+
args = [self.class.path, "-no-remote", "--verbose"] + extra_args
|
|
33
33
|
@process = ChildProcess.new(*args).start
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -63,43 +63,49 @@ module Selenium
|
|
|
63
63
|
|
|
64
64
|
private
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
class << self
|
|
67
|
+
def path
|
|
68
|
+
@path ||= case Platform.os
|
|
69
|
+
when :macosx
|
|
70
|
+
"/Applications/Firefox.app/Contents/MacOS/firefox-bin"
|
|
71
|
+
when :windows
|
|
72
|
+
windows_path
|
|
73
|
+
when :linux, :unix
|
|
74
|
+
Platform.find_binary("firefox3", "firefox2", "firefox") || "/usr/bin/firefox"
|
|
75
|
+
else
|
|
76
|
+
raise "Unknown platform: #{Platform.os}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
unless File.file?(@path)
|
|
80
|
+
raise Error::WebDriverError, "Could not find Firefox binary. Make sure Firefox is installed (OS: #{Platform.os})"
|
|
81
|
+
end
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
unless File.file?(path)
|
|
81
|
-
raise Error::WebDriverError, "Could not find Firefox binary. Make sure Firefox is installed (OS: #{Platform.os})"
|
|
83
|
+
@path
|
|
82
84
|
end
|
|
83
|
-
end
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def windows_path
|
|
89
|
+
windows_registry_path || "#{ ENV['PROGRAMFILES'] || "\\Program Files" }\\Mozilla Firefox\\firefox.exe"
|
|
90
|
+
end
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
require "win32/registry"
|
|
92
|
+
def windows_registry_path
|
|
93
|
+
require "win32/registry"
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
lm = Win32::Registry::HKEY_LOCAL_MACHINE
|
|
96
|
+
lm.open("SOFTWARE\\Mozilla\\Mozilla Firefox") do |reg|
|
|
97
|
+
main = lm.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{reg.keys[0]}\\Main")
|
|
98
|
+
if entry = main.find {|key, type, data| key =~ /pathtoexe/i}
|
|
99
|
+
return entry.last
|
|
100
|
+
end
|
|
98
101
|
end
|
|
102
|
+
rescue LoadError
|
|
103
|
+
# older JRuby or IronRuby does not have win32/registry
|
|
104
|
+
nil
|
|
105
|
+
rescue Win32::Registry::Error
|
|
106
|
+
raise Error::WebDriverError, "Firefox not found in the Windows registry. Make sure Firefox is installed"
|
|
99
107
|
end
|
|
100
|
-
|
|
101
|
-
raise Error::WebDriverError, "Firefox not found in Windows registry, please make sure you have it installed."
|
|
102
|
-
end
|
|
108
|
+
end # class << self
|
|
103
109
|
|
|
104
110
|
end # Binary
|
|
105
111
|
end # Firefox
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module Selenium
|
|
2
2
|
module WebDriver
|
|
3
3
|
module Firefox
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
# @private
|
|
6
|
+
class Bridge < Remote::Bridge
|
|
6
7
|
|
|
7
8
|
def initialize(opts = {})
|
|
8
9
|
@binary = Binary.new
|
|
@@ -17,8 +18,7 @@ module Selenium
|
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
@launcher.launch
|
|
20
|
-
|
|
21
|
-
@context = newSession
|
|
21
|
+
super :url => @launcher.connection.url, :desired_capabilities => :firefox
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def browser
|
|
@@ -30,125 +30,14 @@ module Selenium
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def quit
|
|
33
|
-
|
|
33
|
+
super
|
|
34
34
|
@binary.wait rescue nil # might raise on windows
|
|
35
35
|
|
|
36
36
|
nil
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def
|
|
40
|
-
execute :
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def refresh
|
|
44
|
-
execute :refresh
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def getWindowHandles
|
|
48
|
-
execute :getWindowHandles
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def getCurrentWindowHandle
|
|
52
|
-
execute :getCurrentWindowHandle
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def getScreenshotAsBase64
|
|
56
|
-
execute :getScreenshotAsBase64
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def get(url)
|
|
60
|
-
execute :get,
|
|
61
|
-
:parameters => [url]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def close
|
|
65
|
-
execute :close
|
|
66
|
-
# TODO: rescue ?
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def goBack
|
|
70
|
-
execute :goBack
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def goForward
|
|
74
|
-
execute :goForward
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def getCurrentUrl
|
|
78
|
-
execute :getCurrentUrl
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def getTitle
|
|
82
|
-
execute :title
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def executeScript(string, *args)
|
|
86
|
-
typed_args = args.map { |e| wrap_script_argument(e) }
|
|
87
|
-
|
|
88
|
-
resp = raw_execute :executeScript, :parameters => [string, typed_args]
|
|
89
|
-
raise TypeError, "expected Hash" unless resp.kind_of? Hash
|
|
90
|
-
|
|
91
|
-
unwrap_script_argument resp["response"]
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
#
|
|
95
|
-
# Finders - TODO: should be shared with Chrome::Bridge
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
def findElementByClassName(parent, class_name)
|
|
99
|
-
find_element_by 'class name', class_name, parent
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def findElementsByClassName(parent, class_name)
|
|
103
|
-
find_elements_by 'class name', class_name, parent
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def findElementById(parent, id)
|
|
107
|
-
find_element_by 'id', id, parent
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def findElementsById(parent, id)
|
|
111
|
-
find_elements_by 'id', id, parent
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def findElementByLinkText(parent, link_text)
|
|
115
|
-
find_element_by 'link text', link_text, parent
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def findElementsByLinkText(parent, link_text)
|
|
119
|
-
find_elements_by 'link text', link_text, parent
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def findElementByPartialLinkText(parent, link_text)
|
|
123
|
-
find_element_by 'partial link text', link_text, parent
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def findElementsByPartialLinkText(parent, link_text)
|
|
127
|
-
find_elements_by 'partial link text', link_text, parent
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def findElementByName(parent, name)
|
|
131
|
-
find_element_by 'name', name, parent
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def findElementsByName(parent, name)
|
|
135
|
-
find_elements_by 'name', name, parent
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def findElementByTagName(parent, tag_name)
|
|
139
|
-
find_element_by 'tag name', tag_name, parent
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def findElementsByTagName(parent, tag_name)
|
|
143
|
-
find_elements_by 'tag name', tag_name, parent
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def findElementByXpath(parent, xpath)
|
|
147
|
-
find_element_by 'xpath', xpath, parent
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def findElementsByXpath(parent, xpath)
|
|
151
|
-
find_elements_by 'xpath', xpath, parent
|
|
39
|
+
def getScreenshot
|
|
40
|
+
execute :screenshot
|
|
152
41
|
end
|
|
153
42
|
|
|
154
43
|
def findElementByCssSelector(parent, selector)
|
|
@@ -159,309 +48,6 @@ module Selenium
|
|
|
159
48
|
find_elements_by 'css selector', selector, parent
|
|
160
49
|
end
|
|
161
50
|
|
|
162
|
-
#
|
|
163
|
-
# Element functions
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
def clickElement(element)
|
|
167
|
-
# execute :clickElement, :element_id => element
|
|
168
|
-
execute :click,
|
|
169
|
-
:element_id => element
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def getElementTagName(element)
|
|
173
|
-
# execute :getElementTagName, :element_id => element
|
|
174
|
-
execute :getTagName,
|
|
175
|
-
:element_id => element
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def getElementAttribute(element, name)
|
|
179
|
-
# execute :getElementAttribute, :element_id => element, :parameters => [name]
|
|
180
|
-
execute :getAttribute,
|
|
181
|
-
:element_id => element,
|
|
182
|
-
:parameters => [name]
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def getElementValue(element)
|
|
186
|
-
# execute :getElementValue, :element_id => element
|
|
187
|
-
execute :getValue,
|
|
188
|
-
:element_id => element
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def getElementText(element)
|
|
192
|
-
# execute :getElementText, :element_id => element
|
|
193
|
-
execute :getText,
|
|
194
|
-
:element_id => element
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def getElementLocation(element)
|
|
198
|
-
# data = execute :getElementLocation, :element_id => element
|
|
199
|
-
data = execute :getLocation,
|
|
200
|
-
:element_id => element
|
|
201
|
-
|
|
202
|
-
Point.new data["x"], data["y"]
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
def getElementSize(element)
|
|
206
|
-
# execute :getElementSize, :element_id => element
|
|
207
|
-
data = execute :getSize,
|
|
208
|
-
:element_id => element
|
|
209
|
-
|
|
210
|
-
Dimension.new data['width'], data['height']
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def sendKeysToElement(element, string)
|
|
214
|
-
# execute :sendKeysToElement, :element_id => element, :parameters => [string.split(//u)]
|
|
215
|
-
execute :sendKeys,
|
|
216
|
-
:element_id => element,
|
|
217
|
-
:parameters => [string.to_s]
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def clearElement(element)
|
|
221
|
-
# execute :clearElement, :element_id => element
|
|
222
|
-
execute :clear,
|
|
223
|
-
:element_id => element
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def isElementEnabled(element)
|
|
227
|
-
# execute :isElementEnabled, :element_id => element
|
|
228
|
-
!getElementAttribute(element, "disabled")
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def isElementSelected(element)
|
|
232
|
-
# execute :isElementSelected, :element_id => element
|
|
233
|
-
execute :isSelected,
|
|
234
|
-
:element_id => element
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def isElementDisplayed(element)
|
|
238
|
-
# execute :isElementDisplayed, :element_id => element
|
|
239
|
-
execute :isDisplayed,
|
|
240
|
-
:element_id => element
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def submitElement(element)
|
|
244
|
-
# execute :submitElement, :element_id => element
|
|
245
|
-
execute :submit,
|
|
246
|
-
:element_id => element
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
def toggleElement(element)
|
|
250
|
-
# execute :toggleElement, :element_id => element
|
|
251
|
-
execute :toggle,
|
|
252
|
-
:element_id => element
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
def setElementSelected(element)
|
|
256
|
-
# execute :setElementSelected, :element_id => element
|
|
257
|
-
execute :setSelected,
|
|
258
|
-
:element_id => element
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
def getElementValueOfCssProperty(element, prop)
|
|
262
|
-
# execute :getElementValueOfCssProperty, :element_id => element, :parameters => [prop]
|
|
263
|
-
execute :getValueOfCssProperty,
|
|
264
|
-
:element_id => element,
|
|
265
|
-
:parameters => [prop]
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
def hoverOverElement(element)
|
|
269
|
-
execute :hover,
|
|
270
|
-
:element_id => element
|
|
271
|
-
# execute :hoverOverElement, :element_id => element
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def dragElement(element, rigth_by, down_by)
|
|
275
|
-
execute :dragElement,
|
|
276
|
-
:element_id => element,
|
|
277
|
-
:parameters => [rigth_by, down_by]
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
def setSpeed(speed)
|
|
282
|
-
pixel_speed = case speed
|
|
283
|
-
when "SLOW" then '1'
|
|
284
|
-
when "MEDIUM" then '10'
|
|
285
|
-
when "FAST" then '100'
|
|
286
|
-
else
|
|
287
|
-
raise ArgumentError, "unknown speed: #{speed.inspect}"
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
execute :setMouseSpeed,
|
|
291
|
-
:parameters => [pixel_speed]
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
def getSpeed
|
|
295
|
-
case execute(:getMouseSpeed)
|
|
296
|
-
when '1' then "SLOW"
|
|
297
|
-
when '10' then "MEDIUM"
|
|
298
|
-
when '100' then "FAST"
|
|
299
|
-
else
|
|
300
|
-
"FAST"
|
|
301
|
-
end
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
def addCookie(cookie)
|
|
305
|
-
execute :addCookie,
|
|
306
|
-
:parameters => [cookie.to_json] # uhm, sending text instead of data
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def deleteCookie(name)
|
|
310
|
-
execute :deleteCookie,
|
|
311
|
-
:parameters => [{:name => name}.to_json] # ditto
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
def getAllCookies
|
|
315
|
-
data = execute :getCookie
|
|
316
|
-
data.map do |c|
|
|
317
|
-
parse_cookie_string(c) unless c.strip.empty?
|
|
318
|
-
end.compact
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
#
|
|
322
|
-
# FF-specific?
|
|
323
|
-
#
|
|
324
|
-
|
|
325
|
-
def deleteAllCookies
|
|
326
|
-
execute :deleteAllCookies
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
def getCookieNamed(name)
|
|
330
|
-
getCookies.find { |c| c['name'] == name }
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
def switchToFrame(name)
|
|
334
|
-
execute :switchToFrame,
|
|
335
|
-
:parameters => [name.to_s]
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
def switchToDefaultContent
|
|
339
|
-
execute :switchToDefaultContent
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
def switchToWindow(name)
|
|
343
|
-
@context = execute :switchToWindow,
|
|
344
|
-
:parameters => [name.to_s]
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
def switchToActiveElement
|
|
348
|
-
Element.new self, element_id_from(execute(:switchToActiveElement))
|
|
349
|
-
end
|
|
350
|
-
alias_method :getActiveElement, :switchToActiveElement
|
|
351
|
-
|
|
352
|
-
private
|
|
353
|
-
|
|
354
|
-
def find_element_by(how, what, parent = nil)
|
|
355
|
-
if parent
|
|
356
|
-
id = execute :findChildElement,
|
|
357
|
-
:parameters => [{:id => parent, :using => how, :value => what}]
|
|
358
|
-
else
|
|
359
|
-
id = execute :findElement,
|
|
360
|
-
:parameters => [how, what]
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
Element.new self, element_id_from(id)
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
def find_elements_by(how, what, parent = nil)
|
|
367
|
-
if parent
|
|
368
|
-
id_string = execute :findChildElements,
|
|
369
|
-
:parameters => [{:id => parent, :using => how, :value => what}]
|
|
370
|
-
else
|
|
371
|
-
id_string = execute :findElements,
|
|
372
|
-
:parameters => [how, what]
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
id_string.map { |id| Element.new self, element_id_from(id) }
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
def newSession
|
|
379
|
-
execute :newSession
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
def execute(*args)
|
|
383
|
-
raw_execute(*args)['response']
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
def raw_execute(command, opts = {})
|
|
387
|
-
request = {:commandName => command, :context => @context.to_s}
|
|
388
|
-
|
|
389
|
-
if eid = opts[:element_id]
|
|
390
|
-
request[:elementId] = eid
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
if params = opts[:parameters]
|
|
394
|
-
request[:parameters] = params
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
puts "--> #{request.inspect}" if $DEBUG
|
|
398
|
-
|
|
399
|
-
@connection.send_string request.to_json
|
|
400
|
-
resp = @connection.read_response
|
|
401
|
-
|
|
402
|
-
puts "<-- #{resp.inspect}" if $DEBUG
|
|
403
|
-
|
|
404
|
-
if resp['isError']
|
|
405
|
-
case resp['response']
|
|
406
|
-
when String
|
|
407
|
-
msg = resp['response']
|
|
408
|
-
when Hash
|
|
409
|
-
msg = resp['response']['message']
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
msg ||= resp.inspect
|
|
413
|
-
raise Error::WebDriverError, msg
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
if ctx = resp['context']
|
|
417
|
-
@context = ctx
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
resp
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
#
|
|
424
|
-
# wrap/unwrap will be shared with Chrome (overrides BridgeHelper for now)
|
|
425
|
-
#
|
|
426
|
-
|
|
427
|
-
def wrap_script_argument(arg)
|
|
428
|
-
case arg
|
|
429
|
-
when Integer, Float
|
|
430
|
-
{ :type => "NUMBER", :value => arg }
|
|
431
|
-
when TrueClass, FalseClass, NilClass
|
|
432
|
-
{ :type => "BOOLEAN", :value => !!arg }
|
|
433
|
-
when Element
|
|
434
|
-
{ :type => "ELEMENT", :value => arg.ref }
|
|
435
|
-
when String
|
|
436
|
-
{ :type => "STRING", :value => arg.to_s }
|
|
437
|
-
when Array # Enumerable?
|
|
438
|
-
arg.map { |e| wrap_script_argument(e) }
|
|
439
|
-
else
|
|
440
|
-
raise TypeError, "Parameter is not of recognized type: #{arg.inspect}:#{arg.class}"
|
|
441
|
-
end
|
|
442
|
-
end
|
|
443
|
-
|
|
444
|
-
def unwrap_script_argument(arg)
|
|
445
|
-
raise TypeError, "expected Hash" unless arg.kind_of? Hash
|
|
446
|
-
case arg["type"]
|
|
447
|
-
when "NULL"
|
|
448
|
-
nil
|
|
449
|
-
when "ELEMENT"
|
|
450
|
-
Element.new self, element_id_from(arg["value"])
|
|
451
|
-
when "ARRAY"
|
|
452
|
-
arg['value'].map { |e| unwrap_script_argument(e) }
|
|
453
|
-
# when "POINT"
|
|
454
|
-
# Point.new arg['x'], arg['y']
|
|
455
|
-
# when "DIMENSION"
|
|
456
|
-
# Dimension.new arg['width'], arg['height']
|
|
457
|
-
# when "COOKIE"
|
|
458
|
-
# {:name => arg['name'], :value => arg['value']}
|
|
459
|
-
else
|
|
460
|
-
arg["value"]
|
|
461
|
-
end
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
|
|
465
51
|
end # Bridge
|
|
466
52
|
end # Firefox
|
|
467
53
|
end # WebDriver
|