Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/bidi/browser_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 { suite } = require('../../lib/test')
22
const { Browser } = require('selenium-webdriver')
23
const BrowserBiDi = require('selenium-webdriver/bidi/browser')
24
const { WindowState } = require('selenium-webdriver/bidi/browser')
25
26
suite(
27
function (env) {
28
let driver
29
30
beforeEach(async function () {
31
driver = await env.builder().build()
32
})
33
34
afterEach(function () {
35
return driver.quit()
36
})
37
38
describe('BiDi Browser', function () {
39
it('can create a user context', async function () {
40
const browser = await BrowserBiDi(driver)
41
42
const userContext = await browser.createUserContext()
43
44
assert.notEqual(userContext, null)
45
46
await browser.removeUserContext(userContext)
47
})
48
49
it('can get user contexts', async function () {
50
const browser = await BrowserBiDi(driver)
51
52
const userContext1 = await browser.createUserContext()
53
const userContext2 = await browser.createUserContext()
54
55
const userContexts = await browser.getUserContexts()
56
57
assert.strictEqual(userContexts.length >= 2, true)
58
59
await browser.removeUserContext(userContext1)
60
await browser.removeUserContext(userContext2)
61
})
62
63
it('can remove user context', async function () {
64
const browser = await BrowserBiDi(driver)
65
66
const userContext1 = await browser.createUserContext()
67
const userContext2 = await browser.createUserContext()
68
69
const userContexts = await browser.getUserContexts()
70
71
assert.strictEqual(userContexts.length >= 2, true)
72
73
await browser.removeUserContext(userContext2)
74
75
const updatedUserContexts = await browser.getUserContexts()
76
77
assert.strictEqual(updatedUserContexts.includes(userContext1), true)
78
assert.strictEqual(updatedUserContexts.includes(userContext2), false)
79
80
await browser.removeUserContext(userContext1)
81
})
82
})
83
84
describe('Client Windows', function () {
85
it('can get client windows', async function () {
86
const browser = await BrowserBiDi(driver)
87
const windows = await browser.getClientWindows()
88
89
assert(Array.isArray(windows))
90
assert(windows.length > 0)
91
92
const window = windows[0]
93
assert(window.clientWindow)
94
assert(Object.values(WindowState).includes(window.state))
95
assert(Number.isInteger(window.width) && window.width > 0)
96
assert(Number.isInteger(window.height) && window.height > 0)
97
assert(Number.isInteger(window.x))
98
assert(Number.isInteger(window.y))
99
assert(typeof window.active === 'boolean')
100
})
101
})
102
},
103
{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },
104
)
105
106