selenium-webdriver 2.43.5 → 2.44.0

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.
Files changed (219) hide show
  1. package/CHANGES.md +20 -0
  2. package/README.md +8 -13
  3. package/builder.js +4 -3
  4. package/docs/class_webdriver_Alert.html +6 -6
  5. package/docs/class_webdriver_AlertPromise.html +6 -6
  6. package/docs/class_webdriver_UnhandledAlertError.html +4 -4
  7. package/docs/class_webdriver_WebDriver.html +39 -37
  8. package/docs/class_webdriver_WebDriver_Logs.html +3 -3
  9. package/docs/class_webdriver_WebDriver_Navigation.html +5 -5
  10. package/docs/class_webdriver_WebDriver_Options.html +9 -9
  11. package/docs/class_webdriver_WebDriver_TargetLocator.html +6 -6
  12. package/docs/class_webdriver_WebDriver_Timeouts.html +4 -4
  13. package/docs/class_webdriver_WebDriver_Window.html +6 -6
  14. package/docs/class_webdriver_WebElement.html +23 -23
  15. package/docs/class_webdriver_WebElementPromise.html +22 -22
  16. package/docs/class_webdriver_promise_CancellationError.html +3 -0
  17. package/docs/class_webdriver_promise_ControlFlow.html +32 -32
  18. package/docs/class_webdriver_promise_Deferred.html +7 -8
  19. package/docs/class_webdriver_promise_Frame_.html +14 -30
  20. package/docs/class_webdriver_promise_Promise.html +2 -2
  21. package/docs/class_webdriver_promise_Task_.html +12 -12
  22. package/docs/class_webdriver_until_Condition.html +3 -0
  23. package/docs/enum_webdriver_Key.html +1 -1
  24. package/docs/enum_webdriver_promise_ControlFlow_EventType.html +1 -1
  25. package/docs/enum_webdriver_promise_Deferred_State_.html +1 -1
  26. package/docs/index.html +8 -13
  27. package/docs/interface_webdriver_promise_Thenable.html +8 -10
  28. package/docs/license.html +1 -1
  29. package/docs/module_selenium-webdriver.html +2 -2
  30. package/docs/module_selenium-webdriver__base.html +1 -1
  31. package/docs/module_selenium-webdriver__base_class_Context.html +1 -1
  32. package/docs/module_selenium-webdriver_builder.html +1 -1
  33. package/docs/module_selenium-webdriver_builder_class_Builder.html +1 -1
  34. package/docs/module_selenium-webdriver_chrome.html +1 -1
  35. package/docs/module_selenium-webdriver_chrome_class_Driver.html +2 -2
  36. package/docs/module_selenium-webdriver_chrome_class_Options.html +2 -2
  37. package/docs/module_selenium-webdriver_chrome_class_ServiceBuilder.html +1 -1
  38. package/docs/module_selenium-webdriver_error.html +1 -1
  39. package/docs/module_selenium-webdriver_executors.html +1 -1
  40. package/docs/module_selenium-webdriver_firefox.html +1 -1
  41. package/docs/module_selenium-webdriver_firefox_binary.html +1 -1
  42. package/docs/module_selenium-webdriver_firefox_binary_class_Binary.html +1 -1
  43. package/docs/module_selenium-webdriver_firefox_class_Driver.html +2 -2
  44. package/docs/module_selenium-webdriver_firefox_class_Options.html +1 -1
  45. package/docs/module_selenium-webdriver_firefox_extension.html +1 -1
  46. package/docs/module_selenium-webdriver_firefox_profile.html +1 -1
  47. package/docs/module_selenium-webdriver_firefox_profile_class_Profile.html +1 -1
  48. package/docs/module_selenium-webdriver_http.html +1 -1
  49. package/docs/module_selenium-webdriver_http_class_HttpClient.html +1 -1
  50. package/docs/module_selenium-webdriver_http_util.html +1 -1
  51. package/docs/module_selenium-webdriver_io.html +1 -1
  52. package/docs/module_selenium-webdriver_io_exec.html +1 -1
  53. package/docs/module_selenium-webdriver_net.html +1 -1
  54. package/docs/module_selenium-webdriver_net_portprober.html +1 -1
  55. package/docs/module_selenium-webdriver_phantomjs.html +1 -1
  56. package/docs/module_selenium-webdriver_phantomjs_class_Driver.html +2 -2
  57. package/docs/module_selenium-webdriver_proxy.html +1 -1
  58. package/docs/module_selenium-webdriver_remote.html +1 -1
  59. package/docs/module_selenium-webdriver_remote_class_DriverService.html +2 -2
  60. package/docs/module_selenium-webdriver_remote_class_SeleniumServer.html +2 -2
  61. package/docs/module_selenium-webdriver_testing.html +16 -29
  62. package/docs/module_selenium-webdriver_testing_assert.html +1 -1
  63. package/docs/namespace_webdriver_promise.html +18 -20
  64. package/docs/namespace_webdriver_stacktrace.html +15 -15
  65. package/docs/namespace_webdriver_until.html +32 -0
  66. package/docs/source/_base.js.src.html +1 -1
  67. package/docs/source/builder.js.src.html +1 -1
  68. package/docs/source/chrome.js.src.html +1 -1
  69. package/docs/source/error.js.src.html +1 -1
  70. package/docs/source/executors.js.src.html +1 -1
  71. package/docs/source/firefox/binary.js.src.html +1 -1
  72. package/docs/source/firefox/extension.js.src.html +1 -1
  73. package/docs/source/firefox/index.js.src.html +1 -1
  74. package/docs/source/firefox/profile.js.src.html +1 -1
  75. package/docs/source/http/index.js.src.html +1 -1
  76. package/docs/source/http/util.js.src.html +1 -1
  77. package/docs/source/index.js.src.html +1 -1
  78. package/docs/source/io/exec.js.src.html +1 -1
  79. package/docs/source/io/index.js.src.html +1 -1
  80. package/docs/source/lib/atoms/error.js.src.html +1 -1
  81. package/docs/source/lib/atoms/json.js.src.html +1 -1
  82. package/docs/source/lib/atoms/response.js.src.html +1 -1
  83. package/docs/source/lib/atoms/userAgent.js.src.html +1 -1
  84. package/docs/source/lib/goog/array/array.js.src.html +1 -1
  85. package/docs/source/lib/goog/asserts/asserts.js.src.html +1 -1
  86. package/docs/source/lib/goog/async/nexttick.js.src.html +1 -1
  87. package/docs/source/lib/goog/async/run.js.src.html +1 -1
  88. package/docs/source/lib/goog/base.js.src.html +1 -1
  89. package/docs/source/lib/goog/debug/debug.js.src.html +1 -1
  90. package/docs/source/lib/goog/debug/entrypointregistry.js.src.html +1 -1
  91. package/docs/source/lib/goog/debug/error.js.src.html +1 -1
  92. package/docs/source/lib/goog/debug/logbuffer.js.src.html +1 -1
  93. package/docs/source/lib/goog/debug/logger.js.src.html +1 -1
  94. package/docs/source/lib/goog/debug/logrecord.js.src.html +1 -1
  95. package/docs/source/lib/goog/deps.js.src.html +1 -1
  96. package/docs/source/lib/goog/disposable/disposable.js.src.html +1 -1
  97. package/docs/source/lib/goog/disposable/idisposable.js.src.html +1 -1
  98. package/docs/source/lib/goog/dom/browserfeature.js.src.html +1 -1
  99. package/docs/source/lib/goog/dom/dom.js.src.html +1 -1
  100. package/docs/source/lib/goog/dom/nodetype.js.src.html +1 -1
  101. package/docs/source/lib/goog/dom/tagname.js.src.html +1 -1
  102. package/docs/source/lib/goog/dom/vendor.js.src.html +1 -1
  103. package/docs/source/lib/goog/events/browserevent.js.src.html +1 -1
  104. package/docs/source/lib/goog/events/browserfeature.js.src.html +1 -1
  105. package/docs/source/lib/goog/events/event.js.src.html +1 -1
  106. package/docs/source/lib/goog/events/eventid.js.src.html +1 -1
  107. package/docs/source/lib/goog/events/events.js.src.html +1 -1
  108. package/docs/source/lib/goog/events/eventtarget.js.src.html +1 -1
  109. package/docs/source/lib/goog/events/eventtype.js.src.html +1 -1
  110. package/docs/source/lib/goog/events/keycodes.js.src.html +1 -1
  111. package/docs/source/lib/goog/events/listenable.js.src.html +1 -1
  112. package/docs/source/lib/goog/events/listener.js.src.html +1 -1
  113. package/docs/source/lib/goog/events/listenermap.js.src.html +1 -1
  114. package/docs/source/lib/goog/functions/functions.js.src.html +1 -1
  115. package/docs/source/lib/goog/iter/iter.js.src.html +1 -1
  116. package/docs/source/lib/goog/json/json.js.src.html +1 -1
  117. package/docs/source/lib/goog/labs/testing/assertthat.js.src.html +1 -1
  118. package/docs/source/lib/goog/labs/testing/logicmatcher.js.src.html +1 -1
  119. package/docs/source/lib/goog/labs/testing/matcher.js.src.html +1 -1
  120. package/docs/source/lib/goog/labs/testing/numbermatcher.js.src.html +1 -1
  121. package/docs/source/lib/goog/labs/testing/objectmatcher.js.src.html +1 -1
  122. package/docs/source/lib/goog/labs/testing/stringmatcher.js.src.html +1 -1
  123. package/docs/source/lib/goog/labs/useragent/browser.js.src.html +1 -1
  124. package/docs/source/lib/goog/labs/useragent/engine.js.src.html +1 -1
  125. package/docs/source/lib/goog/labs/useragent/util.js.src.html +1 -1
  126. package/docs/source/lib/goog/math/box.js.src.html +1 -1
  127. package/docs/source/lib/goog/math/coordinate.js.src.html +1 -1
  128. package/docs/source/lib/goog/math/math.js.src.html +1 -1
  129. package/docs/source/lib/goog/math/rect.js.src.html +1 -1
  130. package/docs/source/lib/goog/math/size.js.src.html +1 -1
  131. package/docs/source/lib/goog/net/wrapperxmlhttpfactory.js.src.html +1 -1
  132. package/docs/source/lib/goog/net/xhrlike.js.src.html +1 -1
  133. package/docs/source/lib/goog/net/xmlhttp.js.src.html +1 -1
  134. package/docs/source/lib/goog/net/xmlhttpfactory.js.src.html +1 -1
  135. package/docs/source/lib/goog/object/object.js.src.html +1 -1
  136. package/docs/source/lib/goog/reflect/reflect.js.src.html +1 -1
  137. package/docs/source/lib/goog/string/string.js.src.html +1 -1
  138. package/docs/source/lib/goog/structs/collection.js.src.html +1 -1
  139. package/docs/source/lib/goog/structs/map.js.src.html +1 -1
  140. package/docs/source/lib/goog/structs/set.js.src.html +1 -1
  141. package/docs/source/lib/goog/structs/structs.js.src.html +1 -1
  142. package/docs/source/lib/goog/style/style.js.src.html +1 -1
  143. package/docs/source/lib/goog/testing/asserts.js.src.html +1 -1
  144. package/docs/source/lib/goog/testing/asynctestcase.js.src.html +1 -1
  145. package/docs/source/lib/goog/testing/events/events.js.src.html +1 -1
  146. package/docs/source/lib/goog/testing/functionmock.js.src.html +1 -1
  147. package/docs/source/lib/goog/testing/jsunit.js.src.html +1 -1
  148. package/docs/source/lib/goog/testing/loosemock.js.src.html +1 -1
  149. package/docs/source/lib/goog/testing/mock.js.src.html +1 -1
  150. package/docs/source/lib/goog/testing/mockclock.js.src.html +1 -1
  151. package/docs/source/lib/goog/testing/mockcontrol.js.src.html +1 -1
  152. package/docs/source/lib/goog/testing/mockinterface.js.src.html +1 -1
  153. package/docs/source/lib/goog/testing/mockmatchers.js.src.html +1 -1
  154. package/docs/source/lib/goog/testing/objectpropertystring.js.src.html +1 -1
  155. package/docs/source/lib/goog/testing/propertyreplacer.js.src.html +1 -1
  156. package/docs/source/lib/goog/testing/recordfunction.js.src.html +1 -1
  157. package/docs/source/lib/goog/testing/stacktrace.js.src.html +1 -1
  158. package/docs/source/lib/goog/testing/strictmock.js.src.html +1 -1
  159. package/docs/source/lib/goog/testing/testcase.js.src.html +1 -1
  160. package/docs/source/lib/goog/testing/testrunner.js.src.html +1 -1
  161. package/docs/source/lib/goog/testing/watchers.js.src.html +1 -1
  162. package/docs/source/lib/goog/uri/uri.js.src.html +1 -1
  163. package/docs/source/lib/goog/uri/utils.js.src.html +1 -1
  164. package/docs/source/lib/goog/useragent/product.js.src.html +1 -1
  165. package/docs/source/lib/goog/useragent/product_isversion.js.src.html +1 -1
  166. package/docs/source/lib/goog/useragent/useragent.js.src.html +1 -1
  167. package/docs/source/lib/webdriver/abstractbuilder.js.src.html +1 -1
  168. package/docs/source/lib/webdriver/actionsequence.js.src.html +1 -1
  169. package/docs/source/lib/webdriver/builder.js.src.html +1 -1
  170. package/docs/source/lib/webdriver/button.js.src.html +1 -1
  171. package/docs/source/lib/webdriver/capabilities.js.src.html +1 -1
  172. package/docs/source/lib/webdriver/command.js.src.html +1 -1
  173. package/docs/source/lib/webdriver/events.js.src.html +1 -1
  174. package/docs/source/lib/webdriver/firefoxdomexecutor.js.src.html +1 -1
  175. package/docs/source/lib/webdriver/http/corsclient.js.src.html +1 -1
  176. package/docs/source/lib/webdriver/http/http.js.src.html +1 -1
  177. package/docs/source/lib/webdriver/http/xhrclient.js.src.html +1 -1
  178. package/docs/source/lib/webdriver/key.js.src.html +1 -1
  179. package/docs/source/lib/webdriver/locators.js.src.html +1 -1
  180. package/docs/source/lib/webdriver/logging.js.src.html +1 -1
  181. package/docs/source/lib/webdriver/process.js.src.html +1 -1
  182. package/docs/source/lib/webdriver/promise.js.src.html +1 -1
  183. package/docs/source/lib/webdriver/session.js.src.html +1 -1
  184. package/docs/source/lib/webdriver/stacktrace.js.src.html +1 -1
  185. package/docs/source/lib/webdriver/testing/asserts.js.src.html +1 -1
  186. package/docs/source/lib/webdriver/testing/testcase.js.src.html +1 -1
  187. package/docs/source/lib/webdriver/until.js.src.html +1 -0
  188. package/docs/source/lib/webdriver/webdriver.js.src.html +1 -1
  189. package/docs/source/net/index.js.src.html +1 -1
  190. package/docs/source/net/portprober.js.src.html +1 -1
  191. package/docs/source/phantomjs.js.src.html +1 -1
  192. package/docs/source/proxy.js.src.html +1 -1
  193. package/docs/source/remote/index.js.src.html +1 -1
  194. package/docs/source/testing/assert.js.src.html +1 -1
  195. package/docs/source/testing/index.js.src.html +1 -1
  196. package/docs/types.js +1 -1
  197. package/example/google_search.js +9 -17
  198. package/example/google_search_generator.js +6 -7
  199. package/example/google_search_test.js +10 -18
  200. package/example/parallel_flows.js +4 -7
  201. package/index.js +6 -0
  202. package/lib/firefox/webdriver.xpi +0 -0
  203. package/lib/goog/deps.js +7 -5
  204. package/lib/test/index.js +0 -8
  205. package/lib/webdriver/promise.js +263 -251
  206. package/lib/webdriver/stacktrace.js +15 -1
  207. package/lib/webdriver/test/promise_flow_test.js +82 -76
  208. package/lib/webdriver/test/promise_test.js +22 -62
  209. package/lib/webdriver/test/stacktrace_test.js +18 -0
  210. package/lib/webdriver/test/until_test.js +388 -0
  211. package/lib/webdriver/test/webdriver_test.js +41 -0
  212. package/lib/webdriver/until.js +408 -0
  213. package/lib/webdriver/webdriver.js +91 -29
  214. package/package.json +2 -2
  215. package/test/element_finding_test.js +6 -6
  216. package/test/http/util_test.js +4 -5
  217. package/test/page_loading_test.js +7 -7
  218. package/test/stale_element_test.js +2 -10
  219. package/testing/index.js +9 -22
@@ -0,0 +1,388 @@
1
+ // Copyright 2014 Software Freedom Conservancy. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ goog.require('bot.Error');
16
+ goog.require('bot.ErrorCode');
17
+ goog.require('bot.response');
18
+ goog.require('goog.testing.AsyncTestCase');
19
+ goog.require('goog.testing.jsunit');
20
+ goog.require('webdriver.By');
21
+ goog.require('webdriver.CommandName');
22
+ goog.require('webdriver.WebDriver');
23
+ goog.require('webdriver.WebElement');
24
+ goog.require('webdriver.WebElementPromise');
25
+ goog.require('webdriver.until');
26
+
27
+ var test = goog.testing.AsyncTestCase.createAndInstall('until_test');
28
+
29
+ var By = webdriver.By;
30
+ var until = webdriver.until;
31
+ var CommandName = webdriver.CommandName;
32
+
33
+ var driver, executor;
34
+
35
+ var TestExecutor = function() {
36
+ this.handlers_ = {};
37
+ };
38
+
39
+
40
+ TestExecutor.prototype.on = function(cmd, handler) {
41
+ this.handlers_[cmd] = handler;
42
+ return this;
43
+ };
44
+
45
+
46
+ TestExecutor.prototype.execute = function(cmd, callback) {
47
+ if (!this.handlers_[cmd.getName()]) {
48
+ throw Error('Unsupported command: ' + cmd.getName());
49
+ }
50
+ this.handlers_[cmd.getName()](cmd, callback);
51
+ };
52
+
53
+
54
+ function setUp() {
55
+ executor = new TestExecutor();
56
+ driver = new webdriver.WebDriver('session-id', executor);
57
+ }
58
+
59
+
60
+ function testUntilAbleToSwitchToFrame_failsFastForNonSwitchErrors() {
61
+ test.waitForAsync();
62
+
63
+ var e = Error('boom');
64
+ executor.on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
65
+ callback(e);
66
+ });
67
+
68
+ driver.wait(until.ableToSwitchToFrame(0), 100).then(fail, function(e2) {
69
+ assertEquals(e, e2);
70
+ test.continueTesting();
71
+ });
72
+ }
73
+
74
+
75
+ function testUntilAbleToSwitchToFrame_byIndex() {
76
+ test.waitForAsync();
77
+
78
+ executor.on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
79
+ callback(null, {status: bot.ErrorCode.SUCCESS});
80
+ });
81
+
82
+ driver.wait(until.ableToSwitchToFrame(0), 100).then(function() {
83
+ test.continueTesting();
84
+ }, fail);
85
+ }
86
+
87
+
88
+ function testUntilAbleToSwitchToFrame_byWebElement() {
89
+ test.waitForAsync();
90
+
91
+ executor.on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
92
+ callback(null, {status: bot.ErrorCode.SUCCESS});
93
+ });
94
+
95
+ var el = new webdriver.WebElement(driver, {ELEMENT: 1234});
96
+ driver.wait(until.ableToSwitchToFrame(el), 100).then(function() {
97
+ test.continueTesting();
98
+ }, fail);
99
+ }
100
+
101
+
102
+ function testUntilAbleToSwitchToFrame_byWebElementPromise() {
103
+ test.waitForAsync();
104
+
105
+ executor.on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
106
+ callback(null, {status: bot.ErrorCode.SUCCESS});
107
+ });
108
+
109
+ var el = new webdriver.WebElementPromise(driver,
110
+ webdriver.promise.fulfilled(
111
+ new webdriver.WebElement(driver, {ELEMENT: 1234})));
112
+ driver.wait(until.ableToSwitchToFrame(el), 100).then(function() {
113
+ test.continueTesting();
114
+ }, fail);
115
+ }
116
+
117
+
118
+ function testUntilAbleToSwitchToFrame_byLocator() {
119
+ test.waitForAsync();
120
+
121
+ executor.on(CommandName.FIND_ELEMENTS, function(cmd, callback) {
122
+ callback(null, {
123
+ status: bot.ErrorCode.SUCCESS,
124
+ value: [{ELEMENT: 1234}]
125
+ });
126
+ }).on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
127
+ callback(null, {status: bot.ErrorCode.SUCCESS});
128
+ });
129
+
130
+ driver.wait(until.ableToSwitchToFrame(By.id('foo')), 100).then(function() {
131
+ test.continueTesting();
132
+ }, fail);
133
+ }
134
+
135
+
136
+ function testUntilAbleToSwitchToFrame_byLocator_elementNotInitiallyFound() {
137
+ test.waitForAsync();
138
+
139
+ var foundResponses = [[], [], [{ELEMENT: 1234}]];
140
+ executor.on(CommandName.FIND_ELEMENTS, function(cmd, callback) {
141
+ callback(null, {
142
+ status: bot.ErrorCode.SUCCESS,
143
+ value: foundResponses.shift()
144
+ });
145
+ }).on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
146
+ callback(null, {status: bot.ErrorCode.SUCCESS});
147
+ });
148
+
149
+ driver.wait(until.ableToSwitchToFrame(By.id('foo')), 2000).then(function() {
150
+ assertEquals(0, foundResponses.length);
151
+ test.continueTesting();
152
+ }, fail);
153
+ }
154
+
155
+
156
+ function testUntilAbleToSwitchToFrame_timesOutIfNeverAbletoSwitchFrames() {
157
+ test.waitForAsync();
158
+
159
+ var count = 0;
160
+ executor.on(CommandName.SWITCH_TO_FRAME, function(cmd, callback) {
161
+ count += 1;
162
+ callback(null, {status: bot.ErrorCode.NO_SUCH_FRAME});
163
+ });
164
+
165
+ driver.wait(until.ableToSwitchToFrame(0), 100).then(fail, function(e) {
166
+ assertTrue(count > 0);
167
+ assertTrue('Wrong message: ' + e.message, goog.string.startsWith(
168
+ e.message, 'Waiting to be able to switch to frame'));
169
+ test.continueTesting();
170
+ });
171
+ }
172
+
173
+
174
+ function testUntilAlertIsPresent_failsFastForNonAlertSwitchErrors() {
175
+ test.waitForAsync();
176
+ driver.wait(until.alertIsPresent(), 100).then(fail, function(e) {
177
+ assertEquals(
178
+ 'Unsupported command: ' + CommandName.GET_ALERT_TEXT, e.message);
179
+ test.continueTesting();
180
+ });
181
+ }
182
+
183
+
184
+ function testUntilAlertIsPresent() {
185
+ test.waitForAsync();
186
+
187
+ var count = 0;
188
+ executor.on(CommandName.GET_ALERT_TEXT, function(cmd, callback) {
189
+ if (count++ < 3) {
190
+ callback(null, {status: bot.ErrorCode.NO_SUCH_ALERT});
191
+ } else {
192
+ callback(null, {status: bot.ErrorCode.SUCCESS});
193
+ }
194
+ }).on(CommandName.DISMISS_ALERT, function(cmd, callback) {
195
+ callback(null, {status: bot.ErrorCode.SUCCESS});
196
+ });
197
+
198
+ driver.wait(until.alertIsPresent(), 1000).then(function(alert) {
199
+ assertEquals(4, count);
200
+ return alert.dismiss();
201
+ }).then(function() {
202
+ test.continueTesting();
203
+ });
204
+ }
205
+
206
+
207
+ function testUntilTitleIs() {
208
+ test.waitForAsync();
209
+
210
+ var titles = ['foo', 'bar', 'baz'];
211
+ executor.on(CommandName.GET_TITLE, function(cmd, callback) {
212
+ callback(null, bot.response.createResponse(titles.shift()));
213
+ });
214
+
215
+ driver.wait(until.titleIs('bar'), 3000).then(function() {
216
+ assertArrayEquals(['baz'], titles);
217
+ test.continueTesting();
218
+ });
219
+ }
220
+
221
+
222
+ function testUntilTitleContains() {
223
+ test.waitForAsync();
224
+
225
+ var titles = ['foo', 'froogle', 'google'];
226
+ executor.on(CommandName.GET_TITLE, function(cmd, callback) {
227
+ callback(null, bot.response.createResponse(titles.shift()));
228
+ });
229
+
230
+ driver.wait(until.titleContains('oogle'), 3000).then(function() {
231
+ assertArrayEquals(['google'], titles);
232
+ test.continueTesting();
233
+ });
234
+ }
235
+
236
+
237
+ function testUntilTitleMatches() {
238
+ test.waitForAsync();
239
+
240
+ var titles = ['foo', 'froogle', 'aaaabc', 'aabbbc', 'google'];
241
+ executor.on(CommandName.GET_TITLE, function(cmd, callback) {
242
+ callback(null, bot.response.createResponse(titles.shift()));
243
+ });
244
+
245
+ driver.wait(until.titleMatches(/^a{2,3}b+c$/), 3000).then(function() {
246
+ assertArrayEquals(['google'], titles);
247
+ test.continueTesting();
248
+ });
249
+ }
250
+
251
+
252
+ function testUntilElementLocated() {
253
+ test.waitForAsync();
254
+
255
+ var responses = [[], [{ELEMENT: 'abc123'}, {ELEMENT: 'foo'}], ['end']];
256
+ executor.on(CommandName.FIND_ELEMENTS, function(cmd, callback) {
257
+ callback(null, bot.response.createResponse(responses.shift()));
258
+ });
259
+
260
+ driver.wait(until.elementLocated(By.id('quux')), 2000).then(function(el) {
261
+ return el.getId();
262
+ }).then(function(id) {
263
+ assertArrayEquals([['end']], responses);
264
+ assertEquals('abc123', id['ELEMENT']);
265
+ test.continueTesting();
266
+ });
267
+ }
268
+
269
+
270
+ function testUntilElementsLocated() {
271
+ test.waitForAsync();
272
+
273
+ var responses = [[], [{ELEMENT: 'abc123'}, {ELEMENT: 'foo'}], ['end']];
274
+ executor.on(CommandName.FIND_ELEMENTS, function(cmd, callback) {
275
+ callback(null, bot.response.createResponse(responses.shift()));
276
+ });
277
+
278
+ driver.wait(until.elementsLocated(By.id('quux')), 2000).then(function(els) {
279
+ return webdriver.promise.all(goog.array.map(els, function(el) {
280
+ return el.getId();
281
+ }));
282
+ }).then(function(ids) {
283
+ assertArrayEquals([['end']], responses);
284
+ assertEquals(2, ids.length);
285
+ assertEquals('abc123', ids[0]['ELEMENT']);
286
+ assertEquals('foo', ids[1]['ELEMENT']);
287
+ test.continueTesting();
288
+ });
289
+ }
290
+
291
+
292
+ function testUntilStalenessOf() {
293
+ test.waitForAsync();
294
+
295
+ var responses = [
296
+ bot.response.createResponse('body'),
297
+ bot.response.createResponse('body'),
298
+ bot.response.createResponse('body'),
299
+ bot.response.createErrorResponse(
300
+ new bot.Error(bot.ErrorCode.STALE_ELEMENT_REFERENCE, 'now stale')),
301
+ ['end']
302
+ ];
303
+ executor.on(CommandName.GET_ELEMENT_TAG_NAME, function(cmd, callback) {
304
+ callback(null, responses.shift());
305
+ });
306
+
307
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
308
+ driver.wait(until.stalenessOf(el), 2000).then(function() {
309
+ assertArrayEquals([['end']], responses);
310
+ test.continueTesting();
311
+ });
312
+ }
313
+
314
+ function runElementStateTest(predicate, command, responses) {
315
+ test.waitForAsync();
316
+ assertTrue(responses.length > 1);
317
+
318
+ responses = goog.array.concat(responses, ['end']);
319
+ executor.on(command, function(cmd, callback) {
320
+ callback(null, bot.response.createResponse(responses.shift()));
321
+ });
322
+ driver.wait(predicate, 2000).then(function() {
323
+ assertArrayEquals(['end'], responses);
324
+ test.continueTesting();
325
+ });
326
+ }
327
+
328
+ function testUntilElementIsVisible() {
329
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
330
+ runElementStateTest(until.elementIsVisible(el),
331
+ CommandName.IS_ELEMENT_DISPLAYED, [false, false, true]);
332
+ }
333
+
334
+
335
+ function testUntilElementIsNotVisible() {
336
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
337
+ runElementStateTest(until.elementIsNotVisible(el),
338
+ CommandName.IS_ELEMENT_DISPLAYED, [true, true, false]);
339
+ }
340
+
341
+
342
+ function testUntilElementIsEnabled() {
343
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
344
+ runElementStateTest(until.elementIsEnabled(el),
345
+ CommandName.IS_ELEMENT_ENABLED, [false, false, true]);
346
+ }
347
+
348
+
349
+ function testUntilElementIsDisabled() {
350
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
351
+ runElementStateTest(until.elementIsDisabled(el),
352
+ CommandName.IS_ELEMENT_ENABLED, [true, true, false]);
353
+ }
354
+
355
+
356
+ function testUntilElementIsSelected() {
357
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
358
+ runElementStateTest(until.elementIsSelected(el),
359
+ CommandName.IS_ELEMENT_SELECTED, [false, false, true]);
360
+ }
361
+
362
+
363
+ function testUntilElementIsNotSelected() {
364
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
365
+ runElementStateTest(until.elementIsNotSelected(el),
366
+ CommandName.IS_ELEMENT_SELECTED, [true, true, false]);
367
+ }
368
+
369
+
370
+ function testUntilElementTextIs() {
371
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
372
+ runElementStateTest(until.elementTextIs(el, 'foobar'),
373
+ CommandName.GET_ELEMENT_TEXT, ['foo', 'fooba', 'foobar']);
374
+ }
375
+
376
+
377
+ function testUntilElementTextContains() {
378
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
379
+ runElementStateTest(until.elementTextContains(el, 'bar'),
380
+ CommandName.GET_ELEMENT_TEXT, ['foo', 'foobaz', 'foobarbaz']);
381
+ }
382
+
383
+
384
+ function testUntilElementTextMatches() {
385
+ var el = new webdriver.WebElement(driver, {ELEMENT:'foo'});
386
+ runElementStateTest(until.elementTextMatches(el, /fo+bar{3}/),
387
+ CommandName.GET_ELEMENT_TEXT, ['foo', 'foobar', 'fooobarrr']);
388
+ }
@@ -510,6 +510,26 @@ function testToWireValue_arrayWithWebElement() {
510
510
  }
511
511
 
512
512
 
513
+ function testToWireValue_arrayWithWebElementPromise() {
514
+ var elementJson = {};
515
+ elementJson[webdriver.WebElement.ELEMENT_KEY] = 'fefifofum';
516
+
517
+ var element = new webdriver.WebElement(STUB_DRIVER, elementJson);
518
+ var elementPromise = new webdriver.WebElementPromise(STUB_DRIVER,
519
+ webdriver.promise.fulfilled(element));
520
+
521
+ var callback;
522
+ webdriver.WebDriver.toWireValue_([elementPromise]).
523
+ then(callback = callbackHelper(function(actual) {
524
+ assertTrue(goog.isArray(actual));
525
+ assertEquals(1, actual.length);
526
+ webdriver.test.testutil.assertObjectEquals(elementJson, actual[0]);
527
+ }));
528
+ callback.assertCalled();
529
+ verifyAll(); // Expected by tear down.
530
+ }
531
+
532
+
513
533
  function testToWireValue_complexArray() {
514
534
  var elementJson = {};
515
535
  elementJson[webdriver.WebElement.ELEMENT_KEY] = 'fefifofum';
@@ -1538,6 +1558,27 @@ function testExecuteScript_webElementArgumentConversion() {
1538
1558
  }
1539
1559
 
1540
1560
 
1561
+ function testExecuteScript_webElementPromiseArgumentConversion() {
1562
+ var elementJson = {'ELEMENT':'bar'};
1563
+
1564
+ var testHelper = TestHelper.expectingSuccess().
1565
+ expect(CName.FIND_ELEMENT, {'using':'id', 'value':'foo'}).
1566
+ andReturnSuccess(elementJson).
1567
+ expect(CName.EXECUTE_SCRIPT).
1568
+ withParameters({
1569
+ 'script': 'return 1;',
1570
+ 'args': [elementJson]
1571
+ }).
1572
+ andReturnSuccess(null).
1573
+ replayAll();
1574
+
1575
+ var driver = testHelper.createDriver();
1576
+ var element = driver.findElement(By.id('foo'));
1577
+ driver.executeScript('return 1;', element);
1578
+ testHelper.execute();
1579
+ }
1580
+
1581
+
1541
1582
  function testExecuteScript_argumentConversion() {
1542
1583
  var elementJson = {};
1543
1584
  elementJson[webdriver.WebElement.ELEMENT_KEY] = 'fefifofum';