Skip to content

Commit

Permalink
[bidi] [js] Add auth related commands (#13572)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Feb 13, 2024
1 parent 587c8ac commit 4eeeba7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
31 changes: 31 additions & 0 deletions javascript/node/selenium-webdriver/bidi/network.js
Expand Up @@ -107,6 +107,37 @@ class Network {

await this.bidi.send(command)
}

async continueWithAuthNoCredentials(requestId) {
const command = {
method: 'network.continueWithAuth',
params: {
request: requestId.toString(),
action: 'default'
},
}
await this.bidi.send(command)
}

async cancelAuth(requestId) {
const command = {
method: 'network.continueWithAuth',
params: {
request: requestId.toString(),
action: 'cancel'
},
}
await this.bidi.send(command)
}

async close() {
await this.bidi.unsubscribe(
'network.beforeRequestSent',
'network.responseStarted',
'network.responseCompleted',
'network.authRequired')
}

}

async function getNetworkInstance(driver, browsingContextIds = null) {
Expand Down
Expand Up @@ -20,29 +20,33 @@
const assert = require('assert')
const firefox = require('../../firefox')
const {Browser, By, WebElement} = require('../../')
const { suite } = require('../../lib/test')
const { Pages, suite } = require('../../lib/test')
const Network = require('../../bidi/network')
const {AddInterceptParameters} = require("../../bidi/addInterceptParameters");
const {InterceptPhase} = require("../../bidi/interceptPhase");
const {until} = require("../../index");

suite(
function (env) {
let driver
let network

beforeEach(async function () {
driver = await env
.builder()
.setFirefoxOptions(new firefox.Options().enableBidi())
.build()

network = await Network(driver)
})

afterEach(async function () {
await network.close()
await driver.quit()
})

describe('Network commands', function () {
xit('can add intercept', async function () {
const network = await Network(driver)
const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))
assert.notEqual(intercept, null)
})
Expand All @@ -54,8 +58,37 @@ suite(

await network.removeIntercept(intercept)
})
})

xit('can continue without auth credentials ', async function () {
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))

await network.authRequired(async (event) => {
await network.continueWithAuthNoCredentials(event.request.request)
})

await driver.get(Pages.basicAuth)
const alert = await driver.wait(until.alertIsPresent())
await alert.dismiss()

await driver.wait(until.elementLocated(By.css('pre')))
let source = await driver.getPageSource()
assert.equal(source.includes('Access denied'), true)
})

xit('can cancel auth ', async function () {
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))

await network.authRequired(async (event) => {
await network.cancelAuth(event.request.request)
})
try {
const alert = await driver.wait(until.alertIsPresent(), 3000)
assert.fail("Alert should not be present")
} catch (e) {
assert.strictEqual(e.name, 'TimeoutError')
}
})
})
},
{browsers: [Browser.FIREFOX]}
{browsers: [Browser.FIREFOX]},
)

0 comments on commit 4eeeba7

Please sign in to comment.