Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/bidi/add_intercept_parameters_test.js
2887 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 { suite } = require('../../lib/test')
23
const { Network } = require('selenium-webdriver/bidi/network')
24
const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')
25
const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')
26
const { UrlPattern } = require('selenium-webdriver/bidi/urlPattern')
27
28
suite(
29
function (env) {
30
let driver
31
let network
32
33
beforeEach(async function () {
34
driver = await env.builder().build()
35
network = await Network(driver)
36
})
37
38
afterEach(async function () {
39
await network.close()
40
await driver.quit()
41
})
42
43
describe('Add Intercept parameters test', function () {
44
it('can add intercept phase', async function () {
45
const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))
46
assert.notEqual(intercept, null)
47
})
48
49
it('can add intercept phases', async function () {
50
const intercept = await network.addIntercept(
51
new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED, InterceptPhase.BEFORE_REQUEST_SENT),
52
)
53
assert.notEqual(intercept, null)
54
})
55
56
it('can add string url pattern', async function () {
57
const intercept = await network.addIntercept(
58
new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlStringPattern(
59
'http://localhost:4444/basicAuth',
60
),
61
)
62
assert.notEqual(intercept, null)
63
})
64
65
it('can add string url patterns', async function () {
66
const intercept = await network.addIntercept(
67
new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlStringPatterns([
68
'http://localhost:4444/basicAuth',
69
'http://localhost:4445/logEntryAdded',
70
]),
71
)
72
assert.notEqual(intercept, null)
73
})
74
75
it('can add url pattern', async function () {
76
const urlPattern = new UrlPattern().protocol('http').hostname('localhost').port(4444).pathname('basicAuth')
77
const intercept = await network.addIntercept(
78
new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlPattern(urlPattern),
79
)
80
assert.notEqual(intercept, null)
81
})
82
83
it('can add url patterns', async function () {
84
const urlPattern1 = new UrlPattern()
85
.protocol('http')
86
.hostname('localhost')
87
.port(4444)
88
.pathname('logEntryAdded')
89
.search('')
90
91
const urlPattern2 = new UrlPattern()
92
.protocol('https')
93
.hostname('localhost')
94
.port(4445)
95
.pathname('basicAuth')
96
.search('auth')
97
98
const intercept = await network.addIntercept(
99
new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlPatterns([urlPattern1, urlPattern2]),
100
)
101
assert.notEqual(intercept, null)
102
})
103
})
104
},
105
{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },
106
)
107
108