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
test: fix debug-controller.spec (#36616)
Dmitry Gozman145e158e52e4
diff --git a/tests/library/debug-controller.spec.ts b/tests/library/debug-controller.spec.tsindex d08b4e8048..3fe102446d 100644--- a/tests/library/debug-controller.spec.ts+++ b/tests/library/debug-controller.spec.ts@@ -22,7 +22,7 @@ import type { Browser, BrowserContext } from '@playwright/test';import type * as channels from '@protocol/channels';import { roundBox } from '../page/pageTest';-type BrowserWithReuse = Browser & { _newContextForReuse: () => Promise<BrowserContext> };+type BrowserWithReuse = Browser & { newContextForReuse: () => Promise<BrowserContext> };type Fixtures = {wsEndpoint: string;backend: channels.DebugControllerChannel;@@ -55,6 +55,14 @@ const test = baseTest.extend<Fixtures>({},}) as BrowserWithReuse;browsers.push(browser);++ let context: BrowserContext | undefined;+ browser.newContextForReuse = async () => {+ if (context)+ await (browser as any)._disconnectFromReusedContext('reusedContext');+ context = await (browser as any)._newContextForReuse();+ return context;+ };return browser;});for (const browser of browsers)@@ -74,7 +82,7 @@ test('should pick element', async ({ backend, connectedBrowser }) => {await backend.setRecorderMode({ mode: 'inspecting' });- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const [page] = context.pages();await page.setContent('<button>Submit</button>');@@ -104,7 +112,7 @@ test('should report pages', async ({ backend, connectedBrowser }) => {backend.on('stateChanged', event => events.push(event));await backend.setReportStateChanged({ enabled: true });- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page1 = await context.newPage();const page2 = await context.newPage();await page1.close();@@ -128,7 +136,7 @@ test('should report pages', async ({ backend, connectedBrowser }) => {});test('should navigate all', async ({ backend, connectedBrowser }) => {- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page1 = await context.newPage();const page2 = await context.newPage();@@ -139,19 +147,24 @@ test('should navigate all', async ({ backend, connectedBrowser }) => {});test('should reset for reuse', async ({ backend, connectedBrowser }) => {- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page1 = await context.newPage();const page2 = await context.newPage();await backend.navigate({ url: 'data:text/plain,Hello world' });- const context2 = await connectedBrowser._newContextForReuse();+ const context2 = await connectedBrowser.newContextForReuse();+ expect(context2.pages().length).toBe(1);+ expect(context2.pages()[0]).not.toBe(page1);expect(await context2.pages()[0].evaluate(() => window.location.href)).toBe('about:blank');+ // Note: ideally, `page1` would be unaccessible, because it was disposed.+ // However, we currently do not check that, and since it keeps the same guid, sending+ // messages to the server keeps working.expect(await page1.evaluate(() => window.location.href)).toBe('about:blank');expect(await page2.evaluate(() => window.location.href).catch(e => e.message)).toContain('Target page, context or browser has been closed');});test('should highlight all', async ({ backend, connectedBrowser }) => {- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page1 = await context.newPage();const page2 = await context.newPage();await backend.navigate({ url: 'data:text/html,<button>Submit</button>' });@@ -169,7 +182,7 @@ test('should record', async ({ backend, connectedBrowser }) => {await backend.setRecorderMode({ mode: 'recording' });- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const [page] = context.pages();await page.setContent('<button>Submit</button>');@@ -206,7 +219,7 @@ test('should record custom data-testid', async ({ backend, connectedBrowser }) =backend.on('sourceChanged', event => events.push(event));// 1. "Show browser" (or "run test").- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page = await context.newPage();await page.setContent(`<div data-custom-id='one'>One</div>`);@@ -235,7 +248,7 @@ test('test', async ({ page }) => {test('should reset routes before reuse', async ({ server, connectedBrowserFactory }) => {const browser1 = await connectedBrowserFactory();- const context1 = await browser1._newContextForReuse();+ const context1 = await browser1.newContextForReuse();await context1.route(server.PREFIX + '/title.html', route => route.fulfill({ body: '<title>Hello</title>', contentType: 'text/html' }));const page1 = await context1.newPage();await page1.route(server.PREFIX + '/consolelog.html', route => route.fulfill({ body: '<title>World</title>', contentType: 'text/html' }));@@ -247,7 +260,7 @@ test('should reset routes before reuse', async ({ server, connectedBrowserFactorawait browser1.close();const browser2 = await connectedBrowserFactory();- const context2 = await browser2._newContextForReuse();+ const context2 = await browser2.newContextForReuse();const page2 = await context2.newPage();await page2.goto(server.PREFIX + '/title.html');@@ -260,7 +273,7 @@ test('should reset routes before reuse', async ({ server, connectedBrowserFactortest('should highlight inside iframe', async ({ backend, connectedBrowser }, testInfo) => {testInfo.annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33146' });- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page = await context.newPage();await backend.navigate({ url: `data:text/html,<div>bar</div><iframe srcdoc="<div>bar</div>"/>` });@@ -284,7 +297,7 @@ test('should highlight inside iframe', async ({ backend, connectedBrowser }, tes});test('should highlight aria template', async ({ backend, connectedBrowser }, testInfo) => {- const context = await connectedBrowser._newContextForReuse();+ const context = await connectedBrowser.newContextForReuse();const page = await context.newPage();await backend.navigate({ url: `data:text/html,<button>Submit</button>` });