Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bidi] [js] Add auth related commands #13572

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions javascript/node/selenium-webdriver/bidi/network.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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]},
)
Loading