feat(trace): record trace during context option fixture override

This commit is contained in:
Dmitry Gozman 2024-05-20 09:05:21 -07:00
parent 4ad94c1a8c
commit 71d315f497
2 changed files with 51 additions and 0 deletions

View file

@ -148,6 +148,13 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
contextOptions: [{}, { option: true }],
_combinedContextOptions: async ({
// Note: we depend on _setupArtifacts here to make sure artifacts are recorded
// for any custom context option fixture function.
//
// For example, "once per worker" authentication guide suggests to make the `storageState` fixture
// dependent on a worker-scoped `workerStorageState` fixture. The latter performs some actions that
// should be visible in the trace.
_setupArtifacts,
acceptDownloads,
bypassCSP,
colorScheme,

View file

@ -1112,3 +1112,47 @@ test('trace:retain-on-first-failure should create trace if request context is di
expect(trace.apiNames).toContain('apiRequestContext.get');
expect(result.failed).toBe(1);
});
test('should record trace in workerStorageState', async ({ runInlineTest, server }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30287' });
const result = await runInlineTest({
'a.spec.ts': `
import { test as base, expect } from '@playwright/test';
const test = base.extend({
storageState: ({ workerStorageState }, use) => use(workerStorageState),
workerStorageState: [async ({ browser }, use) => {
const page = await browser.newPage({ storageState: undefined });
await page.setContent('<div>hello</div>');
await page.close();
await use(undefined);
}, { scope: 'worker' }],
})
test('pass', async ({ page }) => {
await page.goto('data:text/html,<div>hi</div>');
});
`,
}, { trace: 'on' });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
const tracePath = test.info().outputPath('test-results', 'a-pass', 'trace.zip');
const trace = await parseTrace(tracePath);
expect(trace.actionTree).toEqual([
'Before Hooks',
' fixture: browser',
' browserType.launch',
' fixture: workerStorageState',
' browser.newPage',
' page.setContent',
' page.close',
' fixture: context',
' browser.newContext',
' fixture: page',
' browserContext.newPage',
'page.goto',
'After Hooks',
' fixture: page',
' fixture: context',
]);
});