selenium-webdriver 4.0.0-alpha.7 → 4.0.0-beta.3

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 (50) hide show
  1. package/CHANGES.md +56 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +2 -0
  5. package/chrome.js +69 -79
  6. package/chromium.js +231 -164
  7. package/{lib/atoms/make-atoms-module.js → devtools/CDPConnection.js} +15 -9
  8. package/edge.js +104 -146
  9. package/example/chrome_android.js +45 -0
  10. package/example/chrome_mobile_emulation.js +46 -0
  11. package/example/firefox_channels.js +84 -0
  12. package/example/google_search.js +50 -0
  13. package/example/google_search_test.js +70 -0
  14. package/example/headless.js +63 -0
  15. package/example/logging.js +64 -0
  16. package/firefox.js +199 -200
  17. package/http/index.js +128 -116
  18. package/http/util.js +56 -64
  19. package/ie.js +180 -104
  20. package/index.js +246 -199
  21. package/io/exec.js +35 -40
  22. package/io/index.js +146 -157
  23. package/io/zip.js +75 -66
  24. package/lib/atoms/find-elements.js +123 -0
  25. package/lib/atoms/get-attribute.js +75 -59
  26. package/lib/atoms/is-displayed.js +72 -72
  27. package/lib/atoms/mutation-listener.js +55 -0
  28. package/lib/by.js +192 -65
  29. package/lib/capabilities.js +76 -86
  30. package/lib/command.js +19 -35
  31. package/lib/error.js +134 -168
  32. package/lib/http.js +308 -232
  33. package/lib/input.js +192 -453
  34. package/lib/logging.js +126 -137
  35. package/lib/promise.js +53 -71
  36. package/lib/proxy.js +31 -41
  37. package/lib/session.js +12 -15
  38. package/lib/symbols.js +3 -4
  39. package/lib/until.js +162 -160
  40. package/lib/webdriver.js +1014 -549
  41. package/net/index.js +30 -36
  42. package/net/portprober.js +30 -143
  43. package/opera.js +406 -0
  44. package/package.json +15 -7
  45. package/proxy.js +2 -2
  46. package/remote/index.js +189 -187
  47. package/safari.js +40 -49
  48. package/testing/index.js +504 -0
  49. package/lib/README +0 -5
  50. package/lib/actions.js +0 -609
package/lib/promise.js CHANGED
@@ -20,9 +20,7 @@
20
20
  * with promises.
21
21
  */
22
22
 
23
- 'use strict';
24
-
25
-
23
+ 'use strict'
26
24
 
27
25
  /**
28
26
  * Determines whether a {@code value} should be treated as a promise.
@@ -32,18 +30,9 @@
32
30
  * @return {boolean} Whether the value is a promise.
33
31
  */
34
32
  function isPromise(value) {
35
- try {
36
- // Use array notation so the Closure compiler does not obfuscate away our
37
- // contract.
38
- return value
39
- && (typeof value === 'object' || typeof value === 'function')
40
- && typeof value['then'] === 'function';
41
- } catch (ex) {
42
- return false;
43
- }
33
+ return Object.prototype.toString.call(value) === '[object Promise]'
44
34
  }
45
35
 
46
-
47
36
  /**
48
37
  * Creates a promise that will be resolved at a set time in the future.
49
38
  * @param {number} ms The amount of time, in milliseconds, to wait before
@@ -51,12 +40,9 @@ function isPromise(value) {
51
40
  * @return {!Promise<void>} The promise.
52
41
  */
53
42
  function delayed(ms) {
54
- return new Promise(resolve => {
55
- setTimeout(() => resolve(), ms);
56
- });
43
+ return new Promise((resolve) => setTimeout(resolve, ms))
57
44
  }
58
45
 
59
-
60
46
  /**
61
47
  * Wraps a function that expects a node-style callback as its final
62
48
  * argument. This callback expects two arguments: an error value (which will be
@@ -70,15 +56,15 @@ function delayed(ms) {
70
56
  * result of the provided function's callback.
71
57
  */
72
58
  function checkedNodeCall(fn, ...args) {
73
- return new Promise(function(fulfill, reject) {
59
+ return new Promise(function (fulfill, reject) {
74
60
  try {
75
- fn(...args, function(error, value) {
76
- error ? reject(error) : fulfill(value);
77
- });
61
+ fn(...args, function (error, value) {
62
+ error ? reject(error) : fulfill(value)
63
+ })
78
64
  } catch (ex) {
79
- reject(ex);
65
+ reject(ex)
80
66
  }
81
- });
67
+ })
82
68
  }
83
69
 
84
70
  /**
@@ -120,15 +106,14 @@ function checkedNodeCall(fn, ...args) {
120
106
  */
121
107
  async function thenFinally(promise, callback) {
122
108
  try {
123
- await Promise.resolve(promise);
124
- return callback();
109
+ await Promise.resolve(promise)
110
+ return callback()
125
111
  } catch (e) {
126
- await callback();
127
- throw e;
112
+ await callback()
113
+ throw e
128
114
  }
129
115
  }
130
116
 
131
-
132
117
  /**
133
118
  * Calls a function for each element in an array and inserts the result into a
134
119
  * new array, which is used as the fulfillment value of the promise returned
@@ -151,24 +136,23 @@ async function thenFinally(promise, callback) {
151
136
  * @template TYPE, SELF
152
137
  */
153
138
  async function map(array, fn, self = undefined) {
154
- const v = await Promise.resolve(array);
139
+ const v = await Promise.resolve(array)
155
140
  if (!Array.isArray(v)) {
156
- throw TypeError('not an array');
141
+ throw TypeError('not an array')
157
142
  }
158
143
 
159
- const arr = /** @type {!Array} */(v);
160
- const n = arr.length;
161
- const values = new Array(n);
144
+ const arr = /** @type {!Array} */ (v)
145
+ const n = arr.length
146
+ const values = new Array(n)
162
147
 
163
148
  for (let i = 0; i < n; i++) {
164
149
  if (i in arr) {
165
- values[i] = await Promise.resolve(fn.call(self, arr[i], i, arr));
150
+ values[i] = await Promise.resolve(fn.call(self, arr[i], i, arr))
166
151
  }
167
152
  }
168
- return values;
153
+ return values
169
154
  }
170
155
 
171
-
172
156
  /**
173
157
  * Calls a function for each element in an array, and if the function returns
174
158
  * true adds the element to a new array.
@@ -191,29 +175,28 @@ async function map(array, fn, self = undefined) {
191
175
  * @template TYPE, SELF
192
176
  */
193
177
  async function filter(array, fn, self = undefined) {
194
- const v = await Promise.resolve(array);
178
+ const v = await Promise.resolve(array)
195
179
  if (!Array.isArray(v)) {
196
- throw TypeError('not an array');
180
+ throw TypeError('not an array')
197
181
  }
198
182
 
199
- const arr = /** @type {!Array} */(v);
200
- const n = arr.length;
201
- const values = [];
202
- let valuesLength = 0;
183
+ const arr = /** @type {!Array} */ (v)
184
+ const n = arr.length
185
+ const values = []
186
+ let valuesLength = 0
203
187
 
204
188
  for (let i = 0; i < n; i++) {
205
189
  if (i in arr) {
206
- let value = arr[i];
207
- let include = await fn.call(self, value, i, arr);
190
+ const value = arr[i]
191
+ const include = await fn.call(self, value, i, arr)
208
192
  if (include) {
209
- values[valuesLength++] = value;
193
+ values[valuesLength++] = value
210
194
  }
211
195
  }
212
196
  }
213
- return values;
197
+ return values
214
198
  }
215
199
 
216
-
217
200
  /**
218
201
  * Returns a promise that will be resolved with the input value in a
219
202
  * fully-resolved state. If the value is an array, each element will be fully
@@ -234,64 +217,63 @@ async function filter(array, fn, self = undefined) {
234
217
  * of the input value.
235
218
  */
236
219
  async function fullyResolved(value) {
237
- value = await Promise.resolve(value);
220
+ value = await Promise.resolve(value)
238
221
  if (Array.isArray(value)) {
239
- return fullyResolveKeys(/** @type {!Array} */ (value));
222
+ return fullyResolveKeys(/** @type {!Array} */ (value))
240
223
  }
241
224
 
242
225
  if (value && typeof value === 'object') {
243
- return fullyResolveKeys(/** @type {!Object} */ (value));
226
+ return fullyResolveKeys(/** @type {!Object} */ (value))
244
227
  }
245
228
 
246
229
  if (typeof value === 'function') {
247
- return fullyResolveKeys(/** @type {!Object} */ (value));
230
+ return fullyResolveKeys(/** @type {!Object} */ (value))
248
231
  }
249
232
 
250
- return value;
233
+ return value
251
234
  }
252
235
 
253
-
254
236
  /**
255
237
  * @param {!(Array|Object)} obj the object to resolve.
256
238
  * @return {!Thenable} A promise that will be resolved with the
257
239
  * input object once all of its values have been fully resolved.
258
240
  */
259
241
  async function fullyResolveKeys(obj) {
260
- const isArray = Array.isArray(obj);
261
- const numKeys = isArray ? obj.length : Object.keys(obj).length;
242
+ const isArray = Array.isArray(obj)
243
+ const numKeys = isArray ? obj.length : Object.keys(obj).length
262
244
 
263
245
  if (!numKeys) {
264
- return obj;
246
+ return obj
265
247
  }
266
248
 
267
249
  async function forEachProperty(obj, fn) {
268
250
  for (let key in obj) {
269
- await fn(obj[key], key);
251
+ await fn(obj[key], key)
270
252
  }
271
253
  }
272
254
 
273
255
  async function forEachElement(arr, fn) {
274
256
  for (let i = 0; i < arr.length; i++) {
275
- await fn(arr[i], i);
257
+ await fn(arr[i], i)
276
258
  }
277
259
  }
278
260
 
279
- const forEachKey = isArray ? forEachElement : forEachProperty;
280
- await forEachKey(obj, async function(partialValue, key) {
281
- if (!Array.isArray(partialValue)
282
- && (!partialValue || typeof partialValue !== 'object')) {
283
- return;
261
+ const forEachKey = isArray ? forEachElement : forEachProperty
262
+ await forEachKey(obj, async function (partialValue, key) {
263
+ if (
264
+ !Array.isArray(partialValue) &&
265
+ (!partialValue || typeof partialValue !== 'object')
266
+ ) {
267
+ return
284
268
  }
285
- let resolvedValue = await fullyResolved(partialValue);
286
- obj[key] = resolvedValue;
287
- });
288
- return obj;
269
+ let resolvedValue = await fullyResolved(partialValue)
270
+ obj[key] = resolvedValue
271
+ })
272
+ return obj
289
273
  }
290
274
 
291
-
292
275
  // PUBLIC API
293
276
 
294
-
295
277
  module.exports = {
296
278
  checkedNodeCall,
297
279
  delayed,
@@ -299,5 +281,5 @@ module.exports = {
299
281
  finally: thenFinally,
300
282
  fullyResolved,
301
283
  isPromise,
302
- map
303
- };
284
+ map,
285
+ }
package/lib/proxy.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * capabilities.setProxy(proxy.manual({http: 'host:1234'});
26
26
  */
27
27
 
28
- 'use strict';
28
+ 'use strict'
29
29
 
30
30
  /**
31
31
  * Supported {@linkplain Config proxy configuration} types.
@@ -38,8 +38,7 @@ const Type = {
38
38
  MANUAL: 'manual',
39
39
  PAC: 'pac',
40
40
  SYSTEM: 'system',
41
- };
42
-
41
+ }
43
42
 
44
43
  /**
45
44
  * Describes how a proxy should be configured for a WebDriver session.
@@ -51,8 +50,7 @@ function Config() {}
51
50
  * The proxy type.
52
51
  * @type {Type}
53
52
  */
54
- Config.prototype.proxyType;
55
-
53
+ Config.prototype.proxyType
56
54
 
57
55
  /**
58
56
  * Describes how to configure a PAC proxy.
@@ -66,8 +64,7 @@ function PacConfig() {}
66
64
  *
67
65
  * @type {string}
68
66
  */
69
- PacConfig.prototype.proxyAutoconfigUrl;
70
-
67
+ PacConfig.prototype.proxyAutoconfigUrl
71
68
 
72
69
  /**
73
70
  * Record object that defines a manual proxy configuration. Manual
@@ -85,61 +82,57 @@ function ManualConfig() {}
85
82
  *
86
83
  * @type {(string|undefined)}
87
84
  */
88
- ManualConfig.prototype.ftpProxy;
85
+ ManualConfig.prototype.ftpProxy
89
86
 
90
87
  /**
91
88
  * The proxy host for HTTP requests.
92
89
  *
93
90
  * @type {(string|undefined)}
94
91
  */
95
- ManualConfig.prototype.httpProxy;
92
+ ManualConfig.prototype.httpProxy
96
93
 
97
94
  /**
98
95
  * An array of hosts which should bypass all proxies.
99
96
  *
100
97
  * @type {(Array<string>|undefined)}
101
98
  */
102
- ManualConfig.prototype.noProxy;
99
+ ManualConfig.prototype.noProxy
103
100
 
104
101
  /**
105
102
  * The proxy host for HTTPS requests.
106
103
  *
107
104
  * @type {(string|undefined)}
108
105
  */
109
- ManualConfig.prototype.sslProxy;
106
+ ManualConfig.prototype.sslProxy
110
107
 
111
108
  /**
112
109
  * Defines the host and port for the SOCKS proxy to use.
113
110
  *
114
111
  * @type {(number|undefined)}
115
112
  */
116
- ManualConfig.prototype.socksProxy;
113
+ ManualConfig.prototype.socksProxy
117
114
 
118
115
  /**
119
116
  * Defines the SOCKS proxy version. Must be a number in the range [0, 255].
120
117
  *
121
118
  * @type {(number|undefined)}
122
119
  */
123
- ManualConfig.prototype.socksVersion;
124
-
120
+ ManualConfig.prototype.socksVersion
125
121
 
126
122
  // PUBLIC API
127
123
 
128
-
129
- /** @const */ exports.Config = Config;
130
- /** @const */ exports.ManualConfig = ManualConfig;
131
- /** @const */ exports.PacConfig = PacConfig;
132
- /** @const */ exports.Type = Type;
133
-
124
+ /** @const */ exports.Config = Config
125
+ /** @const */ exports.ManualConfig = ManualConfig
126
+ /** @const */ exports.PacConfig = PacConfig
127
+ /** @const */ exports.Type = Type
134
128
 
135
129
  /**
136
130
  * Configures WebDriver to bypass all browser proxies.
137
131
  * @return {!Config} A new proxy configuration object.
138
132
  */
139
- exports.direct = function() {
140
- return {proxyType: Type.DIRECT};
141
- };
142
-
133
+ exports.direct = function () {
134
+ return { proxyType: Type.DIRECT }
135
+ }
143
136
 
144
137
  /**
145
138
  * Manually configures the browser proxy. The following options are
@@ -162,16 +155,15 @@ exports.direct = function() {
162
155
  * configuration options.
163
156
  * @return {!ManualConfig} A new proxy configuration object.
164
157
  */
165
- exports.manual = function({ftp, http, https, bypass}) {
158
+ exports.manual = function ({ ftp, http, https, bypass }) {
166
159
  return {
167
160
  proxyType: Type.MANUAL,
168
161
  ftpProxy: ftp,
169
162
  httpProxy: http,
170
163
  sslProxy: https,
171
164
  noProxy: bypass,
172
- };
173
- };
174
-
165
+ }
166
+ }
175
167
 
176
168
  /**
177
169
  * Creates a proxy configuration for a socks proxy.
@@ -193,14 +185,13 @@ exports.manual = function({ftp, http, https, bypass}) {
193
185
  * @return {!ManualConfig} A new proxy configuration object.
194
186
  * @see https://en.wikipedia.org/wiki/SOCKS
195
187
  */
196
- exports.socks = function(socksProxy, socksVersion = undefined) {
197
- return /** @type {!Config} */({
188
+ exports.socks = function (socksProxy, socksVersion = undefined) {
189
+ return /** @type {!Config} */ ({
198
190
  proxyType: Type.MANUAL,
199
191
  socksProxy,
200
- socksVersion
201
- });
202
- };
203
-
192
+ socksVersion,
193
+ })
194
+ }
204
195
 
205
196
  /**
206
197
  * Configures WebDriver to configure the browser proxy using the PAC file at
@@ -208,15 +199,14 @@ exports.socks = function(socksProxy, socksVersion = undefined) {
208
199
  * @param {string} proxyAutoconfigUrl URL for the PAC proxy to use.
209
200
  * @return {!PacConfig} A new proxy configuration object.
210
201
  */
211
- exports.pac = function(proxyAutoconfigUrl) {
212
- return {proxyType: Type.PAC, proxyAutoconfigUrl};
213
- };
214
-
202
+ exports.pac = function (proxyAutoconfigUrl) {
203
+ return { proxyType: Type.PAC, proxyAutoconfigUrl }
204
+ }
215
205
 
216
206
  /**
217
207
  * Configures WebDriver to use the current system's proxy.
218
208
  * @return {!Config} A new proxy configuration object.
219
209
  */
220
- exports.system = function() {
221
- return {proxyType: Type.SYSTEM};
222
- };
210
+ exports.system = function () {
211
+ return { proxyType: Type.SYSTEM }
212
+ }
package/lib/session.js CHANGED
@@ -15,16 +15,14 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- 'use strict';
19
-
20
- const {Capabilities} = require('./capabilities');
18
+ 'use strict'
21
19
 
20
+ const { Capabilities } = require('./capabilities')
22
21
 
23
22
  /**
24
23
  * Contains information about a single WebDriver session.
25
24
  */
26
25
  class Session {
27
-
28
26
  /**
29
27
  * @param {string} id The session ID.
30
28
  * @param {!./capabilities.Capabilities} capabilities
@@ -32,26 +30,27 @@ class Session {
32
30
  */
33
31
  constructor(id, capabilities) {
34
32
  /** @private {string} */
35
- this.id_ = id;
33
+ this.id_ = id
36
34
 
37
35
  /** @private {!Capabilities} */
38
- this.caps_ = capabilities instanceof Capabilities
39
- ? /** @type {!Capabilities} */(capabilities)
40
- : new Capabilities(capabilities);
36
+ this.caps_ =
37
+ capabilities instanceof Capabilities
38
+ ? /** @type {!Capabilities} */ (capabilities)
39
+ : new Capabilities(capabilities)
41
40
  }
42
41
 
43
42
  /**
44
43
  * @return {string} This session's ID.
45
44
  */
46
45
  getId() {
47
- return this.id_;
46
+ return this.id_
48
47
  }
49
48
 
50
49
  /**
51
50
  * @return {!Capabilities} This session's capabilities.
52
51
  */
53
52
  getCapabilities() {
54
- return this.caps_;
53
+ return this.caps_
55
54
  }
56
55
 
57
56
  /**
@@ -60,7 +59,7 @@ class Session {
60
59
  * @return {*} The capability value.
61
60
  */
62
61
  getCapability(key) {
63
- return this.caps_.get(key);
62
+ return this.caps_.get(key)
64
63
  }
65
64
 
66
65
  /**
@@ -69,12 +68,10 @@ class Session {
69
68
  * @return {string} The JSON representation of this Session.
70
69
  */
71
70
  toJSON() {
72
- return this.getId();
71
+ return this.getId()
73
72
  }
74
73
  }
75
74
 
76
-
77
75
  // PUBLIC API
78
76
 
79
-
80
- module.exports = {Session: Session};
77
+ module.exports = { Session: Session }
package/lib/symbols.js CHANGED
@@ -15,14 +15,13 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- 'use strict';
18
+ 'use strict'
19
19
 
20
20
  /**
21
21
  * @fileoverview Defines well-known symbols used within the selenium-webdriver
22
22
  * library.
23
23
  */
24
24
 
25
-
26
25
  module.exports = {
27
26
  /**
28
27
  * The serialize symbol specifies a method that returns an object's serialized
@@ -34,5 +33,5 @@ module.exports = {
34
33
  * `toJSON()` method, except the serialized result may be a promise, or
35
34
  * another object with a promised property.
36
35
  */
37
- serialize: Symbol('serialize')
38
- };
36
+ serialize: Symbol('serialize'),
37
+ }