Path: blob/trunk/javascript/selenium-webdriver/test/bidi/browser_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 { suite } = require('../../lib/test')21const { Browser } = require('selenium-webdriver')22const BrowserBiDi = require('selenium-webdriver/bidi/browser')23const { WindowState } = require('selenium-webdriver/bidi/browser')2425suite(26function (env) {27let driver2829beforeEach(async function () {30driver = await env.builder().build()31})3233afterEach(function () {34return driver.quit()35})3637describe('BiDi Browser', function () {38it('can create a user context', async function () {39const browser = await BrowserBiDi(driver)4041const userContext = await browser.createUserContext()4243assert.notEqual(userContext, null)4445await browser.removeUserContext(userContext)46})4748it('can get user contexts', async function () {49const browser = await BrowserBiDi(driver)5051const userContext1 = await browser.createUserContext()52const userContext2 = await browser.createUserContext()5354const userContexts = await browser.getUserContexts()5556assert.strictEqual(userContexts.length >= 2, true)5758await browser.removeUserContext(userContext1)59await browser.removeUserContext(userContext2)60})6162it('can remove user context', async function () {63const browser = await BrowserBiDi(driver)6465const userContext1 = await browser.createUserContext()66const userContext2 = await browser.createUserContext()6768const userContexts = await browser.getUserContexts()6970assert.strictEqual(userContexts.length >= 2, true)7172await browser.removeUserContext(userContext2)7374const updatedUserContexts = await browser.getUserContexts()7576assert.strictEqual(updatedUserContexts.includes(userContext1), true)77assert.strictEqual(updatedUserContexts.includes(userContext2), false)7879await browser.removeUserContext(userContext1)80})81})8283describe('Client Windows', function () {84it('can get client windows', async function () {85const browser = await BrowserBiDi(driver)86const windows = await browser.getClientWindows()8788assert(Array.isArray(windows))89assert(windows.length > 0)9091const window = windows[0]92assert(window.clientWindow)93assert(Object.values(WindowState).includes(window.state))94assert(Number.isInteger(window.width) && window.width > 0)95assert(Number.isInteger(window.height) && window.height > 0)96assert(Number.isInteger(window.x))97assert(Number.isInteger(window.y))98assert(typeof window.active === 'boolean')99})100})101},102{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },103)104105106