Path: blob/trunk/javascript/selenium-webdriver/test/firefox/contextSwitching_test.js
2884 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 error = require('selenium-webdriver/lib/error')21const { Browser } = require('selenium-webdriver/index')22const { Context } = require('selenium-webdriver/firefox')23const { suite } = require('../../lib/test')24const firefox = require('selenium-webdriver/firefox')2526suite(27function (env) {28describe('firefox', function () {29let driver3031beforeEach(function () {32driver = null33})3435afterEach(function () {36return driver && driver.quit()37})3839describe('context switching', function () {40beforeEach(async function () {41let options = env.builder().getFirefoxOptions() || new firefox.Options()42options.addArguments('-remote-allow-system-access')43driver = await env.builder().setFirefoxOptions(options).build()44})4546it('can get context', async function () {47assert.strictEqual(await driver.getContext(), Context.CONTENT)48})4950it('can set context', async function () {51await driver.setContext(Context.CHROME)52let ctxt = await driver.getContext()53assert.strictEqual(ctxt, Context.CHROME)5455await driver.setContext(Context.CONTENT)56ctxt = await driver.getContext()57assert.strictEqual(ctxt, Context.CONTENT)58})5960it('throws on unknown context', function () {61return driver.setContext('foo').then(assert.fail, function (e) {62assert(e instanceof error.InvalidArgumentError)63})64})65})66})67},68{ browsers: [Browser.FIREFOX] },69)707172