feat(trace): record trace during context option fixture override
This commit is contained in:
parent
4ad94c1a8c
commit
71d315f497
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue