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

[JS] Fix: using fulfillRequest when intercepting #10764

Merged
merged 2 commits into from
Jun 22, 2022
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
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'] }
)