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