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
chore: set title from global teardown (#36433)
Simon Knott5efa0656964f
diff --git a/packages/playwright/src/reporters/html.ts b/packages/playwright/src/reporters/html.tsindex 297fa7849c..1b6ff2f2ad 100644--- a/packages/playwright/src/reporters/html.ts+++ b/packages/playwright/src/reporters/html.ts@@ -57,7 +57,6 @@ class HtmlReporter implements ReporterV2 {private _open: string | undefined;private _port: number | undefined;private _host: string | undefined;- private _title: string | undefined;private _buildResult: { ok: boolean, singleTestId: string | undefined } | undefined;private _topLevelErrors: api.TestError[] = [];@@ -78,13 +77,12 @@ class HtmlReporter implements ReporterV2 {}onBegin(suite: api.Suite) {- const { outputFolder, open, attachmentsBaseURL, host, port, title } = this._resolveOptions();+ const { outputFolder, open, attachmentsBaseURL, host, port } = this._resolveOptions();this._outputFolder = outputFolder;this._open = open;this._host = host;this._port = port;this._attachmentsBaseURL = attachmentsBaseURL;- this._title = title;const reportedWarnings = new Set<string>();for (const project of this.config.projects) {if (this._isSubdirectory(outputFolder, project.outputDir) || this._isSubdirectory(project.outputDir, outputFolder)) {@@ -104,7 +102,7 @@ class HtmlReporter implements ReporterV2 {this.suite = suite;}- _resolveOptions(): { outputFolder: string, open: HtmlReportOpenOption, attachmentsBaseURL: string, host: string | undefined, port: number | undefined, title: string | undefined } {+ _resolveOptions(): { outputFolder: string, open: HtmlReportOpenOption, attachmentsBaseURL: string, host: string | undefined, port: number | undefined } {const outputFolder = reportFolderFromEnv() ?? resolveReporterOutputPath('playwright-report', this._options.configDir, this._options.outputFolder);return {outputFolder,@@ -112,7 +110,6 @@ class HtmlReporter implements ReporterV2 {attachmentsBaseURL: process.env.PLAYWRIGHT_HTML_ATTACHMENTS_BASE_URL || this._options.attachmentsBaseURL || 'data/',host: process.env.PLAYWRIGHT_HTML_HOST || this._options.host,port: process.env.PLAYWRIGHT_HTML_PORT ? +process.env.PLAYWRIGHT_HTML_PORT : this._options.port,- title: process.env.PLAYWRIGHT_HTML_TITLE || this._options.title,};}@@ -128,7 +125,7 @@ class HtmlReporter implements ReporterV2 {async onEnd(result: api.FullResult) {const projectSuites = this.suite.suites;await removeFolders([this._outputFolder]);- const builder = new HtmlBuilder(this.config, this._outputFolder, this._attachmentsBaseURL, this._title);+ const builder = new HtmlBuilder(this.config, this._outputFolder, this._attachmentsBaseURL, process.env.PLAYWRIGHT_HTML_TITLE || this._options.title);this._buildResult = await builder.build(this.config.metadata, projectSuites, result, this._topLevelErrors);}diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.tsindex 4e9547e45b..6b99892b02 100644--- a/tests/playwright-test/reporter-html.spec.ts+++ b/tests/playwright-test/reporter-html.spec.ts@@ -481,6 +481,40 @@ for (const useIntermediateMergeReport of [true, false] as const) {await expect(anchorLocator.nth(1)).toHaveAttribute('href', 'http://microsoft.com');});+ test('should allow setting title from env in global teardown', async ({ runInlineTest, page, showReport }, testInfo) => {+ test.skip(useIntermediateMergeReport, 'env vars are not available in merge report');++ const result = await runInlineTest({+ 'playwright.config.ts': `+ module.exports = {+ globalTeardown: './global-teardown.js',+ };+ `,+ 'omega-star.test.js': `+ import { test, expect } from '@playwright/test';+ import fs from 'fs/promises';+ test('version check', async ({}, testInfo) => {+ const apiVersion = 'abcde';+ await fs.writeFile(testInfo.outputPath('omega_star_version'), apiVersion);+ expect(2).toEqual(2);+ });+ `,+ 'global-teardown.js': `+ import fs from 'fs/promises';+ import path from 'path';+ export default async (config) => {+ const apiVersion = await fs.readFile(path.join('test-results', 'omega-star-version-check', 'omega_star_version'), 'utf-8');+ process.env.PLAYWRIGHT_HTML_TITLE = 'Omega Star Test Suite (Version: ' + apiVersion + ')';+ };+ `,+ }, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);++ await showReport();+ await expect(page.locator('.header-title')).toHaveText('Omega Star Test Suite (Version: abcde)');+ });+test('should include stdio', async ({ runInlineTest, page, showReport }) => {const result = await runInlineTest({'a.test.js': `