Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/firefox/contextSwitching_test.js
2884 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 error = require('selenium-webdriver/lib/error')
22
const { Browser } = require('selenium-webdriver/index')
23
const { Context } = require('selenium-webdriver/firefox')
24
const { suite } = require('../../lib/test')
25
const firefox = require('selenium-webdriver/firefox')
26
27
suite(
28
function (env) {
29
describe('firefox', function () {
30
let driver
31
32
beforeEach(function () {
33
driver = null
34
})
35
36
afterEach(function () {
37
return driver && driver.quit()
38
})
39
40
describe('context switching', function () {
41
beforeEach(async function () {
42
let options = env.builder().getFirefoxOptions() || new firefox.Options()
43
options.addArguments('-remote-allow-system-access')
44
driver = await env.builder().setFirefoxOptions(options).build()
45
})
46
47
it('can get context', async function () {
48
assert.strictEqual(await driver.getContext(), Context.CONTENT)
49
})
50
51
it('can set context', async function () {
52
await driver.setContext(Context.CHROME)
53
let ctxt = await driver.getContext()
54
assert.strictEqual(ctxt, Context.CHROME)
55
56
await driver.setContext(Context.CONTENT)
57
ctxt = await driver.getContext()
58
assert.strictEqual(ctxt, Context.CONTENT)
59
})
60
61
it('throws on unknown context', function () {
62
return driver.setContext('foo').then(assert.fail, function (e) {
63
assert(e instanceof error.InvalidArgumentError)
64
})
65
})
66
})
67
})
68
},
69
{ browsers: [Browser.FIREFOX] },
70
)
71
72