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
fix(test runner): collect artifacts when calling `browser.close()` (#14797)
Dmitry Gozmanc7a28ac7e9ea
diff --git a/packages/playwright-core/src/client/browser.ts b/packages/playwright-core/src/client/browser.tsindex 077f8c1902..0c5599e660 100644--- a/packages/playwright-core/src/client/browser.ts+++ b/packages/playwright-core/src/client/browser.ts@@ -104,6 +104,8 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements apasync close(): Promise<void> {try {+ for (const context of this.contexts())+ await this._browserType?._onWillCloseContext?.(context);if (this._shouldCloseConnectionOnClose)this._connection.close(kBrowserClosedError);elsediff --git a/tests/playwright-test/playwright.trace.spec.ts b/tests/playwright-test/playwright.trace.spec.tsindex adcc69deb3..27a713a63d 100644--- a/tests/playwright-test/playwright.trace.spec.ts+++ b/tests/playwright-test/playwright.trace.spec.ts@@ -241,6 +241,27 @@ test('should not override trace file in afterAll', async ({ runInlineTest, serveexpect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace-1.zip'))).toBeTruthy();});+test('should record trace on manual browser closure', async ({ runInlineTest }, testInfo) => {+ const result = await runInlineTest({+ 'a.spec.ts': `+ const { test } = pwt;++ test.use({ trace: 'on' });++ test.afterAll(async ({ browser }) => {+ await browser.close();+ });++ test('test 1', async ({ page }) => {+ await page.goto('about:blank');+ });+ `,+ }, { workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+ expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBeTruthy();+});async function parseTrace(file: string): Promise<Map<string, Buffer>> {const zipFS = new ZipFileSystem(file);