Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(test runner): save traces for beforeAll/afterAll hooks (#10950)
Dmitry Gozman192071d5bc2c
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex e66c148090..a4c20b68a3 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -262,9 +262,8 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({// 3. Determine whether we need the artifacts.const testFailed = testInfo.status !== testInfo.expectedStatus;- const isHook = !!hookType(testInfo);- const preserveTrace = captureTrace && !isHook && (traceMode === 'on' || (testFailed && traceMode === 'retain-on-failure') || (traceMode === 'on-first-retry' && testInfo.retry === 1));- const captureScreenshots = !isHook && (screenshot === 'on' || (screenshot === 'only-on-failure' && testFailed));+ const preserveTrace = captureTrace && (traceMode === 'on' || (testFailed && traceMode === 'retain-on-failure') || (traceMode === 'on-first-retry' && testInfo.retry === 1));+ const captureScreenshots = (screenshot === 'on' || (screenshot === 'only-on-failure' && testFailed));const traceAttachments: string[] = [];const addTraceAttachment = () => {diff --git a/tests/playwright-test/playwright.artifacts.spec.ts b/tests/playwright-test/playwright.artifacts.spec.tsindex 572382a66c..a48788ed56 100644--- a/tests/playwright-test/playwright.artifacts.spec.ts+++ b/tests/playwright-test/playwright.artifacts.spec.ts@@ -145,6 +145,10 @@ test('should work with screenshot: on', async ({ runInlineTest }, testInfo) => {' test-failed-1.png','artifacts-persistent-passing',' test-finished-1.png',+ 'artifacts-shared-afterAll-worker0',+ ' test-finished-1.png',+ 'artifacts-shared-beforeAll-worker0',+ ' test-finished-1.png','artifacts-shared-shared-failing',' test-failed-1.png','artifacts-shared-shared-passing',@@ -210,6 +214,10 @@ test('should work with trace: on', async ({ runInlineTest }, testInfo) => {' trace.zip','artifacts-persistent-passing',' trace.zip',+ 'artifacts-shared-afterAll-worker0',+ ' trace.zip',+ 'artifacts-shared-beforeAll-worker0',+ ' trace.zip','artifacts-shared-shared-failing',' trace.zip','artifacts-shared-shared-passing',@@ -269,6 +277,8 @@ test('should work with trace: on-first-retry', async ({ runInlineTest }, testInf' trace.zip','artifacts-persistent-failing-retry1',' trace.zip',+ 'artifacts-shared-beforeAll-worker1-retry1',+ ' trace.zip','artifacts-shared-shared-failing-retry1',' trace.zip','artifacts-two-contexts-failing-retry1',diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.tsindex 524b229150..ed9d677d5e 100644--- a/tests/playwright-test/reporter-html.spec.ts+++ b/tests/playwright-test/reporter-html.spec.ts@@ -299,9 +299,12 @@ test('should render beforeAll/afterAll hooks', async ({ runInlineTest, page, shoconst result = await runInlineTest({'a.test.js': `const { test } = pwt;+ test.use({ trace: 'on' });test.beforeAll(async () => {});- test.afterAll(async () => {+ test.afterAll(async ({ browser }) => {+ const page = await browser.newPage();+ await page.close();await test.step('after step', () => {throw new Error('oh!');});@@ -328,6 +331,7 @@ test('should render beforeAll/afterAll hooks', async ({ runInlineTest, page, shoawait page.click('text=afterAll');await expect(page.locator('.tree-item:has-text("after step") svg.color-text-danger')).toHaveCount(1);+ await expect(page.locator('img')).toBeVisible();});test('should render text attachments as text', async ({ runInlineTest, page, showReport }) => {