Skip to content

Commit bc69a20

Browse files
committed
[js] Updating edge.js to extend chromium.driver (fixes #9626)
1 parent 5131149 commit bc69a20

File tree

3 files changed

+168
-13
lines changed

3 files changed

+168
-13
lines changed

javascript/node/selenium-webdriver/edge.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,20 @@ class Options extends chromium.Options {
143143
/**
144144
* Creates a new WebDriver client for Microsoft's Edge.
145145
*/
146-
class Driver extends webdriver.WebDriver {
146+
class Driver extends chromium.Driver {
147147
/**
148148
* Creates a new browser session for Microsoft's Edge browser.
149149
*
150-
* @param {(Capabilities|Options)=} options The configuration options.
151-
* @param {remote.DriverService=} opt_service The service to use; will create
150+
* @param {(Capabilities|Options)=} opt_config The configuration options.
151+
* @param {remote.DriverService=} opt_serviceExecutor The service to use; will create
152152
* a new Legacy or Chromium service based on {@linkplain Options} by default.
153153
* @return {!Driver} A new driver instance.
154154
*/
155-
static createSession(options, opt_service) {
156-
options = options || new Options()
157-
let service = opt_service || getDefaultService()
158-
let client = service.start().then((url) => new http.HttpClient(url))
159-
let executor = new http.Executor(client)
160-
161-
return /** @type {!Driver} */ (super.createSession(executor, options, () =>
162-
service.kill()
155+
static createSession(opt_config, opt_serviceExecutor) {
156+
let caps = opt_config || new Options()
157+
return /** @type {!Driver} */ (super.createSession(
158+
caps,
159+
opt_serviceExecutor
163160
))
164161
}
165162

@@ -213,6 +210,7 @@ function locateSynchronously() {
213210
Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
214211
Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions'
215212
Driver.prototype.VENDOR_CAPABILITY_PREFIX = 'ms'
213+
Driver.getDefaultService = getDefaultService
216214

217215
// PUBLIC API
218216

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
23+
const edge = require('../../edge')
24+
const symbols = require('../../lib/symbols')
25+
const test = require('../../lib/test')
26+
27+
describe('edge.Options', function () {
28+
describe('addArguments', function () {
29+
it('takes var_args', function () {
30+
let options = new edge.Options()
31+
assert.deepStrictEqual(options[symbols.serialize](), {
32+
browserName: 'MicrosoftEdge',
33+
'ms:edgeOptions': {},
34+
})
35+
36+
options.addArguments('a', 'b')
37+
assert.deepStrictEqual(options[symbols.serialize](), {
38+
browserName: 'MicrosoftEdge',
39+
'ms:edgeOptions': {
40+
args: ['a', 'b'],
41+
},
42+
})
43+
})
44+
45+
it('flattens input arrays', function () {
46+
let options = new edge.Options()
47+
assert.deepStrictEqual(options[symbols.serialize](), {
48+
browserName: 'MicrosoftEdge',
49+
'ms:edgeOptions': {},
50+
})
51+
52+
options.addArguments(['a', 'b'], 'c', [1, 2], 3)
53+
assert.deepStrictEqual(options[symbols.serialize](), {
54+
browserName: 'MicrosoftEdge',
55+
'ms:edgeOptions': {
56+
args: ['a', 'b', 'c', 1, 2, 3],
57+
},
58+
})
59+
})
60+
})
61+
62+
describe('addExtensions', function () {
63+
it('takes var_args', function () {
64+
let options = new edge.Options()
65+
assert.strictEqual(options.options_.extensions, undefined)
66+
67+
options.addExtensions('a', 'b')
68+
assert.deepStrictEqual(options.options_.extensions, ['a', 'b'])
69+
})
70+
71+
it('flattens input arrays', function () {
72+
let options = new edge.Options()
73+
assert.strictEqual(options.options_.extensions, undefined)
74+
75+
options.addExtensions(['a', 'b'], 'c', [1, 2], 3)
76+
assert.deepStrictEqual(options.options_.extensions, ['a', 'b', 'c', 1, 2, 3])
77+
})
78+
})
79+
80+
describe('serialize', function () {
81+
it('base64 encodes extensions', async function () {
82+
let expected = fs.readFileSync(__filename, 'base64')
83+
let wire = new edge.Options()
84+
.addExtensions(__filename)
85+
[symbols.serialize]()
86+
87+
assert.strictEqual(wire['ms:edgeOptions'].extensions.length, 1)
88+
assert.strictEqual(
89+
await wire['ms:edgeOptions'].extensions[0],
90+
expected
91+
)
92+
})
93+
})
94+
95+
describe('windowTypes', function() {
96+
it('takes var_args', function() {
97+
let options = new edge.Options();
98+
assert.strictEqual(options.options_.windowTypes, undefined);
99+
100+
options.windowTypes('a', 'b');
101+
assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b']);
102+
})
103+
104+
it('flattens input arrays', function() {
105+
let options = new edge.Options();
106+
assert.strictEqual(options.options_.windowTypes, undefined);
107+
108+
options.windowTypes(['a', 'b'], 'c', [1, 2], 3);
109+
assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b', 'c', 1, 2, 3]);
110+
})
111+
})
112+
})
113+
114+
test.suite(
115+
function (env) {
116+
var driver
117+
118+
afterEach(function () {
119+
return driver.quit()
120+
})
121+
122+
describe('Edge options', function () {
123+
it('can start edge with custom args', async function () {
124+
var options = new edge.Options().addArguments('user-agent=foo;bar')
125+
126+
driver = await env.builder().setEdgeOptions(options).build()
127+
128+
await driver.get(test.Pages.ajaxyPage)
129+
130+
var userAgent = await driver.executeScript(
131+
'return window.navigator.userAgent'
132+
)
133+
assert.strictEqual(userAgent, 'foo;bar')
134+
})
135+
136+
it('can start edge with network conditions set', async function () {
137+
138+
driver = await env.builder().build()
139+
await driver.get(test.Pages.ajaxyPage)
140+
await driver.setNetworkConditions({
141+
offline: true,
142+
latency: 0,
143+
download_throughput: 0,
144+
upload_throughput: 0
145+
});
146+
assert.deepStrictEqual(await driver.getNetworkConditions(),
147+
{
148+
download_throughput: 0,
149+
latency: 0,
150+
offline: true,
151+
upload_throughput: 0
152+
})
153+
})
154+
})
155+
},
156+
{ browsers: ['MicrosoftEdge'] }
157+
)

javascript/node/selenium-webdriver/test/edge_test.js renamed to javascript/node/selenium-webdriver/test/edge/service_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
'use strict'
1919

2020
const assert = require('assert')
21-
const edge = require('../edge')
22-
const test = require('../lib/test')
21+
const edge = require('../../edge')
22+
const test = require('../../lib/test')
2323

2424
test.suite(
2525
function (_env) {

0 commit comments

Comments
 (0)