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: fix ui mode w/ multiple contexts (#22514)
Pavel Feldman0c70f6900e64
diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.tsindex 21d741d627..249b1af9d1 100644--- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts+++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts@@ -128,9 +128,8 @@ function traceDescriptor(traceName: string) {const traceDir = path.dirname(traceName);const traceFile = path.basename(traceName);for (const name of fs.readdirSync(traceDir)) {- // 23423423.trace => 23423423-trace.traceif (name.startsWith(traceFile))- result.entries.push({ name: name.replace(traceFile, traceFile + '-trace'), path: path.join(traceDir, name) });+ result.entries.push({ name, path: path.join(traceDir, name) });}const resourcesDir = path.join(traceDir, 'resources');diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex 206e05e06c..6e03c03878 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -397,7 +397,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({{(playwright.request as any)._onDidCreateContext = onDidCreateRequestContext;(playwright.request as any)._onWillCloseContext = onWillCloseRequestContext;- (playwright.request as any)._defaultContextOptions = _combinedContextOptions;+ (playwright.request as any)._defaultContextOptions = { ..._combinedContextOptions };+ (playwright.request as any)._defaultContextOptions.tracesDir = path.join(_artifactsDir(), 'traces');const existingApiRequests: APIRequestContext[] = Array.from((playwright.request as any)._contexts as Set<APIRequestContext>);await Promise.all(existingApiRequests.map(onDidCreateRequestContext));}diff --git a/packages/trace-viewer/src/traceModel.ts b/packages/trace-viewer/src/traceModel.tsindex 6c6eafcbe9..7fd1966b2e 100644--- a/packages/trace-viewer/src/traceModel.ts+++ b/packages/trace-viewer/src/traceModel.ts@@ -57,7 +57,7 @@ export class TraceModel {const ordinals: string[] = [];let hasSource = false;for (const entryName of await this._backend.entryNames()) {- const match = entryName.match(/(.+-)?trace\.trace/);+ const match = entryName.match(/(.+)\.trace/);if (match)ordinals.push(match[1] || '');if (entryName.includes('src@'))@@ -77,12 +77,12 @@ export class TraceModel {contextEntry.traceUrl = traceURL;contextEntry.hasSource = hasSource;- const trace = await this._backend.readText(ordinal + 'trace.trace') || '';+ const trace = await this._backend.readText(ordinal + '.trace') || '';for (const line of trace.split('\n'))this.appendEvent(contextEntry, actionMap, line);unzipProgress(++done, total);- const network = await this._backend.readText(ordinal + 'trace.network') || '';+ const network = await this._backend.readText(ordinal + '.network') || '';for (const line of network.split('\n'))this.appendEvent(contextEntry, actionMap, line);unzipProgress(++done, total);@@ -95,7 +95,7 @@ export class TraceModel {}}- const stacks = await this._backend.readText(ordinal + 'trace.stacks');+ const stacks = await this._backend.readText(ordinal + '.stacks');if (stacks) {const callMetadata = parseClientSideCallMetadata(JSON.parse(stacks));for (const action of contextEntry.actions)diff --git a/tests/playwright-test/ui-mode-test-progress.spec.ts b/tests/playwright-test/ui-mode-test-progress.spec.tsindex 4c5d49d496..eb2fce07c9 100644--- a/tests/playwright-test/ui-mode-test-progress.spec.ts+++ b/tests/playwright-test/ui-mode-test-progress.spec.ts@@ -209,3 +209,36 @@ test('should update tracing network live', async ({ runUITest, server }) => {'verify background').toHaveCSS('background-color', 'rgb(255, 0, 0)', { timeout: 15000 });});++test('should show trace w/ multiple contexts', async ({ runUITest, server, createLatch }) => {+ const latch = createLatch();++ const { page } = await runUITest({+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';+ test.beforeEach(async ({ request }) => {+ await request.get('${server.EMPTY_PAGE}');+ });+ test('live test', async ({ page }) => {+ await page.goto('about:blank');+ ${latch.blockingCode}+ });+ `,+ });++ // Start test.+ await page.getByText('live test').dblclick();++ // It should wait on the latch.+ const listItem = page.getByTestId('action-list').getByRole('listitem');+ await expect(+ listItem,+ 'action list'+ ).toHaveText([+ /apiRequestContext.get[\d.]+m?s/,+ /browserContext.newPage[\d.]+m?s/,+ /page.gotoabout:blank[\d.]+m?s/,+ ], { timeout: 15000 });++ latch.open();+});