Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/edge/options_test.js
2885 views
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('node:assert')
21
const fs = require('node:fs')
22
const edge = require('selenium-webdriver/edge')
23
const symbols = require('selenium-webdriver/lib/symbols')
24
const test = require('../../lib/test')
25
const { locate } = require('../../lib/test/resources')
26
27
const WEBEXTENSION_CRX = locate('common/extensions/webextensions-selenium-example.crx')
28
29
describe('edge.Options', function () {
30
describe('addArguments', function () {
31
it('takes var_args', function () {
32
let options = new edge.Options()
33
assert.deepStrictEqual(options[symbols.serialize](), {
34
browserName: 'MicrosoftEdge',
35
'ms:edgeOptions': {},
36
})
37
38
options.addArguments('a', 'b')
39
assert.deepStrictEqual(options[symbols.serialize](), {
40
browserName: 'MicrosoftEdge',
41
'ms:edgeOptions': {
42
args: ['a', 'b'],
43
},
44
})
45
})
46
47
it('flattens input arrays', function () {
48
let options = new edge.Options()
49
assert.deepStrictEqual(options[symbols.serialize](), {
50
browserName: 'MicrosoftEdge',
51
'ms:edgeOptions': {},
52
})
53
54
options.addArguments(['a', 'b'], 'c', [1, 2], 3)
55
assert.deepStrictEqual(options[symbols.serialize](), {
56
browserName: 'MicrosoftEdge',
57
'ms:edgeOptions': {
58
args: ['a', 'b', 'c', 1, 2, 3],
59
},
60
})
61
})
62
63
it('useWebView changes browser name', function () {
64
let options = new edge.Options()
65
assert.strictEqual(options.getBrowserName(), 'MicrosoftEdge')
66
options.useWebView(true)
67
assert.strictEqual(options.getBrowserName(), 'webview2')
68
options.useWebView(false)
69
assert.strictEqual(options.getBrowserName(), 'MicrosoftEdge')
70
})
71
})
72
73
describe('addExtensions', function () {
74
it('takes var_args', function () {
75
let options = new edge.Options()
76
assert.strictEqual(options.options_.extensions, undefined)
77
78
options.addExtensions('a', 'b')
79
assert.deepStrictEqual(options.options_.extensions.extensions, ['a', 'b'])
80
})
81
82
it('flattens input arrays', function () {
83
let options = new edge.Options()
84
assert.strictEqual(options.options_.extensions, undefined)
85
86
options.addExtensions(['a', 'b'], 'c', [1, 2], 3)
87
assert.deepStrictEqual(options.options_.extensions.extensions, ['a', 'b', 'c', 1, 2, 3])
88
})
89
})
90
91
describe('serialize', function () {
92
it('base64 encodes extensions', async function () {
93
let expected = fs.readFileSync(WEBEXTENSION_CRX, 'base64')
94
let wire = new edge.Options().addExtensions(WEBEXTENSION_CRX)[symbols.serialize]()
95
96
let extensions = wire['ms:edgeOptions'].extensions[symbols.serialize]()
97
assert.strictEqual(extensions.length, 1)
98
assert.strictEqual(await extensions[0], expected)
99
})
100
})
101
102
describe('windowTypes', function () {
103
it('takes var_args', function () {
104
let options = new edge.Options()
105
assert.strictEqual(options.options_.windowTypes, undefined)
106
107
options.windowTypes('a', 'b')
108
assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b'])
109
})
110
111
it('flattens input arrays', function () {
112
let options = new edge.Options()
113
assert.strictEqual(options.options_.windowTypes, undefined)
114
115
options.windowTypes(['a', 'b'], 'c', [1, 2], 3)
116
assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b', 'c', 1, 2, 3])
117
})
118
})
119
})
120
121
test.suite(
122
function (env) {
123
let driver
124
125
beforeEach(function () {
126
driver = null
127
})
128
129
afterEach(function () {
130
return driver && driver.quit()
131
})
132
133
describe('Edge options', function () {
134
it('can start edge with custom args', async function () {
135
const options = new edge.Options().addArguments('user-agent=foo;bar')
136
137
driver = await env.builder().setEdgeOptions(options).build()
138
139
await driver.get(test.Pages.ajaxyPage)
140
141
var userAgent = await driver.executeScript('return window.navigator.userAgent')
142
assert.strictEqual(userAgent, 'foo;bar')
143
})
144
145
it('can start edge with network conditions set', async function () {
146
driver = await env.builder().build()
147
await driver.get(test.Pages.ajaxyPage)
148
await driver.setNetworkConditions({
149
offline: true,
150
latency: 0,
151
download_throughput: 0,
152
upload_throughput: 0,
153
})
154
assert.deepStrictEqual(await driver.getNetworkConditions(), {
155
download_throughput: 0,
156
latency: 0,
157
offline: true,
158
upload_throughput: 0,
159
})
160
})
161
162
it('can install an extension from path', async function () {
163
let options = new edge.Options().addExtensions(WEBEXTENSION_CRX)
164
165
driver = await env.builder().setEdgeOptions(options).build()
166
167
await driver.get(test.Pages.echoPage)
168
await verifyWebExtensionWasInstalled()
169
})
170
171
it('can install an extension from Buffer', async function () {
172
let options = new edge.Options().addExtensions(fs.readFileSync(WEBEXTENSION_CRX))
173
174
driver = await env.builder().setEdgeOptions(options).build()
175
176
await driver.get(test.Pages.echoPage)
177
await verifyWebExtensionWasInstalled()
178
})
179
180
async function verifyWebExtensionWasInstalled() {
181
let footer = await driver.findElement({
182
id: 'webextensions-selenium-example',
183
})
184
let text = await footer.getText()
185
assert.strictEqual(text, 'Content injected by webextensions-selenium-example')
186
}
187
})
188
},
189
{ browsers: ['MicrosoftEdge'] },
190
)
191
192