From 5d5314e006ece4789a61a8303335a727159de582 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 31 May 2023 21:50:20 -0700 Subject: [PATCH] test: make sure trace is recorded for custom fixtures (#23418) References #23220. --- .../playwright-test/playwright.trace.spec.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/playwright-test/playwright.trace.spec.ts b/tests/playwright-test/playwright.trace.spec.ts index 418795d681..bd95a7c3aa 100644 --- a/tests/playwright-test/playwright.trace.spec.ts +++ b/tests/playwright-test/playwright.trace.spec.ts @@ -15,7 +15,7 @@ */ import { test, expect } from './playwright-test-fixtures'; -import { parseTrace } from '../config/utils'; +import { parseTrace, parseTraceRaw } from '../config/utils'; import fs from 'fs'; test.describe.configure({ mode: 'parallel' }); @@ -578,3 +578,32 @@ test('should opt out of attachments', async ({ runInlineTest, server }, testInfo expect(trace.actions[1].attachments).toEqual(undefined); expect([...trace.resources.keys()].filter(f => f.startsWith('resources/'))).toHaveLength(0); }); + +test('should record with custom page fixture', async ({ runInlineTest }, testInfo) => { + const result = await runInlineTest({ + 'a.spec.ts': ` + import { test as base, expect } from '@playwright/test'; + + const test = base.extend({ + myPage: async ({ browser }, use) => { + await use(await browser.newPage()); + }, + }); + + test.use({ trace: 'on' }); + + test('fails', async ({ myPage }, testInfo) => { + await myPage.setContent('hello'); + throw new Error('failure!'); + }); + `, + }, { workers: 1 }); + + expect(result.exitCode).toBe(1); + expect(result.failed).toBe(1); + expect(result.output).toContain('failure!'); + const trace = await parseTraceRaw(testInfo.outputPath('test-results', 'a-fails', 'trace.zip')); + expect(trace.events).toContainEqual(expect.objectContaining({ + type: 'frame-snapshot', + })); +});