Skip to content

Commit

Permalink
[bidi][js] Add auth required event
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Jan 3, 2024
1 parent 52f1625 commit 45da018
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions javascript/node/selenium-webdriver/bidi/networkInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class NetworkInspector {
await this.subscribeAndHandleEvent('network.responseCompleted', callback)
}

async authRequired(callback) {
await this.subscribeAndHandleEvent('network.authRequired', callback)
}

async subscribeAndHandleEvent(eventType, callback) {
if (this._browsingContextIds != null) {
await this.bidi.subscribe(eventType, this._browsingContextIds)
Expand Down
24 changes: 24 additions & 0 deletions javascript/node/selenium-webdriver/test/bidi/bidi_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,30 @@ suite(
)
assert(onResponseCompleted[0].response.mimeType.includes('text/plain'))
})
// Implemented in Firefox Nightly 123
xit('can subscribe to auth required', async function () {
let onAuthRequired = []
const inspector = await NetworkInspector(driver)
await inspector.authRequired(function (event) {
onAuthRequired.push(event)
})

await driver.get(Pages.basicAuth)

assert.equal(onAuthRequired[0].request.method, 'GET')
assert.equal(
onAuthRequired[0].request.url,
await driver.getCurrentUrl()
)
assert.equal(
onAuthRequired[0].response.url,
await driver.getCurrentUrl()
)
assert.equal(onAuthRequired[0].response.fromCache, false)
assert(onAuthRequired[0].response.mimeType.includes('text/plain'))
assert.equal(onAuthRequired[0].response.status, 401)
assert.equal(onAuthRequired[0].response.statusText, 'unauthorized')
})
})

describe('Integration Tests', function () {
Expand Down

0 comments on commit 45da018

Please sign in to comment.