Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: move more unsupported apis to interception (#91)
Pavel Feldmanc7a07ea2a8db
diff --git a/docs/api.md b/docs/api.mdindex 5e84034786..c9b4735cf5 100644--- a/docs/api.md+++ b/docs/api.md@@ -88,7 +88,6 @@* [page.accessibility](#pageaccessibility)* [page.addScriptTag(options)](#pageaddscripttagoptions)* [page.addStyleTag(options)](#pageaddstyletagoptions)- * [page.authenticate(credentials)](#pageauthenticatecredentials)* [page.browser()](#pagebrowser)* [page.browserContext()](#pagebrowsercontext)* [page.click(selector[, options])](#pageclickselector-options)@@ -127,7 +126,6 @@* [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout)* [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders)* [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)- * [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled)* [page.setUserAgent(userAgent)](#pagesetuseragentuseragent)* [page.setViewport(viewport)](#pagesetviewportviewport)* [page.target()](#pagetarget)@@ -232,10 +230,12 @@* [executionContext.frame()](#executioncontextframe)- [class: Interception](#class-interception)* [interception.abort(request, [errorCode])](#interceptionabortrequest-errorcode)+ * [interception.authenticate(credentials)](#interceptionauthenticatecredentials)* [interception.continue(request, [overrides])](#interceptioncontinuerequest-overrides)* [interception.disable()](#interceptiondisable)* [interception.enable()](#interceptionenable)* [interception.fulfill(request, response)](#interceptionfulfillrequest-response)+ * [interception.setOfflineMode(enabled)](#interceptionsetofflinemodeenabled)- [class: JSHandle](#class-jshandle)* [jsHandle.asElement()](#jshandleaselement)* [jsHandle.dispose()](#jshandledispose)@@ -1119,16 +1119,6 @@ Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<sShortcut for [page.mainFrame().addStyleTag(options)](#frameaddstyletagoptions).-#### page.authenticate(credentials)-- `credentials` <?[Object]>- - `username` <[string]>- - `password` <[string]>-- returns: <[Promise]>--Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).--To disable authentication, pass `null`.-#### page.browser()- returns: <[Browser]>@@ -1676,10 +1666,6 @@ The extra HTTP headers will be sent with every request the page initiates.> **NOTE** changing this value won't affect scripts that have already been run. It will take full effect on the next [navigation](#pagegotourl-options).-#### page.setOfflineMode(enabled)-- `enabled` <[boolean]> When `true`, enables offline mode for the page.-- returns: <[Promise]>-#### page.setUserAgent(userAgent)- `userAgent` <[string]> Specific user agent to use in this page- returns: <[Promise]> Promise which resolves when the user agent is set.@@ -3111,6 +3097,16 @@ await resultHandle.dispose();Aborts request. To use this, request interception should be enabled with `page.interception.enable()`.Exception is immediately thrown if the request interception is not enabled.+#### interception.authenticate(credentials)+- `credentials` <?[Object]>+ - `username` <[string]>+ - `password` <[string]>+- returns: <[Promise]>++Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).++To disable authentication, pass `null`.+#### interception.continue(request, [overrides])- `request` <[Request]>- `overrides` <[Object]> Optional request overwrites, which can be one of the following:@@ -3195,6 +3191,9 @@ page.on('request', request => {> **NOTE** Mocking responses for dataURL requests is not supported.> Calling `request.respond` for a dataURL request is a noop.+#### interception.setOfflineMode(enabled)+- `enabled` <[boolean]> When `true`, enables offline mode for the page.+- returns: <[Promise]>### class: JSHandlediff --git a/src/chromium/Page.ts b/src/chromium/Page.tsindex 2e7b76c180..de469d8c45 100644--- a/src/chromium/Page.ts+++ b/src/chromium/Page.ts@@ -217,10 +217,6 @@ export class Page extends EventEmitter {return this._frameManager.frames();}- setOfflineMode(enabled: boolean) {- return this._frameManager.networkManager().setOfflineMode(enabled);- }-setDefaultNavigationTimeout(timeout: number) {this._timeoutSettings.setDefaultNavigationTimeout(timeout);}@@ -290,10 +286,6 @@ export class Page extends EventEmitter {}}- async authenticate(credentials: { username: string; password: string; } | null) {- return this._frameManager.networkManager().authenticate(credentials);- }-async setExtraHTTPHeaders(headers: { [s: string]: string; }) {return this._frameManager.networkManager().setExtraHTTPHeaders(headers);}diff --git a/src/chromium/features/coverage.spec.js b/src/chromium/features/coverage.spec.jsindex aee11c12a7..97fd005de3 100644--- a/src/chromium/features/coverage.spec.js+++ b/src/chromium/features/coverage.spec.js@@ -109,8 +109,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {expect(coverage.length).toBe(0);});});- // @see https://crbug.com/990945- xit('should not hang when there is a debugger statement', async function({page, server}) {+ it('should not hang when there is a debugger statement', async function({page, server}) {await page.coverage.startJSCoverage();await page.goto(server.EMPTY_PAGE);await page.evaluate(() => {diff --git a/src/chromium/features/coverage.ts b/src/chromium/features/coverage.tsindex 93616d2cf5..b089e21e76 100644--- a/src/chromium/features/coverage.ts+++ b/src/chromium/features/coverage.ts@@ -92,6 +92,7 @@ class JSCoverage {helper.addEventListener(this._client, 'Debugger.scriptParsed', this._onScriptParsed.bind(this)),helper.addEventListener(this._client, 'Runtime.executionContextsCleared', this._onExecutionContextsCleared.bind(this)),];+ this._client.on('Debugger.paused', () => this._client.send('Debugger.resume'));await Promise.all([this._client.send('Profiler.enable'),this._client.send('Profiler.startPreciseCoverage', {callCount: false, detailed: true}),diff --git a/src/chromium/features/interception.ts b/src/chromium/features/interception.tsindex 23998ea346..c71279cbe7 100644--- a/src/chromium/features/interception.ts+++ b/src/chromium/features/interception.ts@@ -29,4 +29,12 @@ export class Interception {async abort(request: Request, errorCode: string = 'failed') {return request._abort(errorCode);}++ setOfflineMode(enabled: boolean) {+ return this._networkManager.setOfflineMode(enabled);+ }++ async authenticate(credentials: { username: string; password: string; } | null) {+ return this._networkManager.authenticate(credentials);+ }}diff --git a/test/headful.spec.js b/test/headful.spec.jsindex ef658f02fe..d606fc8319 100644--- a/test/headful.spec.js+++ b/test/headful.spec.js@@ -94,7 +94,7 @@ module.exports.addTests = function({testRunner, expect, playwright, defaultBrowsconst page = await browser.newPage();await page.goto(server.EMPTY_PAGE);await page.interception.enable();- page.on('request', r => r.respond({body: 'YO, GOOGLE.COM'}));+ page.on('request', r => page.interception.fulfill(r, {body: 'YO, GOOGLE.COM'}));await page.evaluate(() => {const frame = document.createElement('iframe');frame.setAttribute('src', 'https://google.com/');diff --git a/test/network.spec.js b/test/network.spec.jsindex 6de0a9c90f..ae1cad06d3 100644--- a/test/network.spec.js+++ b/test/network.spec.js@@ -358,12 +358,12 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {});// FIXME: WebKit doesn't support network interception.- describe.skip(FFOX || WEBKIT)('Page.authenticate', function() {+ describe.skip(FFOX || WEBKIT)('Interception.authenticate', function() {it('should work', async({page, server}) => {server.setAuth('/empty.html', 'user', 'pass');let response = await page.goto(server.EMPTY_PAGE);expect(response.status()).toBe(401);- await page.authenticate({+ await page.interception.authenticate({username: 'user',password: 'pass'});@@ -373,7 +373,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {it('should fail if wrong credentials', async({page, server}) => {// Use unique user/password since Chrome caches credentials per origin.server.setAuth('/empty.html', 'user2', 'pass2');- await page.authenticate({+ await page.interception.authenticate({username: 'foo',password: 'bar'});@@ -383,13 +383,13 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {it('should allow disable authentication', async({page, server}) => {// Use unique user/password since Chrome caches credentials per origin.server.setAuth('/empty.html', 'user3', 'pass3');- await page.authenticate({+ await page.interception.authenticate({username: 'user3',password: 'pass3'});let response = await page.goto(server.EMPTY_PAGE);expect(response.status()).toBe(200);- await page.authenticate(null);+ await page.interception.authenticate(null);// Navigate to a different origin to bust Chrome's credential caching.response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');expect(response.status()).toBe(401);diff --git a/test/page.spec.js b/test/page.spec.jsindex 9ef89c0fde..ca678a37c7 100644--- a/test/page.spec.js+++ b/test/page.spec.js@@ -166,21 +166,21 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF});});- describe.skip(FFOX || WEBKIT)('Page.setOfflineMode', function() {+ describe.skip(FFOX || WEBKIT)('Interception.setOfflineMode', function() {it('should work', async({page, server}) => {- await page.setOfflineMode(true);+ await page.interception.setOfflineMode(true);let error = null;await page.goto(server.EMPTY_PAGE).catch(e => error = e);expect(error).toBeTruthy();- await page.setOfflineMode(false);+ await page.interception.setOfflineMode(false);const response = await page.reload();expect(response.status()).toBe(200);});it('should emulate navigator.onLine', async({page, server}) => {expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);- await page.setOfflineMode(true);+ await page.interception.setOfflineMode(true);expect(await page.evaluate(() => window.navigator.onLine)).toBe(false);- await page.setOfflineMode(false);+ await page.interception.setOfflineMode(false);expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);});});