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

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 (79) hide show
  1. package/CHANGES.md +9 -2
  2. package/README.md +2 -4
  3. package/chrome.js +19 -527
  4. package/chromium.js +762 -0
  5. package/edge.js +97 -58
  6. package/firefox.js +23 -5
  7. package/http/index.js +4 -0
  8. package/io/index.js +1 -1
  9. package/lib/actions.js +1 -1
  10. package/lib/atoms/get-attribute.js +1 -2
  11. package/lib/atoms/is-displayed.js +5 -6
  12. package/lib/atoms/make-atoms-module.js +17 -0
  13. package/lib/capabilities.js +17 -4
  14. package/lib/command.js +1 -0
  15. package/lib/http.js +8 -3
  16. package/lib/input.js +6 -6
  17. package/lib/logging.js +1 -1
  18. package/lib/webdriver.js +33 -3
  19. package/net/portprober.js +1 -1
  20. package/package.json +8 -9
  21. package/BUILD.bazel +0 -88
  22. package/example/chrome_android.js +0 -42
  23. package/example/chrome_mobile_emulation.js +0 -42
  24. package/example/firefox_channels.js +0 -77
  25. package/example/google_search.js +0 -50
  26. package/example/google_search_test.js +0 -72
  27. package/example/headless.js +0 -55
  28. package/example/logging.js +0 -68
  29. package/jasmine.json +0 -11
  30. package/lib/atoms/BUILD.bazel +0 -28
  31. package/lib/test/bootstrap_jasmine.js +0 -28
  32. package/lib/test/build.js +0 -156
  33. package/lib/test/data/actions/click.html +0 -24
  34. package/lib/test/data/actions/drag.html +0 -77
  35. package/lib/test/data/actions/record_click.html +0 -21
  36. package/lib/test/data/chrome/download.html +0 -2
  37. package/lib/test/data/firefox/webextension.xpi +0 -0
  38. package/lib/test/fileserver.js +0 -337
  39. package/lib/test/httpserver.js +0 -120
  40. package/lib/test/index.js +0 -87
  41. package/lib/test/resources.js +0 -40
  42. package/test/actions_test.js +0 -206
  43. package/test/builder_test.js +0 -106
  44. package/test/chrome/devtools_test.js +0 -93
  45. package/test/chrome/options_test.js +0 -121
  46. package/test/chrome/service_test.js +0 -45
  47. package/test/cookie_test.js +0 -210
  48. package/test/element_finding_test.js +0 -431
  49. package/test/execute_script_test.js +0 -355
  50. package/test/fingerprint_test.js +0 -63
  51. package/test/firefox_test.js +0 -233
  52. package/test/frame_test.js +0 -45
  53. package/test/http/http_test.js +0 -229
  54. package/test/http/util_test.js +0 -178
  55. package/test/io/io_test.js +0 -364
  56. package/test/io/zip_test.js +0 -126
  57. package/test/lib/by_test.js +0 -160
  58. package/test/lib/capabilities_test.js +0 -129
  59. package/test/lib/error_test.js +0 -333
  60. package/test/lib/http_test.js +0 -576
  61. package/test/lib/input_test.js +0 -1379
  62. package/test/lib/logging_test.js +0 -272
  63. package/test/lib/promise_test.js +0 -674
  64. package/test/lib/testutil.js +0 -90
  65. package/test/lib/until_test.js +0 -478
  66. package/test/lib/webdriver_test.js +0 -1692
  67. package/test/logging_test.js +0 -160
  68. package/test/net/index_test.js +0 -60
  69. package/test/net/portprober_test.js +0 -128
  70. package/test/page_loading_test.js +0 -156
  71. package/test/proxy_test.js +0 -167
  72. package/test/rect_test.js +0 -51
  73. package/test/remote_test.js +0 -98
  74. package/test/safari_test.js +0 -44
  75. package/test/stale_element_test.js +0 -60
  76. package/test/upload_test.js +0 -78
  77. package/test/window_test.js +0 -168
  78. package/testing/index.js +0 -498
  79. package/tools/init_jasmine.js +0 -7
@@ -1,431 +0,0 @@
1
- // Licensed to the Software Freedom Conservancy (SFC) under one
2
- // or more contributor license agreements. See the NOTICE file
3
- // distributed with this work for additional information
4
- // regarding copyright ownership. The SFC licenses this file
5
- // to you under the Apache License, Version 2.0 (the
6
- // "License"); you may not use this file except in compliance
7
- // with the License. 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,
12
- // software distributed under the License is distributed on an
13
- // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- // KIND, either express or implied. See the License for the
15
- // specific language governing permissions and limitations
16
- // under the License.
17
-
18
- 'use strict';
19
-
20
- const assert = require('assert');
21
- const {fail} = require('assert');
22
-
23
- const promise = require('../lib/promise');
24
- const {Browser, By, error, until} = require('..');
25
- const {Pages, ignore, suite, whereIs} = require('../lib/test');
26
-
27
-
28
- suite(function(env) {
29
- const browsers = (...args) => env.browsers(...args);
30
-
31
- var driver;
32
-
33
- before(async function() {
34
- driver = await env.builder().build();
35
- });
36
-
37
- after(function() {
38
- return driver.quit();
39
- });
40
-
41
- describe('finding elements', function() {
42
- it('should work after loading multiple pages in a row', async function() {
43
- await driver.get(Pages.formPage);
44
- await driver.get(Pages.xhtmlTestPage);
45
- await driver.findElement(By.linkText('click me')).click();
46
- await driver.wait(until.titleIs('We Arrive Here'), 5000);
47
- });
48
-
49
- describe('By.id()', function() {
50
- it('should work', async function() {
51
- await driver.get(Pages.xhtmlTestPage);
52
- await driver.findElement(By.id('linkId')).click();
53
- await driver.wait(until.titleIs('We Arrive Here'), 5000);
54
- });
55
-
56
- it('should fail if ID not present on page', async function() {
57
- await driver.get(Pages.formPage);
58
- return driver.findElement(By.id('nonExistantButton')).
59
- then(fail, function(e) {
60
- assert.ok(e instanceof error.NoSuchElementError);
61
- });
62
- });
63
-
64
- it(
65
- 'should find multiple elements by ID even though that is ' +
66
- 'malformed HTML',
67
- async function() {
68
- await driver.get(Pages.nestedPage);
69
-
70
- let elements = await driver.findElements(By.id('2'));
71
- assert.equal(elements.length, 8);
72
- });
73
- });
74
-
75
- describe('By.linkText()', function() {
76
- it('should be able to click on link identified by text', async function() {
77
- await driver.get(Pages.xhtmlTestPage);
78
- await driver.findElement(By.linkText('click me')).click();
79
- await driver.wait(until.titleIs('We Arrive Here'), 5000);
80
- });
81
-
82
- it(
83
- 'should be able to find elements by partial link text',
84
- async function() {
85
- await driver.get(Pages.xhtmlTestPage);
86
- await driver.findElement(By.partialLinkText('ick me')).click();
87
- await driver.wait(until.titleIs('We Arrive Here'), 5000);
88
- });
89
-
90
- it('should work when link text contains equals sign', async function() {
91
- await driver.get(Pages.xhtmlTestPage);
92
- let el = await driver.findElement(By.linkText('Link=equalssign'));
93
-
94
- let id = await el.getAttribute('id');
95
- assert.equal(id, 'linkWithEqualsSign');
96
- });
97
-
98
- it('matches by partial text when containing equals sign',
99
- async function() {
100
- await driver.get(Pages.xhtmlTestPage);
101
- let link = await driver.findElement(By.partialLinkText('Link='));
102
-
103
- let id = await link.getAttribute('id');
104
- assert.equal(id, 'linkWithEqualsSign');
105
- });
106
-
107
- it('works when searching for multiple and text contains =',
108
- async function() {
109
- await driver.get(Pages.xhtmlTestPage);
110
- let elements =
111
- await driver.findElements(By.linkText('Link=equalssign'));
112
-
113
- assert.equal(elements.length, 1);
114
-
115
- let id = await elements[0].getAttribute('id');
116
- assert.equal(id, 'linkWithEqualsSign');
117
- });
118
-
119
- it(
120
- 'works when searching for multiple with partial text containing =',
121
- async function() {
122
- await driver.get(Pages.xhtmlTestPage);
123
- let elements =
124
- await driver.findElements(By.partialLinkText('Link='));
125
-
126
- assert.equal(elements.length, 1);
127
-
128
- let id = await elements[0].getAttribute('id');
129
- assert.equal(id, 'linkWithEqualsSign');
130
- });
131
-
132
- it('should be able to find multiple exact matches',
133
- async function() {
134
- await driver.get(Pages.xhtmlTestPage);
135
- let elements = await driver.findElements(By.linkText('click me'));
136
- assert.equal(elements.length, 2);
137
- });
138
-
139
- it('should be able to find multiple partial matches',
140
- async function() {
141
- await driver.get(Pages.xhtmlTestPage);
142
- let elements =
143
- await driver.findElements(By.partialLinkText('ick me'));
144
- assert.equal(elements.length, 2);
145
- });
146
-
147
- ignore(browsers(Browser.SAFARI)).
148
- it('works on XHTML pages', async function() {
149
- await driver.get(whereIs('actualXhtmlPage.xhtml'));
150
-
151
- let el = await driver.findElement(By.linkText('Foo'));
152
- assert.equal(await el.getText(), 'Foo');
153
- });
154
- });
155
-
156
- describe('By.name()', function() {
157
- it('should work', async function() {
158
- await driver.get(Pages.formPage);
159
-
160
- let el = await driver.findElement(By.name('checky'));
161
- assert.equal(await el.getAttribute('value'), 'furrfu');
162
- });
163
-
164
- it('should find multiple elements with same name', async function() {
165
- await driver.get(Pages.nestedPage);
166
-
167
- let elements = await driver.findElements(By.name('checky'));
168
- assert.ok(elements.length > 1);
169
- });
170
-
171
- it(
172
- 'should be able to find elements that do not support name property',
173
- async function() {
174
- await driver.get(Pages.nestedPage);
175
- await driver.findElement(By.name('div1'));
176
- // Pass if this does not return an error.
177
- });
178
-
179
- it('shoudl be able to find hidden elements by name', async function() {
180
- await driver.get(Pages.formPage);
181
- await driver.findElement(By.name('hidden'));
182
- // Pass if this does not return an error.
183
- });
184
- });
185
-
186
- describe('By.className()', function() {
187
- it('should work', async function() {
188
- await driver.get(Pages.xhtmlTestPage);
189
-
190
- let el = await driver.findElement(By.className('extraDiv'));
191
- let text = await el.getText();
192
- assert.ok(
193
- text.startsWith('Another div starts here.'),
194
- `Unexpected text: "${text}"`);
195
- });
196
-
197
- it('should work when name is first name among many', async function() {
198
- await driver.get(Pages.xhtmlTestPage);
199
-
200
- let el = await driver.findElement(By.className('nameA'));
201
- assert.equal(await el.getText(), 'An H2 title');
202
- });
203
-
204
- it('should work when name is last name among many', async function() {
205
- await driver.get(Pages.xhtmlTestPage);
206
-
207
- let el = await driver.findElement(By.className('nameC'));
208
- assert.equal(await el.getText(), 'An H2 title');
209
- });
210
-
211
- it('should work when name is middle of many', async function() {
212
- await driver.get(Pages.xhtmlTestPage);
213
-
214
- let el = await driver.findElement(By.className('nameBnoise'));
215
- assert.equal(await el.getText(), 'An H2 title');
216
- });
217
-
218
- it('should work when name surrounded by whitespace', async function() {
219
- await driver.get(Pages.xhtmlTestPage);
220
-
221
- let el = await driver.findElement(By.className('spaceAround'));
222
- assert.equal(await el.getText(), 'Spaced out');
223
- });
224
-
225
- it('should fail if queried name only partially matches', async function() {
226
- await driver.get(Pages.xhtmlTestPage);
227
- return driver.findElement(By.className('nameB')).
228
- then(fail, function(e) {
229
- assert.ok(e instanceof error.NoSuchElementError);
230
- });
231
- });
232
-
233
- it('should implicitly wait', async function() {
234
- const TIMEOUT_IN_MS = 1000;
235
- const EPSILON = TIMEOUT_IN_MS / 2;
236
-
237
- await driver.manage().setTimeouts({implicit: TIMEOUT_IN_MS});
238
- await driver.get(Pages.formPage);
239
-
240
- var start = new Date();
241
- return driver.findElement(By.id('nonExistantButton')).
242
- then(fail, function(e) {
243
- var end = new Date();
244
- assert.ok(e instanceof error.NoSuchElementError);
245
-
246
- let elapsed = end - start;
247
- let diff = Math.abs(elapsed - TIMEOUT_IN_MS);
248
- assert.ok(
249
- diff < EPSILON,
250
- `Expected ${TIMEOUT_IN_MS} \u00b1 ${EPSILON} but got ${elapsed}`);
251
- });
252
- });
253
-
254
- it('should be able to find multiple matches', async function() {
255
- await driver.get(Pages.xhtmlTestPage);
256
-
257
- let elements = await driver.findElements(By.className('nameC'));
258
- assert.ok(elements.length > 1);
259
- });
260
-
261
- it('permits compound class names', function() {
262
- return driver.get(Pages.xhtmlTestPage)
263
- .then(() => driver.findElement(By.className('nameA nameC')))
264
- .then(el => el.getText())
265
- .then(text => assert.equal(text, 'An H2 title'));
266
- });
267
- });
268
-
269
- describe('By.xpath()', function() {
270
- it('should work with multiple matches', async function() {
271
- await driver.get(Pages.xhtmlTestPage);
272
- let elements = await driver.findElements(By.xpath('//div'));
273
- assert.ok(elements.length > 1);
274
- });
275
-
276
- it('should work for selectors using contains keyword', async function() {
277
- await driver.get(Pages.nestedPage);
278
- await driver.findElement(By.xpath('//a[contains(., "hello world")]'));
279
- // Pass if no error.
280
- });
281
- });
282
-
283
- describe('By.tagName()', function() {
284
- it('works', async function() {
285
- await driver.get(Pages.formPage);
286
-
287
- let el = await driver.findElement(By.tagName('input'));
288
- assert.equal((await el.getTagName()).toLowerCase(), 'input');
289
- });
290
-
291
- it('can find multiple elements', async function() {
292
- await driver.get(Pages.formPage);
293
-
294
- let elements = await driver.findElements(By.tagName('input'));
295
- assert.ok(elements.length > 1);
296
- });
297
- });
298
-
299
- describe('By.css()', function() {
300
- it('works', async function() {
301
- await driver.get(Pages.xhtmlTestPage);
302
- await driver.findElement(By.css('div.content'));
303
- // Pass if no error.
304
- });
305
-
306
- it('can find multiple elements', async function() {
307
- await driver.get(Pages.xhtmlTestPage);
308
-
309
- let elements = await driver.findElements(By.css('p'));
310
- assert.ok(elements.length > 1);
311
- // Pass if no error.
312
- });
313
-
314
- it(
315
- 'should find first matching element when searching by ' +
316
- 'compound CSS selector',
317
- async function() {
318
- await driver.get(Pages.xhtmlTestPage);
319
-
320
- let el =
321
- await driver.findElement(By.css('div.extraDiv, div.content'));
322
- assert.equal(await el.getAttribute('class'), 'content');
323
- });
324
-
325
- it('should be able to find multiple elements by compound selector',
326
- async function() {
327
- await driver.get(Pages.xhtmlTestPage);
328
- let elements =
329
- await driver.findElements(By.css('div.extraDiv, div.content'));
330
-
331
- return Promise.all([
332
- assertClassIs(elements[0], 'content'),
333
- assertClassIs(elements[1], 'extraDiv')
334
- ]);
335
-
336
- async function assertClassIs(el, expected) {
337
- let clazz = await el.getAttribute('class');
338
- assert.equal(clazz, expected);
339
- }
340
- });
341
-
342
- // IE only supports short version option[selected].
343
- ignore(browsers(Browser.IE)).
344
- it('should be able to find element by boolean attribute', async function() {
345
- await driver.get(whereIs(
346
- 'locators_tests/boolean_attribute_selected.html'));
347
-
348
- let el = await driver.findElement(By.css('option[selected="selected"]'));
349
- assert.equal(await el.getAttribute('value'), 'two');
350
- });
351
-
352
- it(
353
- 'should be able to find element with short ' +
354
- 'boolean attribute selector',
355
- async function() {
356
- await driver.get(whereIs(
357
- 'locators_tests/boolean_attribute_selected.html'));
358
-
359
- let el = await driver.findElement(By.css('option[selected]'));
360
- assert.equal(await el.getAttribute('value'), 'two');
361
- });
362
-
363
- it(
364
- 'should be able to find element with short boolean attribute ' +
365
- 'selector on HTML4 page',
366
- async function() {
367
- await driver.get(whereIs(
368
- 'locators_tests/boolean_attribute_selected_html4.html'));
369
-
370
- let el = await driver.findElement(By.css('option[selected]'));
371
- assert.equal(await el.getAttribute('value'), 'two');
372
- });
373
- });
374
-
375
- describe('by custom locator', function() {
376
- it('handles single element result', async function() {
377
- await driver.get(Pages.javascriptPage);
378
-
379
- let link = await driver.findElement(function(driver) {
380
- let links = driver.findElements(By.tagName('a'));
381
- return promise.filter(links, function(link) {
382
- return link.getAttribute('id').then(id => id === 'updatediv');
383
- }).then(links => links[0]);
384
- });
385
-
386
- let text = await link.getText();
387
- let regex = /Update\s+a\s+div/;
388
- assert.ok(regex.test(text), `"${text}" does not match ${regex}`);
389
- });
390
-
391
- it('uses first element if locator resolves to list', async function() {
392
- await driver.get(Pages.javascriptPage);
393
-
394
- let link = await driver.findElement(function() {
395
- return driver.findElements(By.tagName('a'));
396
- });
397
-
398
- assert.equal(await link.getText(), 'Change the page title!');
399
- });
400
-
401
- it('fails if locator returns non-webelement value', async function() {
402
- await driver.get(Pages.javascriptPage);
403
-
404
- let link = driver.findElement(function() {
405
- return driver.getTitle();
406
- });
407
-
408
- return link.then(
409
- () => fail('Should have failed'),
410
- (e) => assert.ok(e instanceof TypeError));
411
- });
412
- });
413
-
414
- describe('switchTo().activeElement()', function() {
415
- // SAFARI's new session response does not identify it as a W3C browser,
416
- // so the command is sent in the unsupported wire protocol format.
417
- ignore(browsers(Browser.SAFARI)).
418
- it('returns document.activeElement', async function() {
419
- await driver.get(Pages.formPage);
420
-
421
- let email = await driver.findElement(By.css('#email'));
422
- await driver.executeScript('arguments[0].focus()', email);
423
-
424
- let ae = await driver.switchTo().activeElement();
425
- let equal = await driver.executeScript(
426
- 'return arguments[0] === arguments[1]', email, ae);
427
- assert.ok(equal);
428
- });
429
- });
430
- });
431
- });