mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: fix ui mode w/ multiple contexts (#22514)
Fixes: https://github.com/microsoft/playwright/issues/21895
This commit is contained in:
parent
cdaccdeaf7
commit
0c70f6900e
@ -128,9 +128,8 @@ function traceDescriptor(traceName: string) {
|
|||||||
const traceDir = path.dirname(traceName);
|
const traceDir = path.dirname(traceName);
|
||||||
const traceFile = path.basename(traceName);
|
const traceFile = path.basename(traceName);
|
||||||
for (const name of fs.readdirSync(traceDir)) {
|
for (const name of fs.readdirSync(traceDir)) {
|
||||||
// 23423423.trace => 23423423-trace.trace
|
|
||||||
if (name.startsWith(traceFile))
|
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');
|
const resourcesDir = path.join(traceDir, 'resources');
|
||||||
|
|||||||
@ -397,7 +397,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
|||||||
{
|
{
|
||||||
(playwright.request as any)._onDidCreateContext = onDidCreateRequestContext;
|
(playwright.request as any)._onDidCreateContext = onDidCreateRequestContext;
|
||||||
(playwright.request as any)._onWillCloseContext = onWillCloseRequestContext;
|
(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>);
|
const existingApiRequests: APIRequestContext[] = Array.from((playwright.request as any)._contexts as Set<APIRequestContext>);
|
||||||
await Promise.all(existingApiRequests.map(onDidCreateRequestContext));
|
await Promise.all(existingApiRequests.map(onDidCreateRequestContext));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ export class TraceModel {
|
|||||||
const ordinals: string[] = [];
|
const ordinals: string[] = [];
|
||||||
let hasSource = false;
|
let hasSource = false;
|
||||||
for (const entryName of await this._backend.entryNames()) {
|
for (const entryName of await this._backend.entryNames()) {
|
||||||
const match = entryName.match(/(.+-)?trace\.trace/);
|
const match = entryName.match(/(.+)\.trace/);
|
||||||
if (match)
|
if (match)
|
||||||
ordinals.push(match[1] || '');
|
ordinals.push(match[1] || '');
|
||||||
if (entryName.includes('src@'))
|
if (entryName.includes('src@'))
|
||||||
@ -77,12 +77,12 @@ export class TraceModel {
|
|||||||
contextEntry.traceUrl = traceURL;
|
contextEntry.traceUrl = traceURL;
|
||||||
contextEntry.hasSource = hasSource;
|
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'))
|
for (const line of trace.split('\n'))
|
||||||
this.appendEvent(contextEntry, actionMap, line);
|
this.appendEvent(contextEntry, actionMap, line);
|
||||||
unzipProgress(++done, total);
|
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'))
|
for (const line of network.split('\n'))
|
||||||
this.appendEvent(contextEntry, actionMap, line);
|
this.appendEvent(contextEntry, actionMap, line);
|
||||||
unzipProgress(++done, total);
|
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) {
|
if (stacks) {
|
||||||
const callMetadata = parseClientSideCallMetadata(JSON.parse(stacks));
|
const callMetadata = parseClientSideCallMetadata(JSON.parse(stacks));
|
||||||
for (const action of contextEntry.actions)
|
for (const action of contextEntry.actions)
|
||||||
|
|||||||
@ -209,3 +209,36 @@ test('should update tracing network live', async ({ runUITest, server }) => {
|
|||||||
'verify background'
|
'verify background'
|
||||||
).toHaveCSS('background-color', 'rgb(255, 0, 0)', { timeout: 15000 });
|
).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();
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user