Path: blob/trunk/javascript/selenium-webdriver/test/bidi/add_intercept_parameters_test.js
2887 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 { Browser } = require('selenium-webdriver')21const { suite } = require('../../lib/test')22const { Network } = require('selenium-webdriver/bidi/network')23const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')24const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')25const { UrlPattern } = require('selenium-webdriver/bidi/urlPattern')2627suite(28function (env) {29let driver30let network3132beforeEach(async function () {33driver = await env.builder().build()34network = await Network(driver)35})3637afterEach(async function () {38await network.close()39await driver.quit()40})4142describe('Add Intercept parameters test', function () {43it('can add intercept phase', async function () {44const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))45assert.notEqual(intercept, null)46})4748it('can add intercept phases', async function () {49const intercept = await network.addIntercept(50new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED, InterceptPhase.BEFORE_REQUEST_SENT),51)52assert.notEqual(intercept, null)53})5455it('can add string url pattern', async function () {56const intercept = await network.addIntercept(57new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlStringPattern(58'http://localhost:4444/basicAuth',59),60)61assert.notEqual(intercept, null)62})6364it('can add string url patterns', async function () {65const intercept = await network.addIntercept(66new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlStringPatterns([67'http://localhost:4444/basicAuth',68'http://localhost:4445/logEntryAdded',69]),70)71assert.notEqual(intercept, null)72})7374it('can add url pattern', async function () {75const urlPattern = new UrlPattern().protocol('http').hostname('localhost').port(4444).pathname('basicAuth')76const intercept = await network.addIntercept(77new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlPattern(urlPattern),78)79assert.notEqual(intercept, null)80})8182it('can add url patterns', async function () {83const urlPattern1 = new UrlPattern()84.protocol('http')85.hostname('localhost')86.port(4444)87.pathname('logEntryAdded')88.search('')8990const urlPattern2 = new UrlPattern()91.protocol('https')92.hostname('localhost')93.port(4445)94.pathname('basicAuth')95.search('auth')9697const intercept = await network.addIntercept(98new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlPatterns([urlPattern1, urlPattern2]),99)100assert.notEqual(intercept, null)101})102})103},104{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },105)106107108