Path: blob/trunk/javascript/selenium-webdriver/test/edge/options_test.js
2885 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const fs = require('node:fs')21const edge = require('selenium-webdriver/edge')22const symbols = require('selenium-webdriver/lib/symbols')23const test = require('../../lib/test')24const { locate } = require('../../lib/test/resources')2526const WEBEXTENSION_CRX = locate('common/extensions/webextensions-selenium-example.crx')2728describe('edge.Options', function () {29describe('addArguments', function () {30it('takes var_args', function () {31let options = new edge.Options()32assert.deepStrictEqual(options[symbols.serialize](), {33browserName: 'MicrosoftEdge',34'ms:edgeOptions': {},35})3637options.addArguments('a', 'b')38assert.deepStrictEqual(options[symbols.serialize](), {39browserName: 'MicrosoftEdge',40'ms:edgeOptions': {41args: ['a', 'b'],42},43})44})4546it('flattens input arrays', function () {47let options = new edge.Options()48assert.deepStrictEqual(options[symbols.serialize](), {49browserName: 'MicrosoftEdge',50'ms:edgeOptions': {},51})5253options.addArguments(['a', 'b'], 'c', [1, 2], 3)54assert.deepStrictEqual(options[symbols.serialize](), {55browserName: 'MicrosoftEdge',56'ms:edgeOptions': {57args: ['a', 'b', 'c', 1, 2, 3],58},59})60})6162it('useWebView changes browser name', function () {63let options = new edge.Options()64assert.strictEqual(options.getBrowserName(), 'MicrosoftEdge')65options.useWebView(true)66assert.strictEqual(options.getBrowserName(), 'webview2')67options.useWebView(false)68assert.strictEqual(options.getBrowserName(), 'MicrosoftEdge')69})70})7172describe('addExtensions', function () {73it('takes var_args', function () {74let options = new edge.Options()75assert.strictEqual(options.options_.extensions, undefined)7677options.addExtensions('a', 'b')78assert.deepStrictEqual(options.options_.extensions.extensions, ['a', 'b'])79})8081it('flattens input arrays', function () {82let options = new edge.Options()83assert.strictEqual(options.options_.extensions, undefined)8485options.addExtensions(['a', 'b'], 'c', [1, 2], 3)86assert.deepStrictEqual(options.options_.extensions.extensions, ['a', 'b', 'c', 1, 2, 3])87})88})8990describe('serialize', function () {91it('base64 encodes extensions', async function () {92let expected = fs.readFileSync(WEBEXTENSION_CRX, 'base64')93let wire = new edge.Options().addExtensions(WEBEXTENSION_CRX)[symbols.serialize]()9495let extensions = wire['ms:edgeOptions'].extensions[symbols.serialize]()96assert.strictEqual(extensions.length, 1)97assert.strictEqual(await extensions[0], expected)98})99})100101describe('windowTypes', function () {102it('takes var_args', function () {103let options = new edge.Options()104assert.strictEqual(options.options_.windowTypes, undefined)105106options.windowTypes('a', 'b')107assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b'])108})109110it('flattens input arrays', function () {111let options = new edge.Options()112assert.strictEqual(options.options_.windowTypes, undefined)113114options.windowTypes(['a', 'b'], 'c', [1, 2], 3)115assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b', 'c', 1, 2, 3])116})117})118})119120test.suite(121function (env) {122let driver123124beforeEach(function () {125driver = null126})127128afterEach(function () {129return driver && driver.quit()130})131132describe('Edge options', function () {133it('can start edge with custom args', async function () {134const options = new edge.Options().addArguments('user-agent=foo;bar')135136driver = await env.builder().setEdgeOptions(options).build()137138await driver.get(test.Pages.ajaxyPage)139140var userAgent = await driver.executeScript('return window.navigator.userAgent')141assert.strictEqual(userAgent, 'foo;bar')142})143144it('can start edge with network conditions set', async function () {145driver = await env.builder().build()146await driver.get(test.Pages.ajaxyPage)147await driver.setNetworkConditions({148offline: true,149latency: 0,150download_throughput: 0,151upload_throughput: 0,152})153assert.deepStrictEqual(await driver.getNetworkConditions(), {154download_throughput: 0,155latency: 0,156offline: true,157upload_throughput: 0,158})159})160161it('can install an extension from path', async function () {162let options = new edge.Options().addExtensions(WEBEXTENSION_CRX)163164driver = await env.builder().setEdgeOptions(options).build()165166await driver.get(test.Pages.echoPage)167await verifyWebExtensionWasInstalled()168})169170it('can install an extension from Buffer', async function () {171let options = new edge.Options().addExtensions(fs.readFileSync(WEBEXTENSION_CRX))172173driver = await env.builder().setEdgeOptions(options).build()174175await driver.get(test.Pages.echoPage)176await verifyWebExtensionWasInstalled()177})178179async function verifyWebExtensionWasInstalled() {180let footer = await driver.findElement({181id: 'webextensions-selenium-example',182})183let text = await footer.getText()184assert.strictEqual(text, 'Content injected by webextensions-selenium-example')185}186})187},188{ browsers: ['MicrosoftEdge'] },189)190191192