From 85a785684d8ce37f99cb64c22597c44021d6fb34 Mon Sep 17 00:00:00 2001 From: TamsilAmani Date: Mon, 13 Jun 2022 16:43:49 +0530 Subject: [PATCH] [JS] Fix: using fulfillRequest when intercepting --- .../node/selenium-webdriver/lib/webdriver.js | 9 +- .../selenium-webdriver/test/devtools_test.js | 114 +++++++++--------- 2 files changed, 63 insertions(+), 60 deletions(-) diff --git a/javascript/node/selenium-webdriver/lib/webdriver.js b/javascript/node/selenium-webdriver/lib/webdriver.js index 1a5a37b6243d3..fdcde178f33b8 100644 --- a/javascript/node/selenium-webdriver/lib/webdriver.js +++ b/javascript/node/selenium-webdriver/lib/webdriver.js @@ -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 { diff --git a/javascript/node/selenium-webdriver/test/devtools_test.js b/javascript/node/selenium-webdriver/test/devtools_test.js index ba1ac33bc5ae9..579b408ae3448 100644 --- a/javascript/node/selenium-webdriver/test/devtools_test.js +++ b/javascript/node/selenium-webdriver/test/devtools_test.js @@ -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) @@ -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') @@ -150,5 +154,5 @@ suite( ) }) }, - { browsers: ['firefox'] } + { browsers: ['firefox', 'chrome'] } )