selenium-webdriver 3.0.0-beta-1 → 3.0.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 (77) hide show
  1. package/CHANGES.md +109 -0
  2. package/LICENSE +1 -1
  3. package/README.md +7 -6
  4. package/chrome.js +31 -128
  5. package/edge.js +13 -91
  6. package/example/chrome_android.js +18 -13
  7. package/example/chrome_mobile_emulation.js +19 -15
  8. package/example/google_search.js +11 -11
  9. package/example/google_search_generator.js +23 -18
  10. package/example/google_search_test.js +31 -17
  11. package/example/logging.js +9 -17
  12. package/example/parallel_flows.js +3 -0
  13. package/firefox/binary.js +17 -0
  14. package/firefox/index.js +198 -101
  15. package/firefox/profile.js +24 -3
  16. package/http/util.js +95 -59
  17. package/ie.js +6 -10
  18. package/index.js +636 -2
  19. package/lib/actions.js +18 -10
  20. package/lib/atoms/getAttribute.js +11 -0
  21. package/lib/atoms/isDisplayed.js +106 -0
  22. package/lib/firefox/amd64/libnoblur64.so +0 -0
  23. package/lib/firefox/i386/libnoblur.so +0 -0
  24. package/lib/firefox/webdriver.xpi +0 -0
  25. package/lib/http.js +159 -46
  26. package/lib/logging.js +7 -1
  27. package/lib/promise.js +602 -358
  28. package/lib/proxy.js +28 -0
  29. package/lib/session.js +1 -1
  30. package/lib/test/build.js +26 -28
  31. package/lib/test/data/formPage.html +1 -0
  32. package/lib/test/fileserver.js +12 -10
  33. package/lib/test/httpserver.js +4 -6
  34. package/lib/test/index.js +18 -11
  35. package/lib/test/promise.js +79 -0
  36. package/lib/webdriver.js +587 -479
  37. package/opera.js +12 -88
  38. package/package.json +13 -14
  39. package/phantomjs.js +7 -14
  40. package/remote/index.js +201 -30
  41. package/safari.js +62 -416
  42. package/test/actions_test.js +9 -11
  43. package/test/chrome/options_test.js +8 -8
  44. package/test/chrome/service_test.js +2 -2
  45. package/test/cookie_test.js +57 -57
  46. package/test/element_finding_test.js +201 -185
  47. package/test/execute_script_test.js +108 -111
  48. package/test/fingerprint_test.js +16 -11
  49. package/test/firefox/firefox_test.js +75 -49
  50. package/test/firefox/profile_test.js +1 -3
  51. package/test/http/util_test.js +21 -27
  52. package/test/io_test.js +2 -5
  53. package/test/lib/http_test.js +8 -6
  54. package/test/lib/promise_aplus_test.js +48 -44
  55. package/test/lib/promise_error_test.js +687 -611
  56. package/test/lib/promise_flow_test.js +1810 -1806
  57. package/test/lib/promise_generator_test.js +227 -225
  58. package/test/lib/promise_test.js +864 -835
  59. package/test/lib/until_test.js +1 -1
  60. package/test/lib/webdriver_test.js +520 -424
  61. package/test/logging_test.js +43 -45
  62. package/test/net/portprober_test.js +23 -24
  63. package/test/page_loading_test.js +84 -78
  64. package/test/phantomjs/execute_phantomjs_test.js +11 -25
  65. package/test/proxy_test.js +23 -23
  66. package/test/remote_test.js +22 -22
  67. package/test/safari_test.js +108 -0
  68. package/test/session_test.js +11 -10
  69. package/test/stale_element_test.js +18 -16
  70. package/test/tag_name_test.js +7 -5
  71. package/test/testing/assert_test.js +2 -3
  72. package/test/testing/index_test.js +163 -117
  73. package/test/upload_test.js +13 -13
  74. package/test/window_test.js +94 -70
  75. package/testing/index.js +176 -37
  76. package/builder.js +0 -553
  77. package/lib/safari/client.js +0 -56
@@ -26,6 +26,8 @@ var promise = require('../').promise,
26
26
  cmd = require('../lib/command'),
27
27
  remote = require('../remote');
28
28
 
29
+ const {enablePromiseManager} = require('../lib/test/promise');
30
+
29
31
  describe('DriverService', function() {
30
32
  describe('start()', function() {
31
33
  var service;
@@ -41,36 +43,34 @@ describe('DriverService', function() {
41
43
  return service.kill();
42
44
  });
43
45
 
44
- it('fails if child-process dies', function(done) {
46
+ it('fails if child-process dies', function() {
45
47
  this.timeout(1000);
46
- service.start(500)
47
- .then(expectFailure.bind(null, done), verifyFailure.bind(null, done));
48
+ return service.start(500).then(expectFailure, verifyFailure);
48
49
  });
49
50
 
50
- it('failures propagate through control flow if child-process dies',
51
- function(done) {
52
- this.timeout(1000);
51
+ enablePromiseManager(function() {
52
+ describe(
53
+ 'failures propagate through control flow if child-process dies',
54
+ function() {
55
+ it('', function() {
56
+ this.timeout(1000);
53
57
 
54
- promise.controlFlow().execute(function() {
55
- promise.controlFlow().execute(function() {
56
- return service.start(500);
58
+ return promise.controlFlow().execute(function() {
59
+ promise.controlFlow().execute(function() {
60
+ return service.start(500);
61
+ });
62
+ }).then(expectFailure, verifyFailure);
63
+ });
57
64
  });
58
- })
59
- .then(expectFailure.bind(null, done), verifyFailure.bind(null, done));
60
- });
65
+ });
61
66
 
62
- function verifyFailure(done, e) {
63
- try {
64
- assert.ok(!(e instanceof promise.CancellationError));
65
- assert.equal('Server terminated early with status 1', e.message);
66
- done();
67
- } catch (ex) {
68
- done(ex);
69
- }
67
+ function verifyFailure(e) {
68
+ assert.ok(!(e instanceof promise.CancellationError));
69
+ assert.equal('Server terminated early with status 1', e.message);
70
70
  }
71
71
 
72
- function expectFailure(done) {
73
- done(Error('expected to fail'));
72
+ function expectFailure() {
73
+ throw Error('expected to fail');
74
74
  }
75
75
  });
76
76
  });
@@ -0,0 +1,108 @@
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 webdriver = require('..'),
21
+ proxy = require('../proxy'),
22
+ safari = require('../safari'),
23
+ assert = require('../testing/assert'),
24
+ test = require('../lib/test');
25
+
26
+
27
+ describe('safari.Options', function() {
28
+ describe('fromCapabilities', function() {
29
+ it('returns a new Options instance if none were defined', function() {
30
+ let options = safari.Options.fromCapabilities(
31
+ new webdriver.Capabilities());
32
+ assert(options).instanceOf(safari.Options);
33
+ });
34
+
35
+ it('returns the options instance if present', function() {
36
+ let options = new safari.Options().setCleanSession(true),
37
+ caps = options.toCapabilities();
38
+ assert(safari.Options.fromCapabilities(caps)).equalTo(options);
39
+ });
40
+
41
+ it('extracts supported WebDriver capabilities', function() {
42
+ let proxyPrefs = proxy.direct(),
43
+ logPrefs = {},
44
+ caps = webdriver.Capabilities.chrome()
45
+ .set(webdriver.Capability.PROXY, proxyPrefs)
46
+ .set(webdriver.Capability.LOGGING_PREFS, logPrefs);
47
+
48
+ let options = safari.Options.fromCapabilities(caps);
49
+ assert(options.proxy_).equalTo(proxyPrefs);
50
+ assert(options.logPrefs_).equalTo(logPrefs);
51
+ });
52
+ });
53
+
54
+ describe('toCapabilities', function() {
55
+ let options;
56
+
57
+ before(function() {
58
+ options = new safari.Options()
59
+ .setCleanSession(true);
60
+ });
61
+
62
+ it('returns a new capabilities object if one is not provided', function() {
63
+ let caps = options.toCapabilities();
64
+ assert(caps).instanceOf(webdriver.Capabilities);
65
+ assert(caps.get('browserName')).equalTo('safari');
66
+ assert(caps.get('safari.options')).equalTo(options);
67
+ });
68
+
69
+ it('adds to input capabilities object', function() {
70
+ let caps = webdriver.Capabilities.safari();
71
+ assert(options.toCapabilities(caps)).equalTo(caps);
72
+ assert(caps.get('safari.options')).equalTo(options);
73
+ });
74
+
75
+ it('sets generic driver capabilities', function() {
76
+ let proxyPrefs = proxy.direct(),
77
+ loggingPrefs = {};
78
+
79
+ options
80
+ .setLoggingPrefs(loggingPrefs)
81
+ .setProxy(proxyPrefs);
82
+
83
+ let caps = options.toCapabilities();
84
+ assert(caps.get('proxy')).equalTo(proxyPrefs);
85
+ assert(caps.get('loggingPrefs')).equalTo(loggingPrefs);
86
+ });
87
+ });
88
+ });
89
+
90
+ test.suite(function(env) {
91
+ describe('safaridriver', function() {
92
+ let service;
93
+
94
+ afterEach(function() {
95
+ if (service) {
96
+ return service.kill();
97
+ }
98
+ });
99
+
100
+ it('can start safaridriver', function() {
101
+ service = new safari.ServiceBuilder().build();
102
+
103
+ return service.start().then(function(url) {
104
+ assert(url).matches(/127\.0\.0\.1/);
105
+ });
106
+ });
107
+ });
108
+ }, {browsers: ['safari']});
@@ -27,27 +27,28 @@ test.suite(function(env) {
27
27
  var browsers = env.browsers;
28
28
 
29
29
  var driver;
30
- test.before(function() {
31
- driver = env.builder().build();
30
+ test.before(function*() {
31
+ driver = yield env.builder().build();
32
32
  });
33
33
 
34
34
  test.after(function() {
35
- driver.quit();
35
+ return driver.quit();
36
36
  });
37
37
 
38
- test.it('can connect to an existing session', function() {
39
- driver.get(Pages.simpleTestPage);
40
- assert(driver.getTitle()).equalTo('Hello WebDriver');
38
+ test.it('can connect to an existing session', function*() {
39
+ yield driver.get(Pages.simpleTestPage);
40
+ yield assert(driver.getTitle()).equalTo('Hello WebDriver');
41
41
 
42
42
  return driver.getSession().then(session1 => {
43
43
  let driver2 = WebDriver.attachToSession(
44
44
  driver.getExecutor(),
45
45
  session1.getId());
46
46
 
47
- assert(driver2.getTitle()).equalTo('Hello WebDriver');
48
-
49
- let session2Id = driver2.getSession().then(s => s.getId());
50
- assert(session2Id).equalTo(session1.getId());
47
+ return assert(driver2.getTitle()).equalTo('Hello WebDriver')
48
+ .then(_ => {
49
+ let session2Id = driver2.getSession().then(s => s.getId());
50
+ return assert(session2Id).equalTo(session1.getId());
51
+ });
51
52
  });
52
53
  });
53
54
  });
@@ -30,31 +30,33 @@ var Browser = require('..').Browser,
30
30
 
31
31
  test.suite(function(env) {
32
32
  var driver;
33
- test.before(function() { driver = env.builder().build(); });
34
- test.after(function() { driver.quit(); });
33
+ test.before(function*() { driver = yield env.builder().build(); });
34
+ test.after(function() { return driver.quit(); });
35
35
 
36
- test.it(
36
+ // Element never goes stale in Safari.
37
+ test.ignore(env.browsers(Browser.SAFARI)).
38
+ it(
37
39
  'dynamically removing elements from the DOM trigger a ' +
38
40
  'StaleElementReferenceError',
39
- function() {
40
- driver.get(Pages.javascriptPage);
41
+ function*() {
42
+ yield driver.get(Pages.javascriptPage);
41
43
 
42
- var toBeDeleted = driver.findElement(By.id('deleted'));
43
- assert(toBeDeleted.isDisplayed()).isTrue();
44
+ var toBeDeleted = yield driver.findElement(By.id('deleted'));
45
+ yield assert(toBeDeleted.getTagName()).isEqualTo('p');
44
46
 
45
- driver.findElement(By.id('delete')).click();
46
- driver.wait(until.stalenessOf(toBeDeleted), 5000);
47
+ yield driver.findElement(By.id('delete')).click();
48
+ yield driver.wait(until.stalenessOf(toBeDeleted), 5000);
47
49
  });
48
50
 
49
- test.it('an element found in a different frame is stale', function() {
50
- driver.get(Pages.missedJsReferencePage);
51
+ test.it('an element found in a different frame is stale', function*() {
52
+ yield driver.get(Pages.missedJsReferencePage);
51
53
 
52
- var frame = driver.findElement(By.css('iframe[name="inner"]'));
53
- driver.switchTo().frame(frame);
54
+ var frame = yield driver.findElement(By.css('iframe[name="inner"]'));
55
+ yield driver.switchTo().frame(frame);
54
56
 
55
- var el = driver.findElement(By.id('oneline'));
56
- driver.switchTo().defaultContent();
57
- el.getText().then(fail, function(e) {
57
+ var el = yield driver.findElement(By.id('oneline'));
58
+ yield driver.switchTo().defaultContent();
59
+ return el.getText().then(fail, function(e) {
58
60
  assert(e).instanceOf(error.StaleElementReferenceError);
59
61
  });
60
62
  });
@@ -24,11 +24,13 @@ var By = require('..').By,
24
24
 
25
25
  test.suite(function(env) {
26
26
  var driver;
27
- test.after(function() { driver.quit(); });
27
+ test.after(function() { return driver.quit(); });
28
28
 
29
- test.it('should return lower case tag name', function() {
30
- driver = env.builder().build();
31
- driver.get(test.Pages.formPage);
32
- assert(driver.findElement(By.id('cheese')).getTagName()).equalTo('input');
29
+ test.it('should return lower case tag name', function*() {
30
+ driver = yield env.builder().build();
31
+ yield driver.get(test.Pages.formPage);
32
+
33
+ let el = yield driver.findElement(By.id('cheese'));
34
+ return assert(el.getTagName()).equalTo('input');
33
35
  });
34
36
  });
@@ -178,9 +178,8 @@ describe('assert', function() {
178
178
  });
179
179
 
180
180
  it('waits for promised values', function() {
181
- let d = Promise.defer();
182
- setTimeout(() => d.resolve(123), 10);
183
- return assert(d.promise).closeTo(124, 1);
181
+ let p = new Promise(resolve => setTimeout(() => resolve(123), 10));
182
+ return assert(p).closeTo(124, 1);
184
183
  });
185
184
  });
186
185
 
@@ -17,8 +17,10 @@
17
17
 
18
18
  'use strict';
19
19
 
20
- var assert = require('assert');
21
- var promise = require('../..').promise;
20
+ const assert = require('assert');
21
+ const promise = require('../..').promise;
22
+ const {enablePromiseManager} = require('../../lib/test/promise');
23
+
22
24
 
23
25
  var test = require('../../testing');
24
26
 
@@ -42,137 +44,181 @@ describe('Mocha Integration', function() {
42
44
  afterEach(function() { assert.equal(this.x, 2); });
43
45
  });
44
46
 
45
- describe('timeout handling', function() {
46
- describe('it does not reset the control flow on a non-timeout', function() {
47
- var flowReset = false;
47
+ enablePromiseManager(function() {
48
+ describe('timeout handling', function() {
49
+ describe('it does not reset the control flow on a non-timeout', function() {
50
+ var flowReset = false;
48
51
 
49
- beforeEach(function() {
50
- flowReset = false;
51
- test.controlFlow().once(promise.ControlFlow.EventType.RESET, onreset);
52
- });
52
+ beforeEach(function() {
53
+ flowReset = false;
54
+ test.controlFlow().once(promise.ControlFlow.EventType.RESET, onreset);
55
+ });
53
56
 
54
- test.it('', function() {
55
- this.timeout(100);
56
- return promise.delayed(50);
57
- });
57
+ test.it('', function() {
58
+ this.timeout(100);
59
+ return promise.delayed(50);
60
+ });
58
61
 
59
- afterEach(function() {
60
- assert.ok(!flowReset);
61
- test.controlFlow().removeListener(
62
- promise.ControlFlow.EventType.RESET, onreset);
63
- });
62
+ afterEach(function() {
63
+ assert.ok(!flowReset);
64
+ test.controlFlow().removeListener(
65
+ promise.ControlFlow.EventType.RESET, onreset);
66
+ });
64
67
 
65
- function onreset() {
66
- flowReset = true;
67
- }
68
- });
68
+ function onreset() {
69
+ flowReset = true;
70
+ }
71
+ });
69
72
 
70
- describe('it resets the control flow after a timeout' ,function() {
71
- var timeoutErr, flowReset;
73
+ describe('it resets the control flow after a timeout' ,function() {
74
+ var timeoutErr, flowReset;
72
75
 
73
- beforeEach(function() {
74
- flowReset = false;
75
- test.controlFlow().once(promise.ControlFlow.EventType.RESET, onreset);
76
- });
76
+ beforeEach(function() {
77
+ flowReset = false;
78
+ test.controlFlow().once(promise.ControlFlow.EventType.RESET, onreset);
79
+ });
77
80
 
78
- test.it('', function() {
79
- var callback = this.runnable().callback;
80
- var test = this;
81
- this.runnable().callback = function(err) {
82
- timeoutErr = err;
83
- // Reset our timeout to 0 so Mocha does not fail the test.
84
- test.timeout(0);
85
- // When we invoke the real callback, do not pass along the error so
86
- // Mocha does not fail the test.
87
- return callback.call(this);
88
- };
89
-
90
- test.timeout(50);
91
- return promise.defer().promise;
92
- });
81
+ test.it('', function() {
82
+ var callback = this.runnable().callback;
83
+ var test = this;
84
+ this.runnable().callback = function(err) {
85
+ timeoutErr = err;
86
+ // Reset our timeout to 0 so Mocha does not fail the test.
87
+ test.timeout(0);
88
+ // When we invoke the real callback, do not pass along the error so
89
+ // Mocha does not fail the test.
90
+ return callback.call(this);
91
+ };
92
+
93
+ test.timeout(50);
94
+ return promise.defer().promise;
95
+ });
93
96
 
94
- afterEach(function() {
95
- return Promise.resolve().then(function() {
96
- test.controlFlow().removeListener(
97
- promise.ControlFlow.EventType.RESET, onreset);
98
- assert.ok(flowReset, 'control flow was not reset after a timeout');
97
+ afterEach(function() {
98
+ return Promise.resolve().then(function() {
99
+ test.controlFlow().removeListener(
100
+ promise.ControlFlow.EventType.RESET, onreset);
101
+ assert.ok(flowReset, 'control flow was not reset after a timeout');
102
+ });
99
103
  });
104
+
105
+ function onreset() {
106
+ flowReset = true;
107
+ }
100
108
  });
109
+ });
110
+
111
+ describe('async "done" support', function() {
112
+ this.timeout(2*1000);
113
+
114
+ var waited = false;
115
+ var DELAY = 100; // ms enough to notice
116
+
117
+ // Each test asynchronously sets waited to true, so clear/check waited
118
+ // before/after:
119
+ beforeEach(function() {
120
+ waited = false;
121
+ });
122
+
123
+ afterEach(function() {
124
+ assert.strictEqual(waited, true);
125
+ });
126
+
127
+ // --- First, vanilla mocha "it" should support the "done" callback correctly.
128
+
129
+ // This 'it' should block until 'done' is invoked
130
+ it('vanilla delayed', function(done) {
131
+ setTimeout(function delayedVanillaTimeout() {
132
+ waited = true;
133
+ done();
134
+ }, DELAY);
135
+ });
136
+
137
+ // --- Now with the webdriver wrappers for 'it' should support the "done" callback:
138
+
139
+ test.it('delayed', function(done) {
140
+ assert(done);
141
+ assert.strictEqual(typeof done, 'function');
142
+ setTimeout(function delayedTimeoutCallback() {
143
+ waited = true;
144
+ done();
145
+ }, DELAY);
146
+ });
147
+
148
+ // --- And test that the webdriver wrapper for 'it' works with a returned promise, too:
149
+
150
+ test.it('delayed by promise', function() {
151
+ var defer = promise.defer();
152
+ setTimeout(function delayedPromiseCallback() {
153
+ waited = true;
154
+ defer.fulfill('ignored');
155
+ });
156
+ return defer.promise;
157
+ });
158
+ });
101
159
 
102
- function onreset() {
103
- flowReset = true;
104
- }
160
+ describe('ControlFlow and "done" work together', function() {
161
+ var flow, order;
162
+ before(function() {
163
+ order = [];
164
+ flow = test.controlFlow();
165
+ flow.execute(function() { order.push(1); });
166
+ });
167
+
168
+ test.it('control flow updates and async done', function(done) {
169
+ flow.execute(function() { order.push(2); });
170
+ flow.execute(function() { order.push(3); }).then(function() {
171
+ order.push(4);
172
+ });
173
+ done();
174
+ });
175
+
176
+ after(function() {
177
+ assert.deepEqual([1, 2, 3, 4], order);
178
+ });
105
179
  });
106
180
  });
107
- });
108
181
 
109
- describe('Mocha async "done" support', function() {
110
- this.timeout(2*1000);
111
-
112
- var waited = false;
113
- var DELAY = 100; // ms enough to notice
114
-
115
- // Each test asynchronously sets waited to true, so clear/check waited
116
- // before/after:
117
- beforeEach(function() {
118
- waited = false;
119
- });
120
-
121
- afterEach(function() {
122
- assert.strictEqual(waited, true);
123
- });
124
-
125
- // --- First, vanilla mocha "it" should support the "done" callback correctly.
126
-
127
- // This 'it' should block until 'done' is invoked
128
- it('vanilla delayed', function(done) {
129
- setTimeout(function delayedVanillaTimeout() {
130
- waited = true;
131
- done();
132
- }, DELAY);
133
- });
134
-
135
- // --- Now with the webdriver wrappers for 'it' should support the "done" callback:
136
-
137
- test.it('delayed', function(done) {
138
- assert(done);
139
- assert.strictEqual(typeof done, 'function');
140
- setTimeout(function delayedTimeoutCallback() {
141
- waited = true;
142
- done();
143
- }, DELAY);
144
- });
145
-
146
- // --- And test that the webdriver wrapper for 'it' works with a returned promise, too:
147
-
148
- test.it('delayed by promise', function() {
149
- var defer = promise.defer();
150
- setTimeout(function delayedPromiseCallback() {
151
- waited = true;
152
- defer.fulfill('ignored');
153
- });
154
- return defer.promise;
155
- });
182
+ describe('generator support', function() {
183
+ let arr;
156
184
 
157
- });
185
+ beforeEach(() => arr = []);
186
+ afterEach(() => assert.deepEqual(arr, [0, 1, 2, 3]));
187
+
188
+ test.it('sync generator', function* () {
189
+ arr.push(yield arr.length);
190
+ arr.push(yield arr.length);
191
+ arr.push(yield arr.length);
192
+ arr.push(yield arr.length);
193
+ });
194
+
195
+ test.it('async generator', function* () {
196
+ arr.push(yield Promise.resolve(arr.length));
197
+ arr.push(yield Promise.resolve(arr.length));
198
+ arr.push(yield Promise.resolve(arr.length));
199
+ arr.push(yield Promise.resolve(arr.length));
200
+ });
201
+
202
+ test.it('generator returns promise', function*() {
203
+ arr.push(yield Promise.resolve(arr.length));
204
+ arr.push(yield Promise.resolve(arr.length));
205
+ arr.push(yield Promise.resolve(arr.length));
206
+ setTimeout(_ => arr.push(arr.length), 10);
207
+ return new Promise((resolve) => setTimeout(_ => resolve(), 25));
208
+ });
158
209
 
159
- describe('ControlFlow and "done" work together', function() {
160
- var flow, order;
161
- before(function() {
162
- order = [];
163
- flow = test.controlFlow();
164
- flow.execute(function() { order.push(1); });
165
- });
166
-
167
- test.it('control flow updates and async done', function(done) {
168
- flow.execute(function() { order.push(2); });
169
- flow.execute(function() { order.push(3); }).then(function() {
170
- order.push(4);
210
+ describe('generator runs with proper "this" context', () => {
211
+ before(function() { this.values = [0, 1, 2, 3]; });
212
+ test.it('', function*() {
213
+ arr = this.values;
171
214
  });
172
- done();
173
- })
215
+ });
174
216
 
175
- after(function() {
176
- assert.deepEqual([1, 2, 3, 4], order);
177
- })
217
+ it('generator function must not take a callback', function() {
218
+ arr = [0, 1, 2, 3]; // For teardown hook.
219
+ assert.throws(_ => {
220
+ test.it('', function*(done){});
221
+ }, TypeError);
222
+ });
223
+ });
178
224
  });
@@ -41,13 +41,13 @@ test.suite(function(env) {
41
41
  })
42
42
 
43
43
  var driver;
44
- test.before(function() {
45
- driver = env.builder().build();
44
+ test.before(function*() {
45
+ driver = yield env.builder().build();
46
46
  });
47
47
 
48
48
  test.after(function() {
49
49
  if (driver) {
50
- driver.quit();
50
+ return driver.quit();
51
51
  }
52
52
  });
53
53
 
@@ -58,29 +58,29 @@ test.suite(function(env) {
58
58
  // See https://github.com/ariya/phantomjs/issues/12506
59
59
  Browser.PHANTOM_JS,
60
60
  Browser.SAFARI)).
61
- it('can upload files', function() {
61
+ it('can upload files', function*() {
62
62
  driver.setFileDetector(new remote.FileDetector);
63
63
 
64
- driver.get(Pages.uploadPage);
64
+ yield driver.get(Pages.uploadPage);
65
65
 
66
- var fp = driver.call(function() {
66
+ var fp = yield driver.call(function() {
67
67
  return io.tmpFile().then(function(fp) {
68
68
  fs.writeFileSync(fp, FILE_HTML);
69
69
  return fp;
70
70
  });
71
71
  });
72
72
 
73
- driver.findElement(By.id('upload')).sendKeys(fp);
74
- driver.findElement(By.id('go')).click();
73
+ yield driver.findElement(By.id('upload')).sendKeys(fp);
74
+ yield driver.findElement(By.id('go')).click();
75
75
 
76
76
  // Uploading files across a network may take a while, even if they're small.
77
- var label = driver.findElement(By.id('upload_label'));
78
- driver.wait(until.elementIsNotVisible(label),
77
+ var label = yield driver.findElement(By.id('upload_label'));
78
+ yield driver.wait(until.elementIsNotVisible(label),
79
79
  10 * 1000, 'File took longer than 10 seconds to upload!');
80
80
 
81
- var frame = driver.findElement(By.id('upload_target'));
82
- driver.switchTo().frame(frame);
83
- assert(driver.findElement(By.css('body')).getText())
81
+ var frame = yield driver.findElement(By.id('upload_target'));
82
+ yield driver.switchTo().frame(frame);
83
+ yield assert(driver.findElement(By.css('body')).getText())
84
84
  .equalTo(LOREM_IPSUM_TEXT);
85
85
  });
86
86
  });