chore: fix ui mode w/ multiple contexts (#22514)

Fixes: https://github.com/microsoft/playwright/issues/21895
This commit is contained in:
Pavel Feldman 2023-04-20 08:19:00 -07:00 committed by GitHub
parent cdaccdeaf7
commit 0c70f6900e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 7 deletions

View File

@ -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.trace
if (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');

View File

@ -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));
}

View File

@ -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)

View File

@ -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();
});