Skip to content

Commit

Permalink
[JS] Fix: using fulfillRequest when intercepting (SeleniumHQ#10764)
Browse files Browse the repository at this point in the history
Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com>
  • Loading branch information
TamsilAmani and harsha509 authored Jun 22, 2022
1 parent 0c7bf07 commit 1d1e261
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 60 deletions.
9 changes: 4 additions & 5 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,12 +1368,11 @@ class WebDriver {
if (params.method === 'Fetch.requestPaused') {
const requestPausedParams = params['params']
if (requestPausedParams.request.url == httpResponse.urlToIntercept) {
connection.execute('Fetch.continueRequest', {
connection.execute('Fetch.fulfillRequest', {
requestId: requestPausedParams['requestId'],
url: httpResponse.urlToIntercept,
method: httpResponse.method,
headers: httpResponse.headers,
postData: httpResponse.body,
responseCode: 200,
responseHeaders: httpResponse.headers,
body: httpResponse.body,
})
callback()
} else {
Expand Down
114 changes: 59 additions & 55 deletions javascript/node/selenium-webdriver/test/devtools_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,75 +34,79 @@ suite(
})
after(async () => await driver.quit())

it('sends Page.enable command using devtools', async function () {
const cdpConnection = await driver.createCDPConnection('page')
cdpConnection.execute('Page.enable', {}, function (_res, err) {
assert(!err)
})
})

it('sends Network and Page command using devtools', async function () {
const cdpConnection = await driver.createCDPConnection('page')
cdpConnection.execute('Network.enable', {}, function (_res, err) {
assert(!err)
ignore(browsers(Browser.CHROME)).it(
'sends Page.enable command using devtools', async function () {
const cdpConnection = await driver.createCDPConnection('page')
cdpConnection.execute('Page.enable', {}, function (_res, err) {
assert(!err)
})
})

cdpConnection.execute(
'Page.navigate',
{ url: 'chrome://newtab/' },
function (_res, err) {
ignore(browsers(Browser.CHROME)).it(
'sends Network and Page command using devtools', async function () {
const cdpConnection = await driver.createCDPConnection('page')
cdpConnection.execute('Network.enable', {}, function (_res, err) {
assert(!err)
}
)
})
})

cdpConnection.execute(
'Page.navigate',
{ url: 'chrome://newtab/' },
function (_res, err) {
assert(!err)
}
)
})

describe('JS CDP events', function () {
it('calls the event listener for console.log', async function () {
const cdpConnection = await driver.createCDPConnection('page')
await driver.onLogEvent(cdpConnection, function (event) {
assert.strictEqual(event['args'][0]['value'], 'here')
ignore(browsers(Browser.CHROME)).it(
'calls the event listener for console.log', async function () {
const cdpConnection = await driver.createCDPConnection('page')
await driver.onLogEvent(cdpConnection, function (event) {
assert.strictEqual(event['args'][0]['value'], 'here')
})
await driver.executeScript('console.log("here")')
})
await driver.executeScript('console.log("here")')
})

it('calls the event listener for js exceptions', async function () {
const cdpConnection = await driver.createCDPConnection('page')
await driver.onLogException(cdpConnection, function (event) {
assert.strictEqual(
event['exceptionDetails']['stackTrace']['callFrames'][0][
'functionName'
],
'onmouseover'
)
ignore(browsers(Browser.CHROME)).it(
'calls the event listener for js exceptions', async function () {
const cdpConnection = await driver.createCDPConnection('page')
await driver.onLogException(cdpConnection, function (event) {
assert.strictEqual(
event['exceptionDetails']['stackTrace']['callFrames'][0][
'functionName'
],
'onmouseover'
)
})
await driver.get(Pages.javascriptPage)
let element = driver.findElement({ id: 'throwing-mouseover' })
await element.click()
})
await driver.get(Pages.javascriptPage)
let element = driver.findElement({ id: 'throwing-mouseover' })
await element.click()
})
})

describe('JS DOM events', function () {
it('calls the event listener on dom mutations', async function () {
const cdpConnection = await driver.createCDPConnection('page')
await driver.logMutationEvents(cdpConnection, function (event) {
assert.strictEqual(event['attribute_name'], 'style')
assert.strictEqual(event['current_value'], '')
assert.strictEqual(event['old_value'], 'display:none;')
})
ignore(browsers(Browser.CHROME)).it(
'calls the event listener on dom mutations', async function () {
const cdpConnection = await driver.createCDPConnection('page')
await driver.logMutationEvents(cdpConnection, function (event) {
assert.strictEqual(event['attribute_name'], 'style')
assert.strictEqual(event['current_value'], '')
assert.strictEqual(event['old_value'], 'display:none;')
})

await driver.get(fileServer.Pages.dynamicPage)
await driver.get(fileServer.Pages.dynamicPage)

let element = driver.findElement({ id: 'reveal' })
await element.click()
let revealed = driver.findElement({ id: 'revealed' })
await driver.wait(until.elementIsVisible(revealed), 5000)
})
let element = driver.findElement({ id: 'reveal' })
await element.click()
let revealed = driver.findElement({ id: 'revealed' })
await driver.wait(until.elementIsVisible(revealed), 5000)
})
})

describe('Basic Auth Injection', function () {
ignore(browsers(Browser.SAFARI, Browser.FIREFOX)).it(
'denies entry if username and password do not match',
async function () {
ignore(browsers(Browser.SAFARI, Browser.FIREFOX, Browser.CHROME)).it(
'denies entry if username and password do not match', async function () {
const pageCdpConnection = await driver.createCDPConnection('page')

await driver.register('random', 'random', pageCdpConnection)
Expand All @@ -115,7 +119,7 @@ suite(
}
)

ignore(browsers(Browser.SAFARI, Browser.FIREFOX)).it(
ignore(browsers(Browser.SAFARI, Browser.FIREFOX, Browser.CHROME)).it(
'grants access if username and password are a match',
async function () {
const pageCdpConnection = await driver.createCDPConnection('page')
Expand Down Expand Up @@ -150,5 +154,5 @@ suite(
)
})
},
{ browsers: ['firefox'] }
{ browsers: ['firefox', 'chrome'] }
)

0 comments on commit 1d1e261

Please sign in to comment.