selenium-webdriver 4.0.0-alpha.5 → 4.0.0-beta.1

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 (49) hide show
  1. package/CHANGES.md +35 -1
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/README.md +4 -4
  5. package/chrome.js +72 -592
  6. package/chromium.js +829 -0
  7. package/devtools/CDPConnection.js +37 -0
  8. package/edge.js +124 -86
  9. package/example/chrome_android.js +16 -13
  10. package/example/chrome_mobile_emulation.js +18 -14
  11. package/example/firefox_channels.js +35 -28
  12. package/example/google_search.js +9 -9
  13. package/example/google_search_test.js +20 -22
  14. package/example/headless.js +27 -19
  15. package/example/logging.js +34 -38
  16. package/firefox.js +200 -200
  17. package/http/index.js +131 -115
  18. package/http/util.js +56 -64
  19. package/ie.js +180 -104
  20. package/index.js +246 -199
  21. package/io/exec.js +34 -39
  22. package/io/index.js +142 -152
  23. package/io/zip.js +75 -65
  24. package/lib/actions.js +140 -122
  25. package/lib/atoms/find-elements.js +124 -0
  26. package/lib/atoms/get-attribute.js +79 -59
  27. package/lib/atoms/is-displayed.js +72 -73
  28. package/lib/atoms/mutation-listener.js +38 -0
  29. package/lib/by.js +192 -65
  30. package/lib/capabilities.js +82 -78
  31. package/lib/command.js +20 -20
  32. package/lib/error.js +134 -168
  33. package/lib/http.js +337 -230
  34. package/lib/input.js +325 -302
  35. package/lib/logging.js +127 -138
  36. package/lib/promise.js +60 -66
  37. package/lib/proxy.js +31 -41
  38. package/lib/session.js +12 -15
  39. package/lib/symbols.js +3 -4
  40. package/lib/until.js +162 -160
  41. package/lib/webdriver.js +1024 -541
  42. package/net/index.js +30 -36
  43. package/net/portprober.js +31 -144
  44. package/opera.js +406 -0
  45. package/package.json +19 -12
  46. package/proxy.js +2 -2
  47. package/remote/index.js +190 -187
  48. package/safari.js +40 -49
  49. package/testing/index.js +166 -155
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.
@@ -35,15 +33,16 @@ function isPromise(value) {
35
33
  try {
36
34
  // Use array notation so the Closure compiler does not obfuscate away our
37
35
  // contract.
38
- return value
39
- && (typeof value === 'object' || typeof value === 'function')
40
- && typeof value['then'] === 'function';
36
+ return (
37
+ value &&
38
+ (typeof value === 'object' || typeof value === 'function') &&
39
+ typeof value['then'] === 'function'
40
+ )
41
41
  } catch (ex) {
42
- return false;
42
+ return false
43
43
  }
44
44
  }
45
45
 
46
-
47
46
  /**
48
47
  * Creates a promise that will be resolved at a set time in the future.
49
48
  * @param {number} ms The amount of time, in milliseconds, to wait before
@@ -51,12 +50,11 @@ function isPromise(value) {
51
50
  * @return {!Promise<void>} The promise.
52
51
  */
53
52
  function delayed(ms) {
54
- return new Promise(resolve => {
55
- setTimeout(() => resolve(), ms);
56
- });
53
+ return new Promise((resolve) => {
54
+ setTimeout(resolve, ms)
55
+ })
57
56
  }
58
57
 
59
-
60
58
  /**
61
59
  * Wraps a function that expects a node-style callback as its final
62
60
  * argument. This callback expects two arguments: an error value (which will be
@@ -70,15 +68,15 @@ function delayed(ms) {
70
68
  * result of the provided function's callback.
71
69
  */
72
70
  function checkedNodeCall(fn, ...args) {
73
- return new Promise(function(fulfill, reject) {
71
+ return new Promise(function (fulfill, reject) {
74
72
  try {
75
- fn(...args, function(error, value) {
76
- error ? reject(error) : fulfill(value);
77
- });
73
+ fn(...args, function (error, value) {
74
+ error ? reject(error) : fulfill(value)
75
+ })
78
76
  } catch (ex) {
79
- reject(ex);
77
+ reject(ex)
80
78
  }
81
- });
79
+ })
82
80
  }
83
81
 
84
82
  /**
@@ -120,15 +118,14 @@ function checkedNodeCall(fn, ...args) {
120
118
  */
121
119
  async function thenFinally(promise, callback) {
122
120
  try {
123
- await Promise.resolve(promise);
124
- return callback();
121
+ await Promise.resolve(promise)
122
+ return callback()
125
123
  } catch (e) {
126
- await callback();
127
- throw e;
124
+ await callback()
125
+ throw e
128
126
  }
129
127
  }
130
128
 
131
-
132
129
  /**
133
130
  * Calls a function for each element in an array and inserts the result into a
134
131
  * new array, which is used as the fulfillment value of the promise returned
@@ -151,24 +148,23 @@ async function thenFinally(promise, callback) {
151
148
  * @template TYPE, SELF
152
149
  */
153
150
  async function map(array, fn, self = undefined) {
154
- const v = await Promise.resolve(array);
151
+ const v = await Promise.resolve(array)
155
152
  if (!Array.isArray(v)) {
156
- throw TypeError('not an array');
153
+ throw TypeError('not an array')
157
154
  }
158
155
 
159
- const arr = /** @type {!Array} */(v);
160
- const n = arr.length;
161
- const values = new Array(n);
156
+ const arr = /** @type {!Array} */ (v)
157
+ const n = arr.length
158
+ const values = new Array(n)
162
159
 
163
160
  for (let i = 0; i < n; i++) {
164
161
  if (i in arr) {
165
- values[i] = await Promise.resolve(fn.call(self, arr[i], i, arr));
162
+ values[i] = await Promise.resolve(fn.call(self, arr[i], i, arr))
166
163
  }
167
164
  }
168
- return values;
165
+ return values
169
166
  }
170
167
 
171
-
172
168
  /**
173
169
  * Calls a function for each element in an array, and if the function returns
174
170
  * true adds the element to a new array.
@@ -191,29 +187,28 @@ async function map(array, fn, self = undefined) {
191
187
  * @template TYPE, SELF
192
188
  */
193
189
  async function filter(array, fn, self = undefined) {
194
- const v = await Promise.resolve(array);
190
+ const v = await Promise.resolve(array)
195
191
  if (!Array.isArray(v)) {
196
- throw TypeError('not an array');
192
+ throw TypeError('not an array')
197
193
  }
198
194
 
199
- const arr = /** @type {!Array} */(v);
200
- const n = arr.length;
201
- const values = [];
202
- let valuesLength = 0;
195
+ const arr = /** @type {!Array} */ (v)
196
+ const n = arr.length
197
+ const values = []
198
+ let valuesLength = 0
203
199
 
204
200
  for (let i = 0; i < n; i++) {
205
201
  if (i in arr) {
206
- let value = arr[i];
207
- let include = await fn.call(self, value, i, arr);
202
+ let value = arr[i]
203
+ let include = await fn.call(self, value, i, arr)
208
204
  if (include) {
209
- values[valuesLength++] = value;
205
+ values[valuesLength++] = value
210
206
  }
211
207
  }
212
208
  }
213
- return values;
209
+ return values
214
210
  }
215
211
 
216
-
217
212
  /**
218
213
  * Returns a promise that will be resolved with the input value in a
219
214
  * fully-resolved state. If the value is an array, each element will be fully
@@ -234,64 +229,63 @@ async function filter(array, fn, self = undefined) {
234
229
  * of the input value.
235
230
  */
236
231
  async function fullyResolved(value) {
237
- value = await Promise.resolve(value);
232
+ value = await Promise.resolve(value)
238
233
  if (Array.isArray(value)) {
239
- return fullyResolveKeys(/** @type {!Array} */ (value));
234
+ return fullyResolveKeys(/** @type {!Array} */ (value))
240
235
  }
241
236
 
242
237
  if (value && typeof value === 'object') {
243
- return fullyResolveKeys(/** @type {!Object} */ (value));
238
+ return fullyResolveKeys(/** @type {!Object} */ (value))
244
239
  }
245
240
 
246
241
  if (typeof value === 'function') {
247
- return fullyResolveKeys(/** @type {!Object} */ (value));
242
+ return fullyResolveKeys(/** @type {!Object} */ (value))
248
243
  }
249
244
 
250
- return value;
245
+ return value
251
246
  }
252
247
 
253
-
254
248
  /**
255
249
  * @param {!(Array|Object)} obj the object to resolve.
256
250
  * @return {!Thenable} A promise that will be resolved with the
257
251
  * input object once all of its values have been fully resolved.
258
252
  */
259
253
  async function fullyResolveKeys(obj) {
260
- const isArray = Array.isArray(obj);
261
- const numKeys = isArray ? obj.length : Object.keys(obj).length;
254
+ const isArray = Array.isArray(obj)
255
+ const numKeys = isArray ? obj.length : Object.keys(obj).length
262
256
 
263
257
  if (!numKeys) {
264
- return obj;
258
+ return obj
265
259
  }
266
260
 
267
261
  async function forEachProperty(obj, fn) {
268
262
  for (let key in obj) {
269
- await fn(obj[key], key);
263
+ await fn(obj[key], key)
270
264
  }
271
265
  }
272
266
 
273
267
  async function forEachElement(arr, fn) {
274
268
  for (let i = 0; i < arr.length; i++) {
275
- await fn(arr[i], i);
269
+ await fn(arr[i], i)
276
270
  }
277
271
  }
278
272
 
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;
273
+ const forEachKey = isArray ? forEachElement : forEachProperty
274
+ await forEachKey(obj, async function (partialValue, key) {
275
+ if (
276
+ !Array.isArray(partialValue) &&
277
+ (!partialValue || typeof partialValue !== 'object')
278
+ ) {
279
+ return
284
280
  }
285
- let resolvedValue = await fullyResolved(partialValue);
286
- obj[key] = resolvedValue;
287
- });
288
- return obj;
281
+ let resolvedValue = await fullyResolved(partialValue)
282
+ obj[key] = resolvedValue
283
+ })
284
+ return obj
289
285
  }
290
286
 
291
-
292
287
  // PUBLIC API
293
288
 
294
-
295
289
  module.exports = {
296
290
  checkedNodeCall,
297
291
  delayed,
@@ -299,5 +293,5 @@ module.exports = {
299
293
  finally: thenFinally,
300
294
  fullyResolved,
301
295
  isPromise,
302
- map
303
- };
296
+ map,
297
+ }
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
+ }