Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/bidi/bidi_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 { Browser } = require('selenium-webdriver')
22
const { Pages, suite } = require('../../lib/test')
23
const logInspector = require('selenium-webdriver/bidi/logInspector')
24
const BrowsingContext = require('selenium-webdriver/bidi/browsingContext')
25
const until = require('selenium-webdriver/lib/until')
26
27
suite(
28
function (env) {
29
let driver
30
let inspector
31
32
beforeEach(async function () {
33
driver = await env.builder().build()
34
inspector = await logInspector(driver)
35
})
36
37
afterEach(async function () {
38
await inspector.close()
39
await driver.quit()
40
})
41
42
describe('Integration Tests', function () {
43
it('can navigate and listen to errors', async function () {
44
let logEntry = null
45
46
await inspector.onJavascriptException(function (log) {
47
logEntry = log
48
})
49
50
const id = await driver.getWindowHandle()
51
const browsingContext = await BrowsingContext(driver, {
52
browsingContextId: id,
53
})
54
const info = await browsingContext.navigate(Pages.logEntryAdded)
55
56
assert.notEqual(browsingContext.id, null)
57
assert.notEqual(info.navigationId, null)
58
assert(info.url.includes('/bidi/logEntryAdded.html'))
59
60
await driver.wait(until.urlIs(Pages.logEntryAdded))
61
await driver.findElement({ id: 'jsException' }).click()
62
63
assert.equal(logEntry.text, 'Error: Not working')
64
assert.equal(logEntry.type, 'javascript')
65
assert.equal(logEntry.level, 'error')
66
67
await browsingContext.close()
68
})
69
})
70
},
71
{ browsers: [Browser.FIREFOX] },
72
)
73
74