fix(trace): afterAll hook should not break tracing with reused context (#33616)
This commit is contained in:
parent
f5477d9051
commit
eaf3536014
|
|
@ -618,9 +618,10 @@ class ArtifactsRecorder {
|
||||||
if (captureScreenshots)
|
if (captureScreenshots)
|
||||||
await this._screenshotOnTestFailure();
|
await this._screenshotOnTestFailure();
|
||||||
|
|
||||||
const leftoverContexts: BrowserContext[] = [];
|
let leftoverContexts: BrowserContext[] = [];
|
||||||
for (const browserType of [this._playwright.chromium, this._playwright.firefox, this._playwright.webkit])
|
for (const browserType of [this._playwright.chromium, this._playwright.firefox, this._playwright.webkit])
|
||||||
leftoverContexts.push(...(browserType as any)._contexts);
|
leftoverContexts.push(...(browserType as any)._contexts);
|
||||||
|
leftoverContexts = leftoverContexts.filter(context => !this._reusedContexts.has(context));
|
||||||
const leftoverApiRequests: APIRequestContext[] = Array.from((this._playwright.request as any)._contexts as Set<APIRequestContext>);
|
const leftoverApiRequests: APIRequestContext[] = Array.from((this._playwright.request as any)._contexts as Set<APIRequestContext>);
|
||||||
|
|
||||||
// Collect traces/screenshots for remaining contexts.
|
// Collect traces/screenshots for remaining contexts.
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,14 @@ test('should reuse context with trace if mode=when-possible', async ({ runInline
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
let lastContextGuid;
|
let lastContextGuid;
|
||||||
|
|
||||||
|
test.beforeAll(async () => {
|
||||||
|
console.log('fromBeforeAll');
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterAll(async () => {
|
||||||
|
console.log('fromAfterAll');
|
||||||
|
});
|
||||||
|
|
||||||
test('one', async ({ context, page }) => {
|
test('one', async ({ context, page }) => {
|
||||||
lastContextGuid = context._guid;
|
lastContextGuid = context._guid;
|
||||||
await page.setContent('<button>Click</button>');
|
await page.setContent('<button>Click</button>');
|
||||||
|
|
@ -113,10 +121,13 @@ test('should reuse context with trace if mode=when-possible', async ({ runInline
|
||||||
|
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(2);
|
expect(result.passed).toBe(2);
|
||||||
|
expect(result.output).toContain('fromBeforeAll');
|
||||||
|
expect(result.output).toContain('fromAfterAll');
|
||||||
|
|
||||||
const trace1 = await parseTrace(testInfo.outputPath('test-results', 'reuse-one', 'trace.zip'));
|
const trace1 = await parseTrace(testInfo.outputPath('test-results', 'reuse-one', 'trace.zip'));
|
||||||
expect(trace1.actionTree).toEqual([
|
expect(trace1.actionTree).toEqual([
|
||||||
'Before Hooks',
|
'Before Hooks',
|
||||||
|
' beforeAll hook',
|
||||||
' fixture: browser',
|
' fixture: browser',
|
||||||
' browserType.launch',
|
' browserType.launch',
|
||||||
' fixture: context',
|
' fixture: context',
|
||||||
|
|
@ -143,6 +154,7 @@ test('should reuse context with trace if mode=when-possible', async ({ runInline
|
||||||
'After Hooks',
|
'After Hooks',
|
||||||
' fixture: page',
|
' fixture: page',
|
||||||
' fixture: context',
|
' fixture: context',
|
||||||
|
' afterAll hook',
|
||||||
]);
|
]);
|
||||||
expect(trace2.traceModel.storage().snapshotsForTest().length).toBeGreaterThan(0);
|
expect(trace2.traceModel.storage().snapshotsForTest().length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue