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,36 +17,191 @@
17
17
 
18
18
  'use strict';
19
19
 
20
- var Browser = require('..').Browser,
21
- By = require('..').By,
22
- until = require('..').until,
23
- test = require('../lib/test'),
24
- fileServer = require('../lib/test/fileserver');
20
+ const assert = require('assert');
25
21
 
22
+ const chrome = require('../chrome');
23
+ const error = require('../lib/error');
24
+ const fileServer = require('../lib/test/fileserver');
25
+ const firefox = require('../firefox');
26
+ const test = require('../lib/test');
27
+ const {Key, Origin} = require('../lib/input');
28
+ const {Browser, By, until} = require('..');
26
29
 
27
30
  test.suite(function(env) {
28
- var driver;
29
- test.beforeEach(function*() { driver = yield env.builder().build(); });
30
- test.afterEach(function() { return driver.quit(); });
31
-
32
- test.ignore(
33
- env.browsers(Browser.FIREFOX, Browser.PHANTOM_JS, Browser.SAFARI)).
31
+ test.ignore(env.browsers(Browser.SAFARI)).
34
32
  describe('WebDriver.actions()', function() {
33
+ let driver;
35
34
 
36
- test.it('can move to and click element in an iframe', function*() {
37
- yield driver.get(fileServer.whereIs('click_tests/click_in_iframe.html'));
35
+ before(async function() {
36
+ driver = await env.builder().build();
37
+ });
38
38
 
39
- yield driver.wait(until.elementLocated(By.id('ifr')), 5000)
40
- .then(frame => driver.switchTo().frame(frame));
39
+ afterEach(async function() {
40
+ try {
41
+ await driver.actions().clear();
42
+ } catch (e) {
43
+ if (e instanceof error.UnsupportedOperationError
44
+ || e instanceof error.UnknownCommandError) {
45
+ return;
46
+ }
47
+ throw e;
48
+ }
49
+ });
50
+
51
+ after(function() {
52
+ return driver.quit();
53
+ });
54
+
55
+ it('click(element)', async function() {
56
+ await driver.get(fileServer.whereIs('/data/actions/click.html'));
57
+
58
+ let box = await driver.findElement(By.id('box'));
59
+ assert.equal(await box.getAttribute('class'), '');
60
+
61
+ await driver.actions({bridge: true}).click(box).perform();
62
+ assert.equal(await box.getAttribute('class'), 'green');
63
+ });
64
+
65
+ it('click(element) clicks in center of element', async function() {
66
+ await driver.get(fileServer.whereIs('/data/actions/record_click.html'));
67
+
68
+ const div = await driver.findElement(By.css('div'));
69
+ const rect = await div.getRect();
70
+ assert.deepEqual(rect, {width: 500, height: 500, x: 0, y: 0});
71
+
72
+ await driver.actions({bridge: true}).click(div).perform();
73
+
74
+ const clicks = await driver.executeScript('return clicks');
75
+ assert.deepEqual(clicks, [[250, 250]]);
76
+ });
77
+
78
+ it('can move relative to element center', async function() {
79
+ await driver.get(fileServer.whereIs('/data/actions/record_click.html'));
41
80
 
42
- let link = yield driver.findElement(By.id('link'));
43
- yield driver.actions()
44
- .mouseMove(link)
81
+ const div = await driver.findElement(By.css('div'));
82
+ const rect = await div.getRect();
83
+ assert.deepEqual(rect, {width: 500, height: 500, x: 0, y: 0});
84
+
85
+ await driver.actions({bridge: true})
86
+ .move({x: 10, y: 10, origin: div})
45
87
  .click()
46
88
  .perform();
47
89
 
90
+ const clicks = await driver.executeScript('return clicks');
91
+ assert.deepEqual(clicks, [[260, 260]]);
92
+ });
93
+
94
+ it('doubleClick(element)', async function() {
95
+ // This test requires Firefox 59+.
96
+ if (env.browser.name === Browser.FIREFOX) {
97
+ await driver.quit();
98
+ driver = await env.builder()
99
+ .setFirefoxOptions(
100
+ new firefox.Options().setBinary(firefox.Channel.NIGHTLY))
101
+ .build();
102
+ }
103
+ await driver.get(fileServer.whereIs('/data/actions/click.html'));
104
+
105
+ let box = await driver.findElement(By.id('box'));
106
+ assert.equal(await box.getAttribute('class'), '');
107
+
108
+ await driver.actions({bridge: true}).doubleClick(box).perform();
109
+ assert.equal(await box.getAttribute('class'), 'blue');
110
+ });
111
+
112
+ it('dragAndDrop()', async function() {
113
+ await driver.get(fileServer.whereIs('/data/actions/drag.html'));
114
+
115
+ let slide = await driver.findElement(By.id('slide'));
116
+ assert.equal(await slide.getCssValue('left'), '0px');
117
+ assert.equal(await slide.getCssValue('top'), '0px');
118
+
119
+ let br = await driver.findElement(By.id('BR'));
120
+ await driver.actions({bridge: true}).dragAndDrop(slide, br).perform();
121
+ assert.equal(await slide.getCssValue('left'), '206px');
122
+ assert.equal(await slide.getCssValue('top'), '206px');
123
+
124
+ let tr = await driver.findElement(By.id('TR'));
125
+ await driver.actions({bridge: true}).dragAndDrop(slide, tr).perform();
126
+ assert.equal(await slide.getCssValue('left'), '206px');
127
+ assert.equal(await slide.getCssValue('top'), '1px');
128
+ });
129
+
130
+ it('move()', async function() {
131
+ await driver.get(fileServer.whereIs('/data/actions/drag.html'));
132
+
133
+ let slide = await driver.findElement(By.id('slide'));
134
+ assert.equal(await slide.getCssValue('left'), '0px');
135
+ assert.equal(await slide.getCssValue('top'), '0px');
136
+
137
+ await driver.actions({bridge: true})
138
+ .move({origin: slide})
139
+ .press()
140
+ .move({x: 100, y: 100, origin: Origin.POINTER})
141
+ .release()
142
+ .perform();
143
+ assert.equal(await slide.getCssValue('left'), '101px');
144
+ assert.equal(await slide.getCssValue('top'), '101px');
145
+ });
146
+
147
+ it('can move to and click element in an iframe', async function() {
148
+ await driver.get(fileServer.whereIs('click_tests/click_in_iframe.html'));
149
+
150
+ await driver.wait(until.elementLocated(By.id('ifr')), 5000)
151
+ .then(frame => driver.switchTo().frame(frame));
152
+
153
+ let link = await driver.findElement(By.id('link'));
154
+
155
+ await driver.actions({bridge: true}).click(link).perform();
156
+ await driver.switchTo().defaultContent();
48
157
  return driver.wait(until.titleIs('Submitted Successfully!'), 5000);
49
158
  });
50
159
 
160
+ it('can send keys to focused element', async function() {
161
+ await driver.get(test.Pages.formPage);
162
+
163
+ let el = await driver.findElement(By.id('email'));
164
+ assert.equal(await el.getAttribute('value'), '');
165
+
166
+ await driver.executeScript('arguments[0].focus()', el);
167
+
168
+ await driver.actions({bridge: true}).sendKeys('foobar').perform();
169
+
170
+ assert.equal(await el.getAttribute('value'), 'foobar');
171
+ });
172
+
173
+ it('can send keys to focused element (with modifiers)', async function() {
174
+ await driver.get(test.Pages.formPage);
175
+
176
+ let el = await driver.findElement(By.id('email'));
177
+ assert.equal(await el.getAttribute('value'), '');
178
+
179
+ await driver.executeScript('arguments[0].focus()', el);
180
+
181
+ await driver.actions({bridge: true})
182
+ .sendKeys('fo')
183
+ .keyDown(Key.SHIFT)
184
+ .sendKeys('OB')
185
+ .keyUp(Key.SHIFT)
186
+ .sendKeys('ar')
187
+ .perform();
188
+
189
+ assert.equal(await el.getAttribute('value'), 'foOBar');
190
+ });
191
+
192
+ it('can interact with simple form elements', async function() {
193
+ await driver.get(test.Pages.formPage);
194
+
195
+ let el = await driver.findElement(By.id('email'));
196
+ assert.equal(await el.getAttribute('value'), '');
197
+
198
+ await driver.actions({bridge: true})
199
+ .click(el)
200
+ .sendKeys('foobar')
201
+ .perform();
202
+
203
+ assert.equal(await el.getAttribute('value'), 'foobar');
204
+ });
51
205
  });
52
206
  });
207
+
@@ -0,0 +1,106 @@
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
+
22
+ const chrome = require('../chrome');
23
+ const edge = require('../edge');
24
+ const error = require('../lib/error');
25
+ const firefox = require('../firefox');
26
+ const ie = require('../ie');
27
+ const safari = require('../safari');
28
+ const test = require('../lib/test');
29
+ const {Browser} = require('../lib/capabilities');
30
+ const {Pages} = require('../lib/test');
31
+ const {Builder, Capabilities, WebDriver} = require('..');
32
+
33
+
34
+ test.suite(function(env) {
35
+ const browsers = (...args) => env.browsers(...args);
36
+
37
+ const BROWSER_MAP = new Map([
38
+ [Browser.CHROME, chrome.Driver],
39
+ [Browser.EDGE, edge.Driver],
40
+ [Browser.FIREFOX, firefox.Driver],
41
+ [Browser.INTERNET_EXPLORER, ie.Driver],
42
+ [Browser.SAFARI, safari.Driver],
43
+ ]);
44
+
45
+ if (BROWSER_MAP.has(env.browser.name)) {
46
+ describe('builder creates thenable driver instances', function() {
47
+ let driver;
48
+
49
+ after(() => driver && driver.quit());
50
+
51
+ it(env.browser.name, function() {
52
+ driver = env.builder().build();
53
+
54
+ const want = BROWSER_MAP.get(env.browser.name);
55
+ assert.ok(
56
+ driver instanceof want,
57
+ `want ${want.name}, but got ${driver.name}`);
58
+ assert.equal(typeof driver.then, 'function');
59
+
60
+ return driver
61
+ .then(
62
+ d =>
63
+ assert.ok(
64
+ d instanceof want,
65
+ `want ${want.name}, but got ${d.name}`))
66
+ // Load something so the safari driver doesn't crash from starting and
67
+ // stopping in short time.
68
+ .then(() => driver.get(Pages.echoPage));
69
+ });
70
+ });
71
+ }
72
+
73
+ class OptionsTest {
74
+ constructor(ctor, key) {
75
+ this.ctor = ctor;
76
+ this.key = key;
77
+ }
78
+ }
79
+
80
+ });
81
+
82
+ describe('Builder', function() {
83
+ describe('catches incorrect use of browser options class', function() {
84
+ function test(key, options) {
85
+ it(key, async function() {
86
+ let builder = new Builder()
87
+ .withCapabilities(new Capabilities()
88
+ .set('browserName', 'fake-browser-should-not-try-to-start')
89
+ .set(key, new options()));
90
+ try {
91
+ let driver = await builder.build();
92
+ await driver.quit();
93
+ return Promise.reject(Error('should have failed'));
94
+ } catch (ex) {
95
+ if (!(ex instanceof error.InvalidArgumentError)) {
96
+ throw ex;
97
+ }
98
+ }
99
+ });
100
+ }
101
+
102
+ test('chromeOptions', chrome.Options);
103
+ test('moz:firefoxOptions', firefox.Options);
104
+ test('safari.options', safari.Options);
105
+ });
106
+ });
@@ -0,0 +1,93 @@
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 fs = require('fs');
22
+ const path = require('path');
23
+
24
+ const chrome = require('../../chrome');
25
+ const error = require('../../lib/error');
26
+ const fileServer = require('../../lib/test/fileserver');
27
+ const io = require('../../io');
28
+ const test = require('../../lib/test');
29
+ const webdriver = require('../..');
30
+
31
+ test.suite(function(env) {
32
+ let driver;
33
+
34
+ before(async function() {
35
+ driver = await env.builder()
36
+ .setChromeOptions(new chrome.Options().headless())
37
+ .build();
38
+ });
39
+ after(() => driver.quit());
40
+
41
+ it('can send commands to devtools', async function() {
42
+ await driver.get(test.Pages.ajaxyPage);
43
+ assert.equal(await driver.getCurrentUrl(), test.Pages.ajaxyPage);
44
+
45
+ await driver.sendDevToolsCommand(
46
+ 'Page.navigate', {url: test.Pages.echoPage});
47
+ assert.equal(await driver.getCurrentUrl(), test.Pages.echoPage);
48
+ });
49
+
50
+ describe('setDownloadPath', function() {
51
+ it('can enable downloads in headless mode', async function() {
52
+ const dir = await io.tmpDir();
53
+ await driver.setDownloadPath(dir);
54
+
55
+ const url = fileServer.whereIs('/data/chrome/download.html');
56
+ await driver.get(`data:text/html,<!DOCTYPE html>
57
+ <div><a download="" href="${url}">Go!</a></div>`);
58
+
59
+ await driver.findElement({css: 'a'}).click();
60
+
61
+ const downloadPath = path.join(dir, 'download.html');
62
+ await driver.wait(() => io.exists(downloadPath), 1000);
63
+
64
+ const goldenPath =
65
+ path.join(__dirname, '../../lib/test/data/chrome/download.html');
66
+ assert.equal(
67
+ fs.readFileSync(downloadPath, 'utf8'),
68
+ fs.readFileSync(goldenPath, 'utf8'));
69
+ });
70
+
71
+ it('throws if path is not a directory', async function() {
72
+ await assertInvalidArgumentError(() => driver.setDownloadPath());
73
+ await assertInvalidArgumentError(() => driver.setDownloadPath(null));
74
+ await assertInvalidArgumentError(() => driver.setDownloadPath(''));
75
+ await assertInvalidArgumentError(() => driver.setDownloadPath(1234));
76
+
77
+ const file = await io.tmpFile();
78
+ await assertInvalidArgumentError(() => driver.setDownloadPath(file));
79
+
80
+ async function assertInvalidArgumentError(fn) {
81
+ try {
82
+ await fn();
83
+ return Promise.reject(Error('should have failed'));
84
+ } catch (err) {
85
+ if (err instanceof error.InvalidArgumentError) {
86
+ return;
87
+ }
88
+ throw err;
89
+ }
90
+ }
91
+ });
92
+ });
93
+ }, {browsers: ['chrome']});
@@ -17,186 +17,80 @@
17
17
 
18
18
  'use strict';
19
19
 
20
- var fs = require('fs');
20
+ const assert = require('assert');
21
+ const fs = require('fs');
21
22
 
22
- var webdriver = require('../..'),
23
- chrome = require('../../chrome'),
24
- symbols = require('../../lib/symbols'),
25
- proxy = require('../../proxy'),
26
- assert = require('../../testing/assert');
27
-
28
- var test = require('../../lib/test');
23
+ const chrome = require('../../chrome');
24
+ const proxy = require('../../proxy');
25
+ const symbols = require('../../lib/symbols');
26
+ const test = require('../../lib/test');
27
+ const webdriver = require('../..');
29
28
 
30
29
 
31
30
  describe('chrome.Options', function() {
32
- describe('fromCapabilities', function() {
33
-
34
- it('should return a new Options instance if none were defined',
35
- function() {
36
- var options = chrome.Options.fromCapabilities(
37
- new webdriver.Capabilities());
38
- assert(options).instanceOf(chrome.Options);
39
- });
40
-
41
- it('should return options instance if present', function() {
42
- var options = new chrome.Options();
43
- var caps = options.toCapabilities();
44
- assert(caps).instanceOf(webdriver.Capabilities);
45
- assert(chrome.Options.fromCapabilities(caps)).equalTo(options);
46
- });
47
-
48
- it('should rebuild options from wire representation', function() {
49
- var expectedExtension = fs.readFileSync(__filename, 'base64');
50
- var caps = webdriver.Capabilities.chrome().set('chromeOptions', {
51
- args: ['a', 'b'],
52
- extensions: [__filename],
53
- binary: 'binaryPath',
54
- logPath: 'logFilePath',
55
- detach: true,
56
- localState: 'localStateValue',
57
- prefs: 'prefsValue'
58
- });
59
-
60
- var options = chrome.Options.fromCapabilities(caps);
61
- var json = options[symbols.serialize]();
62
-
63
- assert(json.args.length).equalTo(2);
64
- assert(json.args[0]).equalTo('a');
65
- assert(json.args[1]).equalTo('b');
66
- assert(json.extensions.length).equalTo(1);
67
- assert(json.extensions[0]).equalTo(expectedExtension);
68
- assert(json.binary).equalTo('binaryPath');
69
- assert(json.logPath).equalTo('logFilePath');
70
- assert(json.detach).equalTo(true);
71
- assert(json.localState).equalTo('localStateValue');
72
- assert(json.prefs).equalTo('prefsValue');
73
- });
74
-
75
- it('should rebuild options from incomplete wire representation',
76
- function() {
77
- var caps = webdriver.Capabilities.chrome().set('chromeOptions', {
78
- logPath: 'logFilePath'
79
- });
80
-
81
- var options = chrome.Options.fromCapabilities(caps);
82
- var json = options[symbols.serialize]();
83
- assert(json.args).isUndefined();
84
- assert(json.binary).isUndefined();
85
- assert(json.detach).isUndefined();
86
- assert(json.excludeSwitches).isUndefined();
87
- assert(json.extensions).isUndefined();
88
- assert(json.localState).isUndefined();
89
- assert(json.logPath).equalTo('logFilePath');
90
- assert(json.prefs).isUndefined();
91
- assert(json.minidumpPath).isUndefined();
92
- assert(json.mobileEmulation).isUndefined();
93
- assert(json.perfLoggingPrefs).isUndefined();
94
- });
95
-
96
- it('should extract supported WebDriver capabilities', function() {
97
- var proxyPrefs = proxy.direct();
98
- var logPrefs = {};
99
- var caps = webdriver.Capabilities.chrome().
100
- set(webdriver.Capability.PROXY, proxyPrefs).
101
- set(webdriver.Capability.LOGGING_PREFS, logPrefs);
102
-
103
- var options = chrome.Options.fromCapabilities(caps);
104
- assert(options.proxy_).equalTo(proxyPrefs);
105
- assert(options.logPrefs_).equalTo(logPrefs);
106
- });
107
- });
108
-
109
31
  describe('addArguments', function() {
110
32
  it('takes var_args', function() {
111
- var options = new chrome.Options();
112
- assert(options[symbols.serialize]().args).isUndefined();
33
+ let options = new chrome.Options();
34
+ assert.deepEqual(
35
+ options[symbols.serialize](),
36
+ {browserName: 'chrome', chromeOptions: {}});
113
37
 
114
38
  options.addArguments('a', 'b');
115
- var json = options[symbols.serialize]();
116
- assert(json.args.length).equalTo(2);
117
- assert(json.args[0]).equalTo('a');
118
- assert(json.args[1]).equalTo('b');
39
+ assert.deepEqual(
40
+ options[symbols.serialize](),
41
+ {
42
+ browserName: 'chrome',
43
+ chromeOptions: {
44
+ args: ['a', 'b']
45
+ }
46
+ });
119
47
  });
120
48
 
121
49
  it('flattens input arrays', function() {
122
- var options = new chrome.Options();
123
- assert(options[symbols.serialize]().args).isUndefined();
50
+ let options = new chrome.Options();
51
+ assert.deepEqual(
52
+ options[symbols.serialize](),
53
+ {browserName: 'chrome', chromeOptions: {}});
124
54
 
125
55
  options.addArguments(['a', 'b'], 'c', [1, 2], 3);
126
- var json = options[symbols.serialize]();
127
- assert(json.args.length).equalTo(6);
128
- assert(json.args[0]).equalTo('a');
129
- assert(json.args[1]).equalTo('b');
130
- assert(json.args[2]).equalTo('c');
131
- assert(json.args[3]).equalTo(1);
132
- assert(json.args[4]).equalTo(2);
133
- assert(json.args[5]).equalTo(3);
56
+ assert.deepEqual(
57
+ options[symbols.serialize](),
58
+ {
59
+ browserName: 'chrome',
60
+ chromeOptions: {
61
+ args: ['a', 'b', 'c', 1, 2, 3]
62
+ }
63
+ });
134
64
  });
135
65
  });
136
66
 
137
67
  describe('addExtensions', function() {
138
68
  it('takes var_args', function() {
139
- var options = new chrome.Options();
140
- assert(options.extensions_.length).equalTo(0);
69
+ let options = new chrome.Options();
70
+ assert.strictEqual(options.options_.extensions, undefined);
141
71
 
142
72
  options.addExtensions('a', 'b');
143
- assert(options.extensions_.length).equalTo(2);
144
- assert(options.extensions_[0]).equalTo('a');
145
- assert(options.extensions_[1]).equalTo('b');
73
+ assert.deepEqual(options.options_.extensions, ['a', 'b']);
146
74
  });
147
75
 
148
76
  it('flattens input arrays', function() {
149
- var options = new chrome.Options();
150
- assert(options.extensions_.length).equalTo(0);
77
+ let options = new chrome.Options();
78
+ assert.strictEqual(options.options_.extensions, undefined);
151
79
 
152
80
  options.addExtensions(['a', 'b'], 'c', [1, 2], 3);
153
- assert(options.extensions_.length).equalTo(6);
154
- assert(options.extensions_[0]).equalTo('a');
155
- assert(options.extensions_[1]).equalTo('b');
156
- assert(options.extensions_[2]).equalTo('c');
157
- assert(options.extensions_[3]).equalTo(1);
158
- assert(options.extensions_[4]).equalTo(2);
159
- assert(options.extensions_[5]).equalTo(3);
81
+ assert.deepEqual(options.options_.extensions, ['a', 'b', 'c', 1, 2, 3]);
160
82
  });
161
83
  });
162
84
 
163
85
  describe('serialize', function() {
164
- it('base64 encodes extensions', function() {
165
- var expected = fs.readFileSync(__filename, 'base64');
166
- var wire = new chrome.Options()
86
+ it('base64 encodes extensions', async function() {
87
+ let expected = fs.readFileSync(__filename, 'base64');
88
+ let wire = new chrome.Options()
167
89
  .addExtensions(__filename)
168
90
  [symbols.serialize]();
169
- assert(wire.extensions.length).equalTo(1);
170
- assert(wire.extensions[0]).equalTo(expected);
171
- });
172
- });
173
-
174
- describe('toCapabilities', function() {
175
- it('returns a new capabilities object if one is not provided', function() {
176
- var options = new chrome.Options();
177
- var caps = options.toCapabilities();
178
- assert(caps.get('browserName')).equalTo('chrome');
179
- assert(caps.get('chromeOptions')).equalTo(options);
180
- });
181
-
182
- it('adds to input capabilities object', function() {
183
- var caps = webdriver.Capabilities.firefox();
184
- var options = new chrome.Options();
185
- assert(options.toCapabilities(caps)).equalTo(caps);
186
- assert(caps.get('browserName')).equalTo('firefox');
187
- assert(caps.get('chromeOptions')).equalTo(options);
188
- });
189
-
190
- it('sets generic driver capabilities', function() {
191
- var proxyPrefs = {};
192
- var loggingPrefs = {};
193
- var options = new chrome.Options().
194
- setLoggingPrefs(loggingPrefs).
195
- setProxy(proxyPrefs);
196
91
 
197
- var caps = options.toCapabilities();
198
- assert(caps.get('proxy')).equalTo(proxyPrefs);
199
- assert(caps.get('loggingPrefs')).equalTo(loggingPrefs);
92
+ assert.equal(wire.chromeOptions.extensions.length, 1);
93
+ assert.equal(await wire.chromeOptions.extensions[0], expected);
200
94
  });
201
95
  });
202
96
  });
@@ -204,24 +98,24 @@ describe('chrome.Options', function() {
204
98
  test.suite(function(env) {
205
99
  var driver;
206
100
 
207
- test.afterEach(function() {
101
+ afterEach(function() {
208
102
  return driver.quit();
209
103
  });
210
104
 
211
105
  describe('Chrome options', function() {
212
- test.it('can start Chrome with custom args', function*() {
106
+ it('can start Chrome with custom args', async function() {
213
107
  var options = new chrome.Options().
214
108
  addArguments('user-agent=foo;bar');
215
109
 
216
- driver = yield env.builder()
110
+ driver = await env.builder()
217
111
  .setChromeOptions(options)
218
112
  .build();
219
113
 
220
- yield driver.get(test.Pages.ajaxyPage);
114
+ await driver.get(test.Pages.ajaxyPage);
221
115
 
222
116
  var userAgent =
223
- yield driver.executeScript('return window.navigator.userAgent');
224
- assert(userAgent).equalTo('foo;bar');
117
+ await driver.executeScript('return window.navigator.userAgent');
118
+ assert.equal(userAgent, 'foo;bar');
225
119
  });
226
120
  });
227
121
  }, {browsers: ['chrome']});