selenium-webdriver 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/{common/src/rb/CHANGES → CHANGES} +13 -0
  2. data/{common/src/rb/README → README} +1 -1
  3. data/{common/src/rb/lib → lib}/selenium-webdriver.rb +0 -0
  4. data/{common/src/rb/lib → lib}/selenium/webdriver.rb +2 -1
  5. data/{common/src/rb/lib → lib}/selenium/webdriver/bridge_helper.rb +0 -0
  6. data/{common/src/rb/lib → lib}/selenium/webdriver/child_process.rb +0 -0
  7. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome.rb +0 -0
  8. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/bridge.rb +2 -2
  9. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/command_executor.rb +0 -0
  10. data/lib/selenium/webdriver/chrome/extension.zip +0 -0
  11. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/launcher.rb +26 -20
  12. data/{common/src/rb/lib → lib}/selenium/webdriver/core_ext/dir.rb +0 -0
  13. data/{common/src/rb/lib → lib}/selenium/webdriver/core_ext/string.rb +0 -0
  14. data/{common/src/rb/lib → lib}/selenium/webdriver/driver.rb +0 -0
  15. data/{common/src/rb/lib → lib}/selenium/webdriver/driver_extensions/takes_screenshot.rb +0 -0
  16. data/{common/src/rb/lib → lib}/selenium/webdriver/element.rb +0 -0
  17. data/{common/src/rb/lib → lib}/selenium/webdriver/error.rb +0 -0
  18. data/{common/src/rb/lib → lib}/selenium/webdriver/file_reaper.rb +2 -1
  19. data/{common/src/rb/lib → lib}/selenium/webdriver/find.rb +0 -0
  20. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox.rb +2 -1
  21. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/binary.rb +32 -6
  22. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/bridge.rb +0 -0
  23. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  24. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/launcher.rb +0 -0
  25. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  26. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  27. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/profile.rb +37 -72
  28. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/profiles_ini.rb +0 -0
  29. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/util.rb +0 -0
  30. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie.rb +2 -2
  31. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/bridge.rb +7 -2
  32. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/lib.rb +0 -0
  33. data/{jobbie/prebuilt/Win32/Release → lib/selenium/webdriver/ie/native/win32}/InternetExplorerDriver.dll +0 -0
  34. data/lib/selenium/webdriver/ie/native/x64/InternetExplorerDriver.dll +0 -0
  35. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/util.rb +0 -0
  36. data/{common/src/rb/lib → lib}/selenium/webdriver/keys.rb +0 -0
  37. data/{common/src/rb/lib → lib}/selenium/webdriver/navigation.rb +0 -0
  38. data/{common/src/rb/lib → lib}/selenium/webdriver/options.rb +0 -0
  39. data/{common/src/rb/lib → lib}/selenium/webdriver/platform.rb +5 -1
  40. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote.rb +0 -0
  41. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/bridge.rb +0 -0
  42. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/capabilities.rb +0 -0
  43. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/commands.rb +0 -0
  44. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/common.rb +0 -0
  45. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/curb.rb +0 -0
  46. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/default.rb +5 -1
  47. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/response.rb +0 -0
  48. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/server_error.rb +0 -0
  49. data/{common/src/rb/lib → lib}/selenium/webdriver/target_locator.rb +0 -0
  50. data/{common/src/rb/lib → lib}/selenium/webdriver/timeouts.rb +0 -0
  51. data/lib/selenium/webdriver/zip_helper.rb +30 -0
  52. metadata +73 -214
  53. data/COPYING +0 -204
  54. data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
  55. data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
  56. data/chrome/src/extension/background.html +0 -9
  57. data/chrome/src/extension/background.js +0 -1029
  58. data/chrome/src/extension/content_script.js +0 -1488
  59. data/chrome/src/extension/icons/busy.png +0 -0
  60. data/chrome/src/extension/icons/free.png +0 -0
  61. data/chrome/src/extension/manifest-nonwin.json +0 -19
  62. data/chrome/src/extension/manifest-win.json +0 -20
  63. data/chrome/src/extension/utils.js +0 -231
  64. data/common/src/js/abstractcommandprocessor.js +0 -132
  65. data/common/src/js/asserts.js +0 -296
  66. data/common/src/js/by.js +0 -149
  67. data/common/src/js/command.js +0 -380
  68. data/common/src/js/core/Blank.html +0 -7
  69. data/common/src/js/core/InjectedRemoteRunner.html +0 -8
  70. data/common/src/js/core/RemoteRunner.html +0 -101
  71. data/common/src/js/core/SeleniumLog.html +0 -109
  72. data/common/src/js/core/TestPrompt.html +0 -145
  73. data/common/src/js/core/TestRunner-splash.html +0 -55
  74. data/common/src/js/core/TestRunner.html +0 -165
  75. data/common/src/js/core/icons/all.png +0 -0
  76. data/common/src/js/core/icons/continue.png +0 -0
  77. data/common/src/js/core/icons/continue_disabled.png +0 -0
  78. data/common/src/js/core/icons/pause.png +0 -0
  79. data/common/src/js/core/icons/pause_disabled.png +0 -0
  80. data/common/src/js/core/icons/selected.png +0 -0
  81. data/common/src/js/core/icons/step.png +0 -0
  82. data/common/src/js/core/icons/step_disabled.png +0 -0
  83. data/common/src/js/core/lib/cssQuery/cssQuery-p.js +0 -6
  84. data/common/src/js/core/lib/cssQuery/src/cssQuery-level2.js +0 -142
  85. data/common/src/js/core/lib/cssQuery/src/cssQuery-level3.js +0 -150
  86. data/common/src/js/core/lib/cssQuery/src/cssQuery-standard.js +0 -53
  87. data/common/src/js/core/lib/cssQuery/src/cssQuery.js +0 -356
  88. data/common/src/js/core/lib/prototype.js +0 -2006
  89. data/common/src/js/core/lib/scriptaculous/builder.js +0 -101
  90. data/common/src/js/core/lib/scriptaculous/controls.js +0 -815
  91. data/common/src/js/core/lib/scriptaculous/dragdrop.js +0 -915
  92. data/common/src/js/core/lib/scriptaculous/effects.js +0 -958
  93. data/common/src/js/core/lib/scriptaculous/scriptaculous.js +0 -47
  94. data/common/src/js/core/lib/scriptaculous/slider.js +0 -283
  95. data/common/src/js/core/lib/scriptaculous/unittest.js +0 -383
  96. data/common/src/js/core/lib/snapsie.js +0 -91
  97. data/common/src/js/core/scripts/find_matching_child.js +0 -69
  98. data/common/src/js/core/scripts/htmlutils.js +0 -8716
  99. data/common/src/js/core/scripts/injection.html +0 -72
  100. data/common/src/js/core/scripts/selenium-api.js +0 -3291
  101. data/common/src/js/core/scripts/selenium-browserbot.js +0 -2457
  102. data/common/src/js/core/scripts/selenium-browserdetect.js +0 -153
  103. data/common/src/js/core/scripts/selenium-commandhandlers.js +0 -379
  104. data/common/src/js/core/scripts/selenium-executionloop.js +0 -175
  105. data/common/src/js/core/scripts/selenium-logging.js +0 -148
  106. data/common/src/js/core/scripts/selenium-remoterunner.js +0 -695
  107. data/common/src/js/core/scripts/selenium-testrunner.js +0 -1362
  108. data/common/src/js/core/scripts/selenium-version.js +0 -5
  109. data/common/src/js/core/scripts/ui-doc.html +0 -808
  110. data/common/src/js/core/scripts/ui-element.js +0 -1644
  111. data/common/src/js/core/scripts/ui-map-sample.js +0 -979
  112. data/common/src/js/core/scripts/user-extensions.js +0 -3
  113. data/common/src/js/core/scripts/user-extensions.js.sample +0 -75
  114. data/common/src/js/core/scripts/xmlextras.js +0 -153
  115. data/common/src/js/core/selenium-logo.png +0 -0
  116. data/common/src/js/core/selenium-test.css +0 -43
  117. data/common/src/js/core/selenium.css +0 -316
  118. data/common/src/js/core/xpath/dom.js +0 -566
  119. data/common/src/js/core/xpath/javascript-xpath-0.1.11.js +0 -2816
  120. data/common/src/js/core/xpath/util.js +0 -549
  121. data/common/src/js/core/xpath/xmltoken.js +0 -149
  122. data/common/src/js/core/xpath/xpath.js +0 -2481
  123. data/common/src/js/extension/README +0 -2
  124. data/common/src/js/extension/dommessenger.js +0 -152
  125. data/common/src/js/factory.js +0 -55
  126. data/common/src/js/future.js +0 -141
  127. data/common/src/js/jsunit.js +0 -40
  128. data/common/src/js/jsunit/app/css/jsUnitStyle.css +0 -50
  129. data/common/src/js/jsunit/app/css/readme +0 -10
  130. data/common/src/js/jsunit/app/emptyPage.html +0 -11
  131. data/common/src/js/jsunit/app/jsUnitCore.js +0 -534
  132. data/common/src/js/jsunit/app/jsUnitMockTimeout.js +0 -81
  133. data/common/src/js/jsunit/app/jsUnitTestManager.js +0 -705
  134. data/common/src/js/jsunit/app/jsUnitTestSuite.js +0 -44
  135. data/common/src/js/jsunit/app/jsUnitTracer.js +0 -102
  136. data/common/src/js/jsunit/app/jsUnitVersionCheck.js +0 -59
  137. data/common/src/js/jsunit/app/main-counts-errors.html +0 -12
  138. data/common/src/js/jsunit/app/main-counts-failures.html +0 -13
  139. data/common/src/js/jsunit/app/main-counts-runs.html +0 -13
  140. data/common/src/js/jsunit/app/main-counts.html +0 -21
  141. data/common/src/js/jsunit/app/main-data.html +0 -178
  142. data/common/src/js/jsunit/app/main-errors.html +0 -23
  143. data/common/src/js/jsunit/app/main-frame.html +0 -19
  144. data/common/src/js/jsunit/app/main-loader.html +0 -45
  145. data/common/src/js/jsunit/app/main-progress.html +0 -25
  146. data/common/src/js/jsunit/app/main-results.html +0 -67
  147. data/common/src/js/jsunit/app/main-status.html +0 -13
  148. data/common/src/js/jsunit/app/testContainer.html +0 -16
  149. data/common/src/js/jsunit/app/testContainerController.html +0 -77
  150. data/common/src/js/jsunit/app/xbDebug.js +0 -306
  151. data/common/src/js/jsunit/changelog.txt +0 -60
  152. data/common/src/js/jsunit/css/jsUnitStyle.css +0 -83
  153. data/common/src/js/jsunit/images/green.gif +0 -0
  154. data/common/src/js/jsunit/images/logo_jsunit.gif +0 -0
  155. data/common/src/js/jsunit/images/powerby-transparent.gif +0 -0
  156. data/common/src/js/jsunit/images/red.gif +0 -0
  157. data/common/src/js/jsunit/licenses/JDOM_license.txt +0 -56
  158. data/common/src/js/jsunit/licenses/Jetty_license.html +0 -213
  159. data/common/src/js/jsunit/licenses/MPL-1.1.txt +0 -470
  160. data/common/src/js/jsunit/licenses/gpl-2.txt +0 -340
  161. data/common/src/js/jsunit/licenses/index.html +0 -141
  162. data/common/src/js/jsunit/licenses/lgpl-2.1.txt +0 -504
  163. data/common/src/js/jsunit/licenses/mpl-tri-license-c.txt +0 -35
  164. data/common/src/js/jsunit/licenses/mpl-tri-license-html.txt +0 -35
  165. data/common/src/js/jsunit/readme.txt +0 -19
  166. data/common/src/js/jsunit/testRunner.html +0 -167
  167. data/common/src/js/jsunit/version.txt +0 -1
  168. data/common/src/js/key.js +0 -117
  169. data/common/src/js/localcommandprocessor.js +0 -171
  170. data/common/src/js/testcase.js +0 -219
  171. data/common/src/js/timing.js +0 -89
  172. data/common/src/js/webdriver.js +0 -860
  173. data/common/src/js/webelement.js +0 -483
  174. data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
  175. data/firefox/prebuilt/amd64/libnoblur64.so +0 -0
  176. data/firefox/prebuilt/i386/libnoblur.so +0 -0
  177. data/firefox/prebuilt/linux/Release/libwebdriver-firefox.so +0 -0
  178. data/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so +0 -0
  179. data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
  180. data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
  181. data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
  182. data/firefox/src/extension/chrome.manifest +0 -3
  183. data/firefox/src/extension/components/badCertListener.js +0 -295
  184. data/firefox/src/extension/components/dispatcher.js +0 -495
  185. data/firefox/src/extension/components/driver-component.js +0 -130
  186. data/firefox/src/extension/components/errorcode.js +0 -70
  187. data/firefox/src/extension/components/firefoxDriver.js +0 -831
  188. data/firefox/src/extension/components/json2.js +0 -273
  189. data/firefox/src/extension/components/keytest.html +0 -554
  190. data/firefox/src/extension/components/nsCommandProcessor.js +0 -684
  191. data/firefox/src/extension/components/promptService.js +0 -208
  192. data/firefox/src/extension/components/request.js +0 -219
  193. data/firefox/src/extension/components/response.js +0 -276
  194. data/firefox/src/extension/components/screenshooter.js +0 -81
  195. data/firefox/src/extension/components/session.js +0 -314
  196. data/firefox/src/extension/components/sessionstore.js +0 -226
  197. data/firefox/src/extension/components/socketListener.js +0 -435
  198. data/firefox/src/extension/components/utils.js +0 -1335
  199. data/firefox/src/extension/components/webLoadingListener.js +0 -57
  200. data/firefox/src/extension/components/webdriverserver.js +0 -110
  201. data/firefox/src/extension/components/wrappedElement.js +0 -706
  202. data/firefox/src/extension/content/fxdriver.xul +0 -30
  203. data/firefox/src/extension/content/server.js +0 -95
  204. data/firefox/src/extension/idl/nsICommandProcessor.idl +0 -38
  205. data/firefox/src/extension/idl/nsIResponseHandler.idl +0 -34
  206. data/firefox/src/extension/install.rdf +0 -29
  207. data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
@@ -1,219 +0,0 @@
1
- /** @license
2
- Copyright 2007-2009 WebDriver committers
3
- Copyright 2007-2009 Google Inc.
4
-
5
- Licensed under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License.
7
- You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software
12
- distributed under the License is distributed on an "AS IS" BASIS,
13
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- See the License for the specific language governing permissions and
15
- limitations under the License.
16
- */
17
-
18
- /**
19
- * @fileoverview A test case that uses the WebDriver Javascript API. Each phase
20
- * of a test (setUp, test function, and tearDown) will be called with an
21
- * instance of a {@code webdriver.WebDriver} that can be used to schedule
22
- * commands for controlling the browser (e.g. clicking or typing on an
23
- * element).
24
- * <p>
25
- * Unlike pure JavaScript test frameworks like Selenium, WebDriver controls the
26
- * browser directly, allowing for more accurate simulation of user actions in a
27
- * web application.
28
- * <p>
29
- * See below for a basic example of using WebDriver to test cut and paste in
30
- * a contentEditable document.
31
- * <pre>
32
- * goog.require('goog.dom');
33
- * goog.require('webdriver.asserts');
34
- * goog.require('webdriver.jsunit');
35
- *
36
- * var richTextFrame;
37
- *
38
- * function setUp() {
39
- * richTextFrame = goog.dom.$('rtframe');
40
- * richTextFrame.contentWindow.document.designMode = 'on';
41
- * richTextFrame.contentWindow.document.body.innerHTML = '';
42
- * }
43
- *
44
- * function testCutAndPaste(driver) {
45
- * driver.switchToFrame('rtframe');
46
- * var body = driver.findElement({xpath: '//body'});
47
- * body.sendKeys('abc', webdriver.Key.CONTROL, 'axvv');
48
- * driver.callFunction(function() {
49
- * assertEquals('abcabc',
50
- * richTextFrame.contentWindow.document.body.innerHTML);
51
- * });
52
- * }
53
- * </pre>
54
- *
55
- * @author jmleyba@gmail.com (Jason Leyba)
56
- */
57
-
58
- goog.provide('webdriver.TestCase');
59
- goog.provide('webdriver.TestCase.Test');
60
-
61
- goog.require('goog.events');
62
- goog.require('goog.testing.TestCase');
63
- goog.require('goog.testing.TestCase.Test');
64
- goog.require('goog.testing.asserts');
65
- goog.require('webdriver.Command');
66
-
67
-
68
-
69
- /**
70
- * A specialized test case for running jsunit tests with the WebDriver
71
- * framework. Each phase of a test (setUp, test, and tearDown) will be given an
72
- * instance of {@code webdriver.WebDriver} that can be used to schedule
73
- * commands for controlling the browser.
74
- * @param {string} name The name of the test case.
75
- * @param {function(): webdriver.WebDriver} driverFactoryFn Factory function to
76
- * use for creating {@code webdriver.WebDriver} instances for each test.
77
- * @extends {goog.testing.TestCase}
78
- * @constructor
79
- */
80
- webdriver.TestCase = function(name, driverFactoryFn) {
81
- goog.testing.TestCase.call(this, name);
82
-
83
- /**
84
- * Factory function use for creating {@code webdriver.WebDriver}
85
- * instances for each test.
86
- * @type {function(): webdriver.WebDriver}
87
- * @private
88
- */
89
- this.driverFactoryFn_ = driverFactoryFn;
90
- };
91
- goog.inherits(webdriver.TestCase, goog.testing.TestCase);
92
-
93
-
94
- /** @override */
95
- webdriver.TestCase.prototype.cycleTests = function() {
96
- this.saveMessage('Start');
97
- this.batchTime_ = this.now_();
98
- this.startTest_();
99
- };
100
-
101
-
102
- /**
103
- * Starts a test.
104
- * @private
105
- */
106
- webdriver.TestCase.prototype.startTest_ = function() {
107
- var test = this.next();
108
- if (!test || !this.running) {
109
- this.finalize(); // Tests are done.
110
- return;
111
- }
112
-
113
- // TODO(jleyba): result_ should be exposed using a public accessor.
114
- this.result_.runCount++;
115
- this.log('Running test: ' + test.name);
116
- goog.testing.TestCase.currentTestName = test.name;
117
-
118
- var driver;
119
- try {
120
- driver = this.driverFactoryFn_();
121
-
122
- // Attach an error handler to record each command failure as an error for
123
- // the current test. After each error, the currently pending command and
124
- // all of its subcommands so we can continue the test.
125
- goog.events.listen(driver, webdriver.Command.ERROR_EVENT,
126
- function(e) {
127
- // console.error('error event!');
128
- var failingCommand = (/** @type {webdriver.Command} */e.target);
129
- // console.dir(failingCommand);
130
- if (!failingCommand.getResponse()) {
131
- // This should never happen, but just in case.
132
- test.errors.push('Unknown error');
133
- } else {
134
- test.errors.push(failingCommand.getResponse().getErrorMessage());
135
- }
136
- driver.abortCommand(null);
137
- }, /*capture=*/false);
138
-
139
- // TODO(jleyba): make this automatic upon creating an instance.
140
- driver.newSession(true);
141
-
142
- // If setup fails, we don't want to run the test function, so group setup
143
- // and the test function together in a function command.
144
- driver.callFunction(function() {
145
- this.setUp(driver);
146
- // Wrap the call to the actual test function in a function command. This
147
- // will ensure all of the commands scheduled in setUp will executed before
148
- // the test function is called.
149
- driver.callFunction(function() {
150
- test.ref.call(test.scope, driver);
151
- });
152
- }, this);
153
-
154
- // Call tearDown once all setup and test commands have completed.
155
- driver.callFunction(function() {
156
- this.tearDown(driver);
157
- }, this);
158
-
159
- // Likewise, once tearDown is completely finished, finish the test.
160
- driver.callFunction(function() {
161
- this.finishTest_(test, driver);
162
- }, this);
163
- } catch (e) {
164
- test.errors.push(e);
165
- this.finishTest_(test, driver);
166
- }
167
- };
168
-
169
- /**
170
- * Completes a test.
171
- * @param {webdriver.TestCase.Test} test The test to complete.
172
- * @param {webdriver.WebDriver} driver The driver instance used by the test.
173
- * @private
174
- */
175
- webdriver.TestCase.prototype.finishTest_ = function(test, driver) {
176
- if (driver) {
177
- driver.dispose();
178
- }
179
- goog.testing.TestCase.currentTestName = null;
180
- var numErrors = test.errors.length;
181
- if (numErrors) {
182
- for (var i = 0; i < numErrors; i++) {
183
- this.doError(test, test.errors[i]);
184
- }
185
- } else {
186
- this.doSuccess(test);
187
- }
188
- this.startTest_(); // Start the next test.
189
- };
190
-
191
-
192
- /** @override */
193
- webdriver.TestCase.prototype.createTestFromAutoDiscoveredFunction =
194
- function(name, ref) {
195
- return new webdriver.TestCase.Test(name, ref, goog.global);
196
- };
197
-
198
-
199
- /**
200
- * Represents a single test function that will be run by a
201
- * {@code webdriver.TestCase}.
202
- * @param {string} name The test name.
203
- * @param {function} ref Reference to the test function.
204
- * @param {Object} opt_scope Optional scope that the test function should be
205
- * called in.
206
- * @constructor
207
- * @extends {goog.testing.TestCase.Test}
208
- */
209
- webdriver.TestCase.Test = function(name, ref, opt_scope) {
210
- goog.testing.TestCase.Test.call(this, name, ref, opt_scope);
211
-
212
- /**
213
- * The errors that occurred while running this test.
214
- * @type {Array.<string|Error>}
215
- */
216
- this.errors = [];
217
- };
218
- goog.inherits(webdriver.TestCase.Test, goog.testing.TestCase.Test);
219
-
@@ -1,89 +0,0 @@
1
- /** @license
2
- Copyright 2007-2009 WebDriver committers
3
- Copyright 2007-2009 Google Inc.
4
-
5
- Licensed under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License.
7
- You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software
12
- distributed under the License is distributed on an "AS IS" BASIS,
13
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- See the License for the specific language governing permissions and
15
- limitations under the License.
16
- */
17
-
18
- /**
19
- * @fileoverview Defines a namespace that implements the global timing
20
- * functions: setTimeout, setInterval, clearTimeout, and clearInterval.
21
- * Internally, this namespaces uses protected references to the real global
22
- * functions so that users can override them without interfering with WebDriver
23
- * functionality.
24
- * @author jmleyba@gmail.com (Jason Leyba)
25
- */
26
-
27
- goog.provide('webdriver.timing');
28
-
29
- goog.require('goog.userAgent');
30
-
31
-
32
- webdriver.timing.protectedSetTimeout_ = goog.global['setTimeout'];
33
- webdriver.timing.protectedSetInterval_ = goog.global['setInterval'];
34
- webdriver.timing.protectedClearTimeout_ = goog.global['clearTimeout'];
35
- webdriver.timing.protectedClearInterval_ = goog.global['clearInterval'];
36
-
37
-
38
- /**
39
- * Schedules a function to be executed after the given {@code delay}.
40
- * @param {function} fn The function to call after {@code delay} milliseconds.
41
- * @param {number} delay The number of milliseconds to delay executing the
42
- * function by.
43
- * @return {number} The timeout ID that can be used with {@code #clearTimeout}
44
- * to cancel executing {@code fn}.
45
- */
46
- webdriver.timing.setTimeout = function(fn, delay) {
47
- return goog.userAgent.IE ?
48
- webdriver.timing.protectedSetTimeout_(fn, delay) :
49
- webdriver.timing.protectedSetTimeout_.call(null, fn, delay);
50
- };
51
-
52
-
53
- /**
54
- * Schedules a function to be executed every {@code interval} milliseconds.
55
- * @param {function} fn The function to call every {@code delay} milliseconds.
56
- * @param {number} interval The number of milliseconds to delay executing the
57
- * function by.
58
- * @return {number} The interval ID that can be used with {@code #clearInterval}
59
- * to cancel this interval.
60
- */
61
- webdriver.timing.setInterval = function(fn, interval) {
62
- return goog.userAgent.IE ?
63
- webdriver.timing.protectedSetInterval_(fn, interval) :
64
- webdriver.timing.protectedSetInterval_.call(goog.global, fn, interval);
65
- };
66
-
67
-
68
- /**
69
- * Cancels a timeout scheduled with {@code #setTimeout()}.
70
- * @param {number} timeoutId ID of the timeout to cancel as returned by
71
- * {@code #setTimeout}. Passing an invalid ID results in a no-op.
72
- */
73
- webdriver.timing.clearTimeout = function(timeoutId) {
74
- return goog.userAgent.IE ?
75
- webdriver.timing.protectedClearTimeout_(timeoutId) :
76
- webdriver.timing.protectedClearTimeout_.call(goog.global, timeoutId);
77
- };
78
-
79
-
80
- /**
81
- * Cancels an interval scheduled with {@code #clearInterval()}.
82
- * @param {number} intervalId ID of the interval to cancel as returned by
83
- * {@code #setInterval}. Passing an invalid ID results in a no-op.
84
- */
85
- webdriver.timing.clearInterval = function(intervalId) {
86
- return goog.userAgent.IE ?
87
- webdriver.timing.protectedClearInterval_(timeoutId) :
88
- webdriver.timing.protectedClearInterval_.call(goog.global, intervalId);
89
- };
@@ -1,860 +0,0 @@
1
- /** @license
2
- Copyright 2007-2009 WebDriver committers
3
- Copyright 2007-2009 Google Inc.
4
-
5
- Licensed under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License.
7
- You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software
12
- distributed under the License is distributed on an "AS IS" BASIS,
13
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- See the License for the specific language governing permissions and
15
- limitations under the License.
16
- */
17
-
18
- /**
19
- * @fileoverview The heart of the WebDriver JavaScript API.
20
- * @author jmleyba@gmail.com (Jason Leyba)
21
- */
22
-
23
- goog.provide('webdriver.WebDriver');
24
- goog.provide('webdriver.WebDriver.EventType');
25
- goog.provide('webdriver.WebDriver.Speed');
26
-
27
- goog.require('goog.debug.Logger');
28
- goog.require('goog.events');
29
- goog.require('goog.events.EventTarget');
30
- goog.require('webdriver.By.Locator');
31
- goog.require('webdriver.Command');
32
- goog.require('webdriver.CommandName');
33
- goog.require('webdriver.Response');
34
- goog.require('webdriver.WebElement');
35
- goog.require('webdriver.timing');
36
-
37
-
38
- /**
39
- * The main interface for controlling a web browser. How the browser is
40
- * controlled is dictated by the injected {@code commandProcessor}. The command
41
- * processor may control the browser either through an extension or plugin, or
42
- * by sending commands to a RemoteWebDriver server.
43
- *
44
- * Any WebDriver command that is expected to produce a return value will return
45
- * a {@code webdriver.Future}. This Future can passed as an argument to another
46
- * command, or an assertion function in the {@code webdriver.asserts} namespace.
47
- * For example:
48
- * driver.get('http://www.google.com');
49
- * var futureTitle = driver.getTitle();
50
- * assertThat(futureTitle, equals('Google Search'));
51
- *
52
- * The WebDriver will dispatch the following events:
53
- * <ul>
54
- * <li>webdriver.WebDriver.EventType.PAUSED - Command execution has been halted
55
- * and no more commands will be processed until {@code #resume()} is called
56
- * </li>
57
- * <li>webdriver.WebDriver.EventType.RESUMED - The driver has resumed execution
58
- * after being paused</li>
59
- * <li>webdriver.WebDriver.EventType.ERROR - Dispatched whenever a WebDriver
60
- * command fails</li>
61
- * </ul>
62
- *
63
- * @param {Object} commandProcessor The command processor to use for executing
64
- * individual {@code webdriver.Command}s.
65
- * @constructor
66
- * @extends {goog.events.EventTarget}
67
- */
68
- webdriver.WebDriver = function(commandProcessor) {
69
- goog.events.EventTarget.call(this);
70
-
71
- /**
72
- * The logger for this instance.
73
- * @type {!goog.debug.Logger}
74
- * @private
75
- */
76
- this.logger_ = goog.debug.Logger.getLogger('webdriver.WebDriver');
77
-
78
- /**
79
- * The command processor to use for executing commands.
80
- * @type {Object}
81
- * @private
82
- */
83
- this.commandProcessor_ = commandProcessor;
84
-
85
- /**
86
- * A stack of frames for queued commands. The list of commands at index 0
87
- * are global commands. When the stack has more than 1 frame, the commands
88
- * in the list at the top of the stack are the remaining subcommands for the
89
- * command at the top of the {@code pendingCommands_} stack.
90
- * @type {Array.<Array.<webdriver.Command>>}
91
- * @private
92
- */
93
- this.queuedCommands_ = [[]];
94
-
95
- /**
96
- * A list of commands that are currently being executed. The command at index
97
- * N+1 is a subcommand to the command at index N. It will always be the case
98
- * that {@code queuedCommands_.length == pendingCommands_.length + 1;}.
99
- * @type {Array.<webdriver.Command>}
100
- * @private
101
- */
102
- this.pendingCommands_ = [];
103
-
104
- /**
105
- * Whether this instance is paused. When paused, commands can still be issued,
106
- * but no commands will be executed.
107
- * @type {boolean}
108
- * @private
109
- */
110
- this.isPaused_ = false;
111
-
112
- /**
113
- * This instance's current session ID. Set with the
114
- * {@code webdriver.WebDriver.prototype.newSession} command.
115
- * @type {?string}
116
- * @private
117
- */
118
- this.sessionId_ = null;
119
-
120
- /**
121
- * Interval ID for the command processing loop.
122
- * @type {number}
123
- * @private
124
- */
125
- this.commandInterval_ = webdriver.timing.setInterval(
126
- goog.bind(this.processCommands_, this),
127
- webdriver.WebDriver.COMMAND_INTERVAL_LENGTH_);
128
- };
129
- goog.inherits(webdriver.WebDriver, goog.events.EventTarget);
130
-
131
-
132
- /**
133
- * The amount of time in milliseconds between ticks of the command processing
134
- * interval.
135
- * @type {number}
136
- * @private
137
- */
138
- webdriver.WebDriver.COMMAND_INTERVAL_LENGTH_ = 10;
139
-
140
-
141
- /**
142
- * Enumeration of the events that may be dispatched by an instance of
143
- * {@code webdriver.WebDriver}.
144
- * @enum {string}
145
- */
146
- webdriver.WebDriver.EventType = {
147
- ERROR: 'ERROR',
148
- PAUSED: 'PAUSED',
149
- RESUMED: 'RESUMED'
150
- };
151
-
152
-
153
- /**
154
- * Enumeration of the supported input speeds.
155
- * @enum {number}
156
- * @see webdriver.WebDriver.prototype.setSpeed
157
- * @see webdriver.WebDriver.prototype.getSpeed
158
- */
159
- webdriver.WebDriver.Speed = {
160
- SLOW: 'SLOW',
161
- MEDIUM: 'MEDIUM',
162
- FAST: 'FAST'
163
- };
164
-
165
-
166
- /**
167
- * @override
168
- */
169
- webdriver.WebDriver.prototype.disposeInternal = function() {
170
- this.commandProcessor_.dispose();
171
- webdriver.timing.clearInterval(this.commandInterval_);
172
-
173
- goog.array.forEach(this.pendingCommands_, function(command) {
174
- command.dispose();
175
- });
176
- goog.array.forEach(this.queuedCommands_, function(frame) {
177
- goog.array.forEach(frame, function(command) {
178
- command.dispose();
179
- });
180
- });
181
-
182
- delete this.commandProcessor_;
183
- delete this.pendingCommands_;
184
- delete this.queuedCommands_;
185
- delete this.isPaused_;
186
- delete this.sessionLocked_;
187
- delete this.sessionId_;
188
- delete this.commandInterval_;
189
-
190
- webdriver.WebDriver.superClass_.disposeInternal.call(this);
191
- };
192
-
193
-
194
- /**
195
- * Queues a command to execute.
196
- * @param {webdriver.CommandName} name The name of the command to execute.
197
- * @return {webdriver.Command} The new command.
198
- * @protected
199
- */
200
- webdriver.WebDriver.prototype.addCommand = function(name) {
201
- var command = new webdriver.Command(this, name);
202
- goog.array.peek(this.queuedCommands_).push(command);
203
- return command;
204
- };
205
-
206
-
207
- /**
208
- * @return {boolean} Whether this driver is idle (there are no pending
209
- * commands).
210
- */
211
- webdriver.WebDriver.prototype.isIdle = function() {
212
- if (this.isDisposed()) {
213
- return true;
214
- }
215
-
216
- // If there is a finished command on the pending command queue, but it
217
- // failed, then the failure hasn't been dealt with yet and the driver will
218
- // not process any more commands, so we consider this idle.
219
- var pendingCommand = goog.array.peek(this.pendingCommands_);
220
- if (pendingCommand && pendingCommand.isFinished() &&
221
- !pendingCommand.getResponse().isSuccess()) {
222
- return true;
223
- }
224
- return !pendingCommand && this.queuedCommands_.length == 1 &&
225
- !this.queuedCommands_[0].length;
226
- };
227
-
228
-
229
- /**
230
- * Aborts the specified command and all of its pending subcommands.
231
- * @param {webdriver.Command|webdriver.WebDriver} command The command to abort.
232
- * @return {number} The total number of commands aborted. A value of 0
233
- * indicates that the given command was not a pending command.
234
- */
235
- webdriver.WebDriver.prototype.abortCommand = function(command) {
236
- var index = (null == command || this == command) ? 0 :
237
- goog.array.findIndexRight(this.pendingCommands_, function(cmd) {
238
- return cmd == command;
239
- });
240
- if (index >= 0) {
241
- var numAborted = this.pendingCommands_.length - index;
242
- var totalNumAborted = numAborted;
243
- for (var i = 0; i < numAborted; i++) {
244
- this.pendingCommands_.pop().dispose();
245
- goog.array.forEach(this.queuedCommands_.pop(), function(subCommand) {
246
- totalNumAborted += 1;
247
- subCommand.dispose();
248
- });
249
- }
250
- return totalNumAborted;
251
- }
252
- return 0;
253
- };
254
-
255
-
256
- /**
257
- * Immediately pauses the driver so it will not execute anymore commands until
258
- * {@code #resume()} is called.
259
- * Dispatches a {@code webdriver.WebDriver.EventType.PAUSED} event.
260
- */
261
- webdriver.WebDriver.prototype.pauseImmediately = function() {
262
- this.isPaused_ = true;
263
- this.logger_.fine('WebDriver paused');
264
- this.dispatchEvent(webdriver.WebDriver.EventType.PAUSED);
265
- };
266
-
267
-
268
- /**
269
- * Unpauses this driver so it can execute commands again. Dispatches a
270
- * {@code webdriver.WebDriver.EventType.RESUMED} event.
271
- */
272
- webdriver.WebDriver.prototype.resume = function() {
273
- this.isPaused_ = false;
274
- this.logger_.fine('WebDriver resumed');
275
- this.dispatchEvent(webdriver.WebDriver.EventType.RESUMED);
276
- };
277
-
278
-
279
- /**
280
- * Event handler for whenever this driver is ready to execute a command.
281
- * @private
282
- */
283
- webdriver.WebDriver.prototype.processCommands_ = function() {
284
- var pendingCommand = goog.array.peek(this.pendingCommands_);
285
- if (this.isPaused_ || (pendingCommand && !pendingCommand.isFinished())) {
286
- return;
287
- }
288
-
289
- if (pendingCommand && !pendingCommand.getResponse().isSuccess()) {
290
- // Or should we be throwing this to be caught by window.onerror?
291
- this.logger_.severe(
292
- 'Unhandled command failure; halting command processing:\n' +
293
- pendingCommand.getResponse().getErrorMessage());
294
- return;
295
- }
296
-
297
- var currentFrame = goog.array.peek(this.queuedCommands_);
298
- var nextCommand = currentFrame.shift();
299
- while (!nextCommand && this.queuedCommands_.length > 1) {
300
- this.queuedCommands_.pop();
301
- this.pendingCommands_.pop();
302
- currentFrame = goog.array.peek(this.queuedCommands_);
303
- nextCommand = currentFrame.shift();
304
- }
305
-
306
- if (nextCommand) {
307
- var parentTarget = goog.array.peek(this.pendingCommands_) || this;
308
- nextCommand.setParentEventTarget(parentTarget);
309
- this.pendingCommands_.push(nextCommand);
310
- this.queuedCommands_.push([]);
311
- this.commandProcessor_.execute(nextCommand);
312
- }
313
- };
314
-
315
-
316
- /**
317
- * @return {?string} This instance's current session ID or {@code null} if it
318
- * does not have one yet.
319
- */
320
- webdriver.WebDriver.prototype.getSessionId = function() {
321
- return this.sessionId_;
322
- };
323
-
324
-
325
- // ----------------------------------------------------------------------------
326
- // Client command functions:
327
- // ----------------------------------------------------------------------------
328
-
329
- /**
330
- * Adds an event handler to catch any {@code ERROR} events from the previous
331
- * command. If the previous command generates an ERROR, that error will be
332
- * suppressed and this instance will continue executing commands. If an error
333
- * was not raised, a new {@code webdriver.WebDriver.EventType.ERROR} event will
334
- * be dispatched for the unexpected behavior.
335
- * @param {string} opt_errorMsg The message to include with the ERROR event if
336
- * the expected error does not occur.
337
- */
338
- webdriver.WebDriver.prototype.catchExpectedError = function(opt_errorMsg,
339
- opt_handlerFn) {
340
- var currentFrame = goog.array.peek(this.queuedCommands_);
341
- var previousCommand = goog.array.peek(currentFrame);
342
- if (!previousCommand) {
343
- throw new Error('No commands in the queue to expect an error from');
344
- }
345
-
346
- var failedCommand = null;
347
- var key = goog.events.listenOnce(previousCommand,
348
- webdriver.Command.ERROR_EVENT, function(e) {
349
- failedCommand = e.target;
350
- this.abortCommand(e.currentTarget);
351
- e.preventDefault();
352
- e.stopPropagation();
353
- return false;
354
- }, /*capture phase*/true, this);
355
-
356
- this.callFunction(function() {
357
- if (null == failedCommand) {
358
- goog.events.unlistenByKey(key);
359
- throw new Error(
360
- (opt_errorMsg ? (opt_errorMsg + '\n') : '') +
361
- 'Expected an error but none were raised.');
362
- } else if (goog.isFunction(opt_handlerFn)) {
363
- opt_handlerFn(failedCommand);
364
- }
365
- });
366
- };
367
-
368
-
369
- /**
370
- * Queueus a command to call the given function if and only if the previous
371
- * command fails. Since failed commands do not have a result, the function
372
- * called will not be given the return value of the previous command.
373
- * @param {function} fn The function to call if the previous command fails.
374
- * @param {Object} opt_selfObj The object in whose scope to call the function.
375
- * @param {*} var_args Any arguments to pass to the function.
376
- */
377
- webdriver.WebDriver.prototype.ifPreviousCommandFailsCall = function(
378
- fn, opt_selfObj, var_args) {
379
- var args = arguments;
380
- var currentFrame = goog.array.peek(this.queuedCommands_);
381
- var previousCommand = goog.array.peek(currentFrame);
382
- if (!previousCommand) {
383
- throw new Error('No commands in the queue to expect an error from');
384
- }
385
- var commandFailed = false;
386
- var key = goog.events.listenOnce(previousCommand,
387
- webdriver.Command.ERROR_EVENT, function(e) {
388
- commandFailed = true;
389
- this.abortCommand(e.currentTarget);
390
- e.preventDefault();
391
- e.stopPropagation();
392
- return false;
393
- }, /*capture phase*/true, this);
394
- this.callFunction(function() {
395
- goog.events.unlistenByKey(key);
396
- if (commandFailed) {
397
- return this.callFunction.apply(this, args);
398
- }
399
- }, this);
400
- };
401
-
402
-
403
- /**
404
- * Adds a command to pause this driver so it will not execute anymore commands
405
- * until {@code #resume()} is called. When this command executes, a
406
- * {@code webdriver.WebDriver.EventType.PAUSED} event will be dispatched.
407
- */
408
- webdriver.WebDriver.prototype.pause = function() {
409
- this.callFunction(goog.bind(this.pauseImmediately, this));
410
- };
411
-
412
-
413
- /**
414
- * Has the driver temporarily halt command execution. This command does
415
- * <em>not</em> result in a {@code webdriver.WebDriver.EventType.PAUSED} event.
416
- * @param {number} ms The amount of time in milliseconds for the driver to
417
- * sleep.
418
- */
419
- webdriver.WebDriver.prototype.sleep = function(ms) {
420
- this.addCommand(webdriver.CommandName.SLEEP).setParameter('ms', ms);
421
- };
422
-
423
-
424
- /**
425
- * Inserts a function into the command queue for the driver to call. The
426
- * function will be passed the last {@code webdriver.Response} retrieved from
427
- * the command processor. The result of the function will be stored in a new
428
- * {@code webdriver.Response} and passed to any subsequent function commands.
429
- * @param {function} fn The function to call; should take a single
430
- * {@code webdriver.Response} object.
431
- * @return {webdriver.Future} The result of the function wrapped in a future.
432
- */
433
- webdriver.WebDriver.prototype.callFunction = function(fn, opt_selfObj,
434
- var_args) {
435
- var args = goog.array.slice(arguments, 2);
436
- var frame = goog.array.peek(this.queuedCommands_);
437
- var previousCommand = goog.array.peek(frame);
438
- args.push(previousCommand ? previousCommand.getFutureResult() : null);
439
- return this.addCommand(webdriver.CommandName.FUNCTION).
440
- setParameter('function', goog.bind(fn, opt_selfObj)).
441
- setParameter('args', args).
442
- getFutureResult();
443
- };
444
-
445
-
446
- /**
447
- * Waits for a condition to be true before executing the next command. If the
448
- * condition does not hold after the given {@code timeout}, an error will be
449
- * raised.
450
- * Example:
451
- * <code>
452
- * driver.get('http://www.google.com');
453
- * var element = driver.findElement({name: 'q'});
454
- * driver.wait(element.isDisplayed, 3000, element);
455
- * </code>
456
- * @param {function} conditionFn The function to evaluate.
457
- * @param {number} timeout The maximum amount of time to wait, in milliseconds.
458
- * @param {Object} opt_self (Optional) The object in whose context to execute
459
- * the {@code conditionFn}.
460
- * @param {boolean} opt_waitNot (Optional) Whether to wait for the inverse of
461
- * the {@code conditionFn}.
462
- */
463
- webdriver.WebDriver.prototype.wait = function(conditionFn, timeout, opt_self,
464
- opt_waitNot) {
465
- conditionFn = goog.bind(conditionFn, opt_self);
466
- var waitOnInverse = !!opt_waitNot;
467
- var callFunction = goog.bind(this.callFunction, this);
468
-
469
- function pollFunction(opt_startTime, opt_future) {
470
- var startTime = opt_startTime || goog.now();
471
-
472
- function checkValue(value) {
473
- var pendingFuture = null;
474
- if (value instanceof webdriver.Future) {
475
- if (value.isSet()) {
476
- value = value.getValue();
477
- } else {
478
- pendingFuture = value;
479
- value = null;
480
- }
481
- }
482
-
483
- var done = !pendingFuture && (waitOnInverse != !!value);
484
- if (!done) {
485
- var ellapsed = goog.now() - startTime;
486
- if (ellapsed > timeout) {
487
- throw Error('Wait timed out after ' + ellapsed + 'ms');
488
- }
489
- // If we pass the pending future in as is, the AbstractCommandProcessor
490
- // will try to resolve it to its value. However, if we're scheduling
491
- // this function, it's because the future has not been set yet, which
492
- // will lead to an error. To avoid this, wrap up the pollFunction in an
493
- // anonymous function so the AbstractCommandProcessor does not
494
- // interfere.
495
- callFunction(goog.bind(pollFunction, null, startTime, pendingFuture));
496
- }
497
- }
498
-
499
- var result = opt_future || conditionFn();
500
- checkValue(result);
501
- }
502
-
503
- this.addCommand(webdriver.CommandName.WAIT).
504
- setParameter('function', pollFunction).
505
- setParameter('args', [0, null]);
506
- };
507
-
508
-
509
- /**
510
- * Waits for the inverse of a condition to be true before executing the next
511
- * command. If the condition does not hold after the given {@code timeout}, an
512
- * error will be raised. Example:
513
- * <code>
514
- * driver.get('http://www.google.com');
515
- * var element = driver.findElement({name: 'q'});
516
- * driver.waitNot(element.isDisplayed, 3000, element);
517
- * </code>
518
- * @param {function} conditionFn The function to evaluate.
519
- * @param {number} timeout The maximum amount of time to wait, in milliseconds.
520
- * @param {Object} opt_self (Optional) The object in whose context to execute
521
- * the {@code conditionFn}.
522
- */
523
- webdriver.WebDriver.prototype.waitNot = function(conditionFn, timeout,
524
- opt_self) {
525
- this.wait(conditionFn, timeout, opt_self, true);
526
- };
527
-
528
-
529
- /**
530
- * Request a new session ID.
531
- */
532
- webdriver.WebDriver.prototype.newSession = function() {
533
- this.callFunction(function() {
534
- this.addCommand(webdriver.CommandName.NEW_SESSION);
535
- this.callFunction(function(value) {
536
- this.sessionId_ = value;
537
- }, this);
538
- }, this);
539
- };
540
-
541
-
542
- /**
543
- * Switch the focus of future commands for this driver to the window with the
544
- * given name.
545
- * @param {string|webdriver.Future} name The name of the window to transfer
546
- * control to. Alternatively, the UUID of a window handle, returned by
547
- * {@code #getWindowHandle()} or {@code #getAllWindowHandles()}.
548
- */
549
- webdriver.WebDriver.prototype.switchToWindow = function(name) {
550
- this.callFunction(function() {
551
- this.addCommand(webdriver.CommandName.SWITCH_TO_WINDOW).
552
- setParameter('name', name);
553
- }, this);
554
- };
555
-
556
-
557
- /**
558
- * Switch the focus of future commands for this driver to the frame with the
559
- * given name or ID. To select sub-frames, simply separate the frame names/IDs
560
- * by dots. As an example, {@code 'main.child'} will select the frame with the
561
- * name 'main' and hten its child 'child'. If a frame name is a number, then it
562
- * will be treated as an index into the {@code window.frames} array of the
563
- * current window.
564
- * @param {string|number|webdriver.WebElement} frame Identifier for the frame
565
- * to transfer control to.
566
- */
567
- webdriver.WebDriver.prototype.switchToFrame = function(frame) {
568
- this.callFunction(function() {
569
- this.addCommand(webdriver.CommandName.SWITCH_TO_FRAME).
570
- setParameter('id', frame);
571
- }, this);
572
- };
573
-
574
-
575
- /**
576
- * Selects either the first frame on the page, or the main document when a page
577
- * contains iframes.
578
- */
579
- webdriver.WebDriver.prototype.switchToDefaultContent = function() {
580
- return this.switchToFrame(null);
581
- };
582
-
583
-
584
- /**
585
- * Retrieves the internal UUID handle for the current window.
586
- * @return {webdriver.Future} The current handle wrapped in a Future.
587
- */
588
- webdriver.WebDriver.prototype.getWindowHandle = function() {
589
- return this.addCommand(webdriver.CommandName.GET_CURRENT_WINDOW_HANDLE).
590
- getFutureResult();
591
- };
592
-
593
-
594
- /**
595
- * Retrieves the handles for all known windows.
596
- */
597
- webdriver.WebDriver.prototype.getAllWindowHandles = function() {
598
- this.addCommand(webdriver.CommandName.GET_WINDOW_HANDLES);
599
- };
600
-
601
-
602
- /**
603
- * Retrieves the HTML source of the current page.
604
- * @return {webdriver.Future} The page source wrapped in a Future.
605
- */
606
- webdriver.WebDriver.prototype.getPageSource = function() {
607
- return this.addCommand(webdriver.CommandName.GET_PAGE_SOURCE).
608
- getFutureResult();
609
- };
610
-
611
-
612
- /**
613
- * Closes the current window.
614
- * <strong>WARNING: This command provides no protection against closing the
615
- * script window (e.g. the window sending commands to the driver)</strong>
616
- */
617
- webdriver.WebDriver.prototype.close = function() {
618
- this.addCommand(webdriver.CommandName.CLOSE);
619
- };
620
-
621
-
622
-
623
- /**
624
- * Helper function for converting an argument to a script into a parameter
625
- * object to send with the {@code webdriver.Command}.
626
- * @param {*} arg The value to convert.
627
- * @return {*} The converted value.
628
- * @see {webdriver.WebDriver.prototype.executeScript}
629
- * @private
630
- */
631
- webdriver.WebDriver.wrapScriptArgument_ = function(arg) {
632
- if (arg instanceof webdriver.WebElement) {
633
- return {'ELEMENT': arg.getId()};
634
- } else if (arg == null || !goog.isDef(arg)) {
635
- return null;
636
- } else if (goog.isBoolean(arg) ||
637
- goog.isNumber(arg) ||
638
- goog.isString(arg)) {
639
- return arg;
640
- } else if (goog.isArray(arg)) {
641
- return goog.array.map(arg, webdriver.WebDriver.wrapScriptArgument_);
642
- } else if (goog.isFunction(arg)) {
643
- throw new Error('Invalid script argument type: ' + goog.typeOf(arg));
644
- } else {
645
- return goog.object.map(arg, webdriver.WebDriver.wrapScriptArgument_);
646
- }
647
- };
648
-
649
-
650
- /**
651
- * Helper function for unwrapping an executeScript result.
652
- * @param {{type:string,value:*}|Array.<{type:string,value:*}>} result The
653
- * result to unwrap.
654
- * @return {*} The unwrapped result.
655
- * @private
656
- */
657
- webdriver.WebDriver.prototype.unwrapScriptResult_ = function(result) {
658
- if (goog.isArray(result)) {
659
- return goog.array.map(result, goog.bind(this.unwrapScriptResult_, this));
660
- }
661
-
662
- if (result != null && goog.isObject(result) && 'ELEMENT' in result) {
663
- var element = new webdriver.WebElement(this);
664
- element.getId().setValue(result['ELEMENT']);
665
- return element;
666
- }
667
-
668
- return result;
669
- };
670
-
671
-
672
- /**
673
- * Adds a command to execute a JavaScript snippet in the window of the page
674
- * currently under test.
675
- * @param {string} script The JavaScript snippet to execute.
676
- * @param {*} var_args The arguments to pass to the script.
677
- * @return {webdriver.Future} The result of the executed script, wrapped in a
678
- * {@code webdriver.Future} instance.
679
- */
680
- webdriver.WebDriver.prototype.executeScript = function(script, var_args) {
681
- var args = goog.array.map(
682
- goog.array.slice(arguments, 1),
683
- webdriver.WebDriver.wrapScriptArgument_);
684
- return this.callFunction(function() {
685
- this.addCommand(webdriver.CommandName.EXECUTE_SCRIPT).
686
- setParameter("script", script).
687
- setParameter("args", args);
688
- return this.callFunction(function(prevResult) {
689
- return this.unwrapScriptResult_(prevResult);
690
- }, this);
691
- }, this);
692
- };
693
-
694
-
695
- /**
696
- * Adds a command to fetch the given URL.
697
- * @param {goog.Uri|string} url The URL to fetch.
698
- */
699
- webdriver.WebDriver.prototype.get = function(url) {
700
- this.callFunction(function() {
701
- this.addCommand(webdriver.CommandName.GET).
702
- setParameter('url', url.toString());
703
- }, this);
704
- };
705
-
706
-
707
- /**
708
- * Navigate backwards in the current browser window's history.
709
- */
710
- webdriver.WebDriver.prototype.back = function() {
711
- this.addCommand(webdriver.CommandName.GO_BACK);
712
- };
713
-
714
-
715
- /**
716
- * Navigate forwards in the current browser window's history.
717
- */
718
- webdriver.WebDriver.prototype.forward = function() {
719
- this.addCommand(webdriver.CommandName.GO_FORWARD);
720
- };
721
-
722
-
723
- /**
724
- * Refresh the current page.
725
- */
726
- webdriver.WebDriver.prototype.refresh = function() {
727
- this.addCommand(webdriver.CommandName.REFRESH);
728
- };
729
-
730
-
731
- /**
732
- * Retrieves the current window URL.
733
- * @return {webdriver.Future} The current URL in a webdriver.Future.
734
- */
735
- webdriver.WebDriver.prototype.getCurrentUrl = function() {
736
- return this.addCommand(webdriver.CommandName.GET_CURRENT_URL).
737
- getFutureResult();
738
- };
739
-
740
-
741
- /**
742
- * Retrieves the current page's title.
743
- * @return {webdriver.Future} The current page title.
744
- */
745
- webdriver.WebDriver.prototype.getTitle = function() {
746
- return this.addCommand(webdriver.CommandName.GET_TITLE).
747
- getFutureResult();
748
- };
749
-
750
-
751
- /**
752
- * Find an element on the current page. If the element cannot be found, an
753
- * {@code webdriver.WebDriver.EventType.ERROR} event will be dispatched.
754
- * @param {webdriver.By.Locator|object} by An object describing the locator
755
- * strategy to use.
756
- * @return {webdriver.WebElement} A WebElement wrapper that can be used to
757
- * issue commands against the located element.
758
- */
759
- webdriver.WebDriver.prototype.findElement = function(by) {
760
- var webElement = new webdriver.WebElement(this);
761
- var locator = webdriver.By.Locator.checkLocator(by);
762
- this.callFunction(function() {
763
- var command = this.addCommand(webdriver.CommandName.FIND_ELEMENT).
764
- setParameter("using", locator.type).
765
- setParameter("value", locator.target);
766
- this.callFunction(function(id) {
767
- webElement.getId().setValue(id['ELEMENT']);
768
- });
769
- }, this);
770
- return webElement;
771
- };
772
-
773
-
774
- /**
775
- * Determine if an element is present on the page.
776
- * @param {webdriver.By.Locator|{*: string}} by The locator to use for finding
777
- * the element, or a short-hand object that can be converted into a locator.
778
- * @return {webdriver.Future} Whether the element was present on the page. The
779
- * return value is wrapped in a Future that will be defined when the driver
780
- * completes the command.
781
- * @see webdriver.By.Locator.createFromObj
782
- */
783
- webdriver.WebDriver.prototype.isElementPresent = function(by) {
784
- var locator = webdriver.By.Locator.checkLocator(by);
785
- return this.callFunction(function() {
786
- var findCommand = this.addCommand(webdriver.CommandName.FIND_ELEMENT).
787
- setParameter("using", locator.type).
788
- setParameter("value", locator.target);
789
- var commandFailed = false;
790
- var key = goog.events.listenOnce(findCommand,
791
- webdriver.Command.ERROR_EVENT, function(e) {
792
- commandFailed = true;
793
- this.abortCommand(e.currentTarget);
794
- e.preventDefault();
795
- e.stopPropagation();
796
- return false;
797
- }, /*capture phase*/true, this);
798
- return this.callFunction(function() {
799
- goog.events.unlistenByKey(key);
800
- return !commandFailed;
801
- });
802
- }, this);
803
- };
804
-
805
-
806
-
807
- /**
808
- * Search for multiple elements on the current page. The result of this
809
- * operation can be accessed from the last saved {@code webdriver.Response}
810
- * object:
811
- * driver.findElements({xpath: '//div'});
812
- * driver.callFunction(function(value) {
813
- * value[0].click();
814
- * value[1].click();
815
- * // etc.
816
- * });
817
- * @param {webdriver.By.Locator|{*: string}} by The locator to use for finding
818
- * the element, or a short-hand object that can be converted into a locator.
819
- * @see webdriver.By.Locator.createFromObj
820
- */
821
- webdriver.WebDriver.prototype.findElements = function(by) {
822
- var locator = webdriver.By.Locator.checkLocator(by);
823
- return this.callFunction(function() {
824
- this.addCommand(webdriver.CommandName.FIND_ELEMENTS).
825
- setParameter("using", locator.type).
826
- setParameter("value", locator.target);
827
- return this.callFunction(function(ids) {
828
- var elements = [];
829
- for (var i = 0; i < ids.length; i++) {
830
- if (ids[i]) {
831
- var element = new webdriver.WebElement(this);
832
- element.getId().setValue(ids[i]['ELEMENT']);
833
- elements.push(element);
834
- }
835
- }
836
- return elements;
837
- }, this);
838
- }, this);
839
- };
840
-
841
-
842
- /**
843
- * Adjust the speed of user input.
844
- * @param {webdriver.WebDriver.Speed} speed The new speed setting.
845
- */
846
- webdriver.WebDriver.prototype.setSpeed = function(speed) {
847
- this.addCommand(webdriver.CommandName.SET_SPEED).
848
- setParameter("speed", speed);
849
- };
850
-
851
-
852
- /**
853
- * Fetch the current user input speed.
854
- * @return {webdriver.Future} A Future whose value will be set by this driver
855
- * when the query command completes.
856
- */
857
- webdriver.WebDriver.prototype.getSpeed = function() {
858
- return this.addCommand(webdriver.CommandName.GET_SPEED).
859
- getFutureResult();
860
- };