Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: remove overrides for type and status (#30211)

Yury Semikhatsky63f876a335d9
diff --git a/docs/src/test-reporter-api/class-suite.md b/docs/src/test-reporter-api/class-suite.md
index 80642def9e..f9661dc3fd 100644
--- a/docs/src/test-reporter-api/class-suite.md
+++ b/docs/src/test-reporter-api/class-suite.md
@@ -81,7 +81,7 @@ Returns a list of titles from the root down to this suite.
## property: Suite.type
* since: v1.44
-- returns: <[SuiteType]<'root' | 'project' | 'file' | 'describe'>>
+- returns: <[SuiteType]<"root"|"project"|"file"|"describe">>
Returns the type of the suite. The Suites form the following hierarchy:
`root` -> `project` -> `file` -> `describe` -> ...`describe` -> `test`.
diff --git a/docs/src/test-reporter-api/class-testcase.md b/docs/src/test-reporter-api/class-testcase.md
index 0abfa5c8d4..1b1dfb7845 100644
--- a/docs/src/test-reporter-api/class-testcase.md
+++ b/docs/src/test-reporter-api/class-testcase.md
@@ -110,6 +110,6 @@ Returns a list of titles from the root down to this test.
## property: TestCase.type
* since: v1.44
-- returns: <[TestCaseType]<'test'>>
+- returns: <[TestCaseType]<"test">>
Returns type of the test.
diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.ts
index 5ed0d34eca..424e60889d 100644
--- a/packages/playwright/types/testReporter.d.ts
+++ b/packages/playwright/types/testReporter.d.ts
@@ -228,672 +228,676 @@ export interface FullProject<TestArgs = {}, WorkerArgs = {}> {
}
/**
- * `Suite` is a group of tests. All tests in Playwright Test form the following hierarchy:
- * - Root suite has a child suite for each {@link FullProject}.
- * - Project suite #1. Has a child suite for each test file in the project.
- * - File suite #1
- * - {@link TestCase} #1
- * - {@link TestCase} #2
- * - Suite corresponding to a
- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe)
- * group
- * - {@link TestCase} #1 in a group
- * - {@link TestCase} #2 in a group
- * - < more test cases ... >
- * - File suite #2
- * - < more file suites ... >
- * - Project suite #2
- * - < more project suites ... >
- *
- * Reporter is given a root suite in the
- * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin) method.
+ * Result of the full test run.
*/
-export interface Suite {
- /**
- * Returns the type of the suite. The Suites form the following hierarchy: `root` -> `project` -> `file` -> `describe`
- * -> ...`describe` -> `test`.
- */
- type: 'root' | 'project' | 'file' | 'describe';
+export interface FullResult {
/**
- * Returns the list of all test cases in this suite and its descendants, as opposite to
- * [suite.tests](https://playwright.dev/docs/api/class-suite#suite-tests).
+ * Status:
+ * - 'passed' - everything went as expected.
+ * - 'failed' - any test has failed.
+ * - 'timedout' - the global time has been reached.
+ * - 'interrupted' - interrupted by the user.
*/
- allTests(): Array<TestCase>;
+ status: 'passed' | 'failed' | 'timedout' | 'interrupted';
/**
- * Test cases and suites defined directly in this suite. The elements are returned in their declaration order. You can
- * discriminate between different entry types using
- * [testCase.type](https://playwright.dev/docs/api/class-testcase#test-case-type) and
- * [suite.type](https://playwright.dev/docs/api/class-suite#suite-type).
+ * Test start wall time.
*/
- entries(): Array<TestCase|Suite>;
+ startTime: Date;
/**
- * Configuration of the project this suite belongs to, or [void] for the root suite.
+ * Test duration in milliseconds.
*/
- project(): FullProject|undefined;
+ duration: number;
+}
+/**
+ * Test runner notifies the reporter about various events during test execution. All methods of the reporter are
+ * optional.
+ *
+ * You can create a custom reporter by implementing a class with some of the reporter methods. Make sure to export
+ * this class as default.
+ *
+ * ```js
+ * // my-awesome-reporter.ts
+ * import type {
+ * Reporter, FullConfig, Suite, TestCase, TestResult, FullResult
+ * } from '@playwright/test/reporter';
+ *
+ * class MyReporter implements Reporter {
+ * constructor(options: { customOption?: string } = {}) {
+ * console.log(`my-awesome-reporter setup with customOption set to ${options.customOption}`);
+ * }
+ *
+ * onBegin(config: FullConfig, suite: Suite) {
+ * console.log(`Starting the run with ${suite.allTests().length} tests`);
+ * }
+ *
+ * onTestBegin(test: TestCase) {
+ * console.log(`Starting test ${test.title}`);
+ * }
+ *
+ * onTestEnd(test: TestCase, result: TestResult) {
+ * console.log(`Finished test ${test.title}: ${result.status}`);
+ * }
+ *
+ * onEnd(result: FullResult) {
+ * console.log(`Finished the run: ${result.status}`);
+ * }
+ * }
+ * export default MyReporter;
+ * ```
+ *
+ * Now use this reporter with
+ * [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter). Learn more about
+ * [using reporters](https://playwright.dev/docs/test-reporters).
+ *
+ * ```js
+ * // playwright.config.ts
+ * import { defineConfig } from '@playwright/test';
+ *
+ * export default defineConfig({
+ * reporter: ['./my-awesome-reporter.ts', { customOption: 'some value' }],
+ * });
+ * ```
+ *
+ * Here is a typical order of reporter calls:
+ * - [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin) is called
+ * once with a root suite that contains all other suites and tests. Learn more about [suites hierarchy]{@link
+ * Suite}.
+ * - [reporter.onTestBegin(test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-test-begin) is
+ * called for each test run. It is given a {@link TestCase} that is executed, and a {@link TestResult} that is
+ * almost empty. Test result will be populated while the test runs (for example, with steps and stdio) and will
+ * get final `status` once the test finishes.
+ * - [reporter.onStepBegin(test, result, step)](https://playwright.dev/docs/api/class-reporter#reporter-on-step-begin)
+ * and
+ * [reporter.onStepEnd(test, result, step)](https://playwright.dev/docs/api/class-reporter#reporter-on-step-end)
+ * are called for each executed step inside the test. When steps are executed, test run has not finished yet.
+ * - [reporter.onTestEnd(test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-test-end) is
+ * called when test run has finished. By this time, {@link TestResult} is complete and you can use
+ * [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status),
+ * [testResult.error](https://playwright.dev/docs/api/class-testresult#test-result-error) and more.
+ * - [reporter.onEnd(result)](https://playwright.dev/docs/api/class-reporter#reporter-on-end) is called once after
+ * all tests that should run had finished.
+ * - [reporter.onExit()](https://playwright.dev/docs/api/class-reporter#reporter-on-exit) is called immediately
+ * before the test runner exits.
+ *
+ * Additionally,
+ * [reporter.onStdOut(chunk, test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-std-out) and
+ * [reporter.onStdErr(chunk, test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-std-err) are
+ * called when standard output is produced in the worker process, possibly during a test execution, and
+ * [reporter.onError(error)](https://playwright.dev/docs/api/class-reporter#reporter-on-error) is called when
+ * something went wrong outside of the test execution.
+ *
+ * If your custom reporter does not print anything to the terminal, implement
+ * [reporter.printsToStdio()](https://playwright.dev/docs/api/class-reporter#reporter-prints-to-stdio) and return
+ * `false`. This way, Playwright will use one of the standard terminal reporters in addition to your custom reporter
+ * to enhance user experience.
+ *
+ * **Merged report API notes**
+ *
+ * When merging mutliple [`blob`](https://playwright.dev/docs/api/test-reporters#blob-reporter) reports via
+ * [`merge-reports`](https://playwright.dev/docs/api/test-sharding#merge-reports-cli) CLI command, the same {@link Reporter} API is called to
+ * produce final reports and all existing reporters should work without any changes. There some subtle differences
+ * though which might affect some custom reporters.
+ * - Projects from different shards are always kept as separate {@link TestProject} objects. E.g. if project
+ * 'Desktop Chrome' was sharded across 5 machines then there will be 5 instances of projects with the same name in
+ * the config passed to
+ * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin).
+ */
+export interface Reporter {
/**
- * Returns a list of titles from the root down to this suite.
+ * Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise]
+ * and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the
+ * test runner.
+ * @param result Result of the full test run, `status` can be one of:
+ * - `'passed'` - Everything went as expected.
+ * - `'failed'` - Any test has failed.
+ * - `'timedout'` - The
+ * [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout) has
+ * been reached.
+ * - `'interrupted'` - Interrupted by the user.
*/
- titlePath(): Array<string>;
-
+ onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void;
/**
- * Location in the source where the suite is defined. Missing for root and project suites.
+ * Called once before running tests. All tests have been already discovered and put into a hierarchy of {@link
+ * Suite}s.
+ * @param config Resolved configuration.
+ * @param suite The root suite that contains all projects, files and test cases.
*/
- location?: Location;
+ onBegin?(config: FullConfig, suite: Suite): void;
/**
- * Parent suite, missing for the root suite.
+ * Called on some global error, for example unhandled exception in the worker process.
+ * @param error The error.
*/
- parent?: Suite;
+ onError?(error: TestError): void;
/**
- * Child suites. See {@link Suite} for the hierarchy of suites.
+ * Called immediately before test runner exists. At this point all the reporters have received the
+ * [reporter.onEnd(result)](https://playwright.dev/docs/api/class-reporter#reporter-on-end) signal, so all the reports
+ * should be build. You can run the code that uploads the reports in this hook.
*/
- suites: Array<Suite>;
+ onExit?(): Promise<void>;
/**
- * Test cases in the suite. Note that only test cases defined directly in this suite are in the list. Any test cases
- * defined in nested
- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups are
- * listed in the child [suite.suites](https://playwright.dev/docs/api/class-suite#suite-suites).
+ * Called when something has been written to the standard error in the worker process.
+ * @param chunk Output chunk.
+ * @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].
+ * @param result Result of the test run, this object gets populated while the test runs.
*/
- tests: Array<TestCase>;
+ onStdErr?(chunk: string|Buffer, test: void|TestCase, result: void|TestResult): void;
/**
- * Suite title.
- * - Empty for root suite.
- * - Project name for project suite.
- * - File path for file suite.
- * - Title passed to
- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) for a
- * group suite.
+ * Called when something has been written to the standard output in the worker process.
+ * @param chunk Output chunk.
+ * @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].
+ * @param result Result of the test run, this object gets populated while the test runs.
*/
- title: string;
-}
+ onStdOut?(chunk: string|Buffer, test: void|TestCase, result: void|TestResult): void;
-/**
- * `TestCase` corresponds to every
- * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) call in a test file.
- * When a single [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) is
- * running in multiple projects or repeated multiple times, it will have multiple `TestCase` objects in corresponding
- * projects' suites.
- */
-export interface TestCase {
/**
- * Returns type of the test.
- */
- type: 'test';
- /**
- * Expected test status.
- * - Tests marked as
- * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip)
- * or
- * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme)
- * are expected to be `'skipped'`.
- * - Tests marked as
- * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail)
- * are expected to be `'failed'`.
- * - Other tests are expected to be `'passed'`.
- *
- * See also [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status) for the actual
- * status.
+ * Called when a test step started in the worker process.
+ * @param test Test that the step belongs to.
+ * @param result Result of the test run, this object gets populated while the test runs.
+ * @param step Test step instance that has started.
*/
- expectedStatus: TestStatus;
+ onStepBegin?(test: TestCase, result: TestResult, step: TestStep): void;
+
/**
- * Whether the test is considered running fine. Non-ok tests fail the test run with non-zero exit code.
+ * Called when a test step finished in the worker process.
+ * @param test Test that the step belongs to.
+ * @param result Result of the test run.
+ * @param step Test step instance that has finished.
*/
- ok(): boolean;
+ onStepEnd?(test: TestCase, result: TestResult, step: TestStep): void;
/**
- * Testing outcome for this test. Note that outcome is not the same as
- * [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status):
- * - Test that is expected to fail and actually fails is `'expected'`.
- * - Test that passes on a second retry is `'flaky'`.
+ * Called after a test has been started in the worker process.
+ * @param test Test that has been started.
+ * @param result Result of the test run, this object gets populated while the test runs.
*/
- outcome(): "skipped"|"expected"|"unexpected"|"flaky";
+ onTestBegin?(test: TestCase, result: TestResult): void;
/**
- * Returns a list of titles from the root down to this test.
+ * Called after a test has been finished in the worker process.
+ * @param test Test that has been finished.
+ * @param result Result of the test run.
*/
- titlePath(): Array<string>;
+ onTestEnd?(test: TestCase, result: TestResult): void;
/**
- * The list of annotations applicable to the current test. Includes:
- * - annotations defined on the test or suite via
- * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) and
- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe);
- * - annotations implicitly added by methods
- * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip),
- * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme)
- * and
- * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail);
- * - annotations appended to
- * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations) during the test
- * execution.
- *
- * Annotations are available during test execution through
- * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations).
- *
- * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).
+ * Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance
+ * user experience. If your reporter does not print to the terminal, it is strongly recommended to return `false`.
*/
- annotations: Array<{
- /**
- * Annotation type, for example `'skip'` or `'fail'`.
- */
- type: string;
+ printsToStdio?(): boolean;
+}
- /**
- * Optional description.
- */
- description?: string;
- }>;
+export interface JSONReport {
+ config: Omit<FullConfig, 'projects'> & {
+ projects: {
+ outputDir: string,
+ repeatEach: number,
+ retries: number,
+ metadata: Metadata,
+ id: string,
+ name: string,
+ testDir: string,
+ testIgnore: string[],
+ testMatch: string[],
+ timeout: number,
+ }[],
+ };
+ suites: JSONReportSuite[];
+ errors: TestError[];
+ stats: {
+ startTime: string; // Date in ISO 8601 format.
+ duration: number; // In milliseconds;
+ expected: number;
+ unexpected: number;
+ flaky: number;
+ skipped: number;
+ }
+}
- /**
- * Unique test ID that is computed based on the test file name, test title and project name. Test ID can be used as a
- * history ID.
- */
+export interface JSONReportSuite {
+ title: string;
+ file: string;
+ column: number;
+ line: number;
+ specs: JSONReportSpec[];
+ suites?: JSONReportSuite[];
+}
+
+export interface JSONReportSpec {
+ tags: string[],
+ title: string;
+ ok: boolean;
+ tests: JSONReportTest[];
id: string;
+ file: string;
+ line: number;
+ column: number;
+}
- /**
- * Location in the source where the test is defined.
- */
- location: Location;
+export interface JSONReportTest {
+ timeout: number;
+ annotations: { type: string, description?: string }[],
+ expectedStatus: TestStatus;
+ projectName: string;
+ projectId: string;
+ results: JSONReportTestResult[];
+ status: 'skipped' | 'expected' | 'unexpected' | 'flaky';
+}
- /**
- * Suite this test case belongs to.
- */
- parent: Suite;
+export interface JSONReportError {
+ message: string;
+ location?: Location;
+}
- /**
- * Contains the repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each` to
- * the [command line](https://playwright.dev/docs/test-cli).
- */
- repeatEachIndex: number;
+export interface JSONReportTestResult {
+ workerIndex: number;
+ status: TestStatus | undefined;
+ duration: number;
+ error: TestError | undefined;
+ errors: JSONReportError[];
+ stdout: JSONReportSTDIOEntry[];
+ stderr: JSONReportSTDIOEntry[];
+ retry: number;
+ steps?: JSONReportTestStep[];
+ startTime: string; // Date in ISO 8601 format.
+ attachments: {
+ name: string;
+ path?: string;
+ body?: string;
+ contentType: string;
+ }[];
+ errorLocation?: Location;
+}
- /**
- * Results for each run of this test.
- */
- results: Array<TestResult>;
+export interface JSONReportTestStep {
+ title: string;
+ duration: number;
+ error: TestError | undefined;
+ steps?: JSONReportTestStep[];
+}
+
+export type JSONReportSTDIOEntry = { text: string } | { buffer: string };
+
+// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
+export {};
- /**
- * The maximum number of retries given to this test in the configuration.
- *
- * Learn more about [test retries](https://playwright.dev/docs/test-retries#retries).
- */
- retries: number;
+/**
+ * Represents a location in the source code where {@link TestCase} or {@link Suite} is defined.
+ */
+export interface Location {
/**
- * The list of tags defined on the test or suite via
- * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) or
- * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe), as well as
- * `@`-tokens extracted from test and suite titles.
- *
- * Learn more about [test tags](https://playwright.dev/docs/test-annotations#tag-tests).
+ * Column number in the source file.
*/
- tags: Array<string>;
+ column: number;
/**
- * The timeout given to the test. Affected by
- * [testConfig.timeout](https://playwright.dev/docs/api/class-testconfig#test-config-timeout),
- * [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout),
- * [test.setTimeout(timeout)](https://playwright.dev/docs/api/class-test#test-set-timeout),
- * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow) and
- * [testInfo.setTimeout(timeout)](https://playwright.dev/docs/api/class-testinfo#test-info-set-timeout).
+ * Path to the source file.
*/
- timeout: number;
+ file: string;
/**
- * Test title as passed to the
- * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) call.
+ * Line number in the source file.
*/
- title: string;
+ line: number;
}
/**
- * A result of a single {@link TestCase} run.
+ * `Suite` is a group of tests. All tests in Playwright Test form the following hierarchy:
+ * - Root suite has a child suite for each {@link FullProject}.
+ * - Project suite #1. Has a child suite for each test file in the project.
+ * - File suite #1
+ * - {@link TestCase} #1
+ * - {@link TestCase} #2
+ * - Suite corresponding to a
+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe)
+ * group
+ * - {@link TestCase} #1 in a group
+ * - {@link TestCase} #2 in a group
+ * - < more test cases ... >
+ * - File suite #2
+ * - < more file suites ... >
+ * - Project suite #2
+ * - < more project suites ... >
+ *
+ * Reporter is given a root suite in the
+ * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin) method.
*/
-export interface TestResult {
- /**
- * The status of this test result. See also
- * [testCase.expectedStatus](https://playwright.dev/docs/api/class-testcase#test-case-expected-status).
- */
- status: TestStatus;
- /**
- * The list of files or buffers attached during the test execution through
- * [testInfo.attachments](https://playwright.dev/docs/api/class-testinfo#test-info-attachments).
- */
- attachments: Array<{
- /**
- * Attachment name.
- */
- name: string;
-
- /**
- * Content type of this attachment to properly present in the report, for example `'application/json'` or
- * `'image/png'`.
- */
- contentType: string;
-
- /**
- * Optional path on the filesystem to the attached file.
- */
- path?: string;
-
- /**
- * Optional attachment body used instead of a file.
- */
- body?: Buffer;
- }>;
-
+export interface Suite {
/**
- * Running time in milliseconds.
+ * Returns the list of all test cases in this suite and its descendants, as opposite to
+ * [suite.tests](https://playwright.dev/docs/api/class-suite#suite-tests).
*/
- duration: number;
+ allTests(): Array<TestCase>;
/**
- * First error thrown during test execution, if any. This is equal to the first element in
- * [testResult.errors](https://playwright.dev/docs/api/class-testresult#test-result-errors).
+ * Test cases and suites defined directly in this suite. The elements are returned in their declaration order. You can
+ * discriminate between different entry types using
+ * [testCase.type](https://playwright.dev/docs/api/class-testcase#test-case-type) and
+ * [suite.type](https://playwright.dev/docs/api/class-suite#suite-type).
*/
- error?: TestError;
+ entries(): Array<TestCase|Suite>;
/**
- * Errors thrown during the test execution.
+ * Configuration of the project this suite belongs to, or [void] for the root suite.
*/
- errors: Array<TestError>;
+ project(): FullProject|undefined;
/**
- * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have
- * a different `parallelIndex`.
+ * Returns a list of titles from the root down to this suite.
*/
- parallelIndex: number;
+ titlePath(): Array<string>;
/**
- * When test is retries multiple times, each retry attempt is given a sequential number.
- *
- * Learn more about [test retries](https://playwright.dev/docs/test-retries#retries).
+ * Location in the source where the suite is defined. Missing for root and project suites.
*/
- retry: number;
+ location?: Location;
/**
- * Start time of this particular test run.
+ * Parent suite, missing for the root suite.
*/
- startTime: Date;
+ parent?: Suite;
/**
- * Anything written to the standard error during the test run.
+ * Child suites. See {@link Suite} for the hierarchy of suites.
*/
- stderr: Array<string|Buffer>;
+ suites: Array<Suite>;
/**
- * Anything written to the standard output during the test run.
+ * Test cases in the suite. Note that only test cases defined directly in this suite are in the list. Any test cases
+ * defined in nested
+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups are
+ * listed in the child [suite.suites](https://playwright.dev/docs/api/class-suite#suite-suites).
*/
- stdout: Array<string|Buffer>;
+ tests: Array<TestCase>;
/**
- * List of steps inside this test run.
+ * Suite title.
+ * - Empty for root suite.
+ * - Project name for project suite.
+ * - File path for file suite.
+ * - Title passed to
+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) for a
+ * group suite.
*/
- steps: Array<TestStep>;
+ title: string;
/**
- * Index of the worker where the test was run. If the test was not run a single time, for example when the user
- * interrupted testing, the only result will have a `workerIndex` equal to `-1`.
- *
- * Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test.
+ * Returns the type of the suite. The Suites form the following hierarchy: `root` -> `project` -> `file` -> `describe`
+ * -> ...`describe` -> `test`.
*/
- workerIndex: number;
+ type: "root"|"project"|"file"|"describe";
}
/**
- * Result of the full test run.
+ * `TestCase` corresponds to every
+ * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) call in a test file.
+ * When a single [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) is
+ * running in multiple projects or repeated multiple times, it will have multiple `TestCase` objects in corresponding
+ * projects' suites.
*/
-export interface FullResult {
+export interface TestCase {
/**
- * Status:
- * - 'passed' - everything went as expected.
- * - 'failed' - any test has failed.
- * - 'timedout' - the global time has been reached.
- * - 'interrupted' - interrupted by the user.
+ * Whether the test is considered running fine. Non-ok tests fail the test run with non-zero exit code.
*/
- status: 'passed' | 'failed' | 'timedout' | 'interrupted';
+ ok(): boolean;
/**
- * Test start wall time.
+ * Testing outcome for this test. Note that outcome is not the same as
+ * [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status):
+ * - Test that is expected to fail and actually fails is `'expected'`.
+ * - Test that passes on a second retry is `'flaky'`.
*/
- startTime: Date;
+ outcome(): "skipped"|"expected"|"unexpected"|"flaky";
/**
- * Test duration in milliseconds.
+ * Returns a list of titles from the root down to this test.
*/
- duration: number;
-}
+ titlePath(): Array<string>;
-/**
- * Test runner notifies the reporter about various events during test execution. All methods of the reporter are
- * optional.
- *
- * You can create a custom reporter by implementing a class with some of the reporter methods. Make sure to export
- * this class as default.
- *
- * ```js
- * // my-awesome-reporter.ts
- * import type {
- * Reporter, FullConfig, Suite, TestCase, TestResult, FullResult
- * } from '@playwright/test/reporter';
- *
- * class MyReporter implements Reporter {
- * constructor(options: { customOption?: string } = {}) {
- * console.log(`my-awesome-reporter setup with customOption set to ${options.customOption}`);
- * }
- *
- * onBegin(config: FullConfig, suite: Suite) {
- * console.log(`Starting the run with ${suite.allTests().length} tests`);
- * }
- *
- * onTestBegin(test: TestCase) {
- * console.log(`Starting test ${test.title}`);
- * }
- *
- * onTestEnd(test: TestCase, result: TestResult) {
- * console.log(`Finished test ${test.title}: ${result.status}`);
- * }
- *
- * onEnd(result: FullResult) {
- * console.log(`Finished the run: ${result.status}`);
- * }
- * }
- * export default MyReporter;
- * ```
- *
- * Now use this reporter with
- * [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter). Learn more about
- * [using reporters](https://playwright.dev/docs/test-reporters).
- *
- * ```js
- * // playwright.config.ts
- * import { defineConfig } from '@playwright/test';
- *
- * export default defineConfig({
- * reporter: ['./my-awesome-reporter.ts', { customOption: 'some value' }],
- * });
- * ```
- *
- * Here is a typical order of reporter calls:
- * - [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin) is called
- * once with a root suite that contains all other suites and tests. Learn more about [suites hierarchy]{@link
- * Suite}.
- * - [reporter.onTestBegin(test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-test-begin) is
- * called for each test run. It is given a {@link TestCase} that is executed, and a {@link TestResult} that is
- * almost empty. Test result will be populated while the test runs (for example, with steps and stdio) and will
- * get final `status` once the test finishes.
- * - [reporter.onStepBegin(test, result, step)](https://playwright.dev/docs/api/class-reporter#reporter-on-step-begin)
- * and
- * [reporter.onStepEnd(test, result, step)](https://playwright.dev/docs/api/class-reporter#reporter-on-step-end)
- * are called for each executed step inside the test. When steps are executed, test run has not finished yet.
- * - [reporter.onTestEnd(test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-test-end) is
- * called when test run has finished. By this time, {@link TestResult} is complete and you can use
- * [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status),
- * [testResult.error](https://playwright.dev/docs/api/class-testresult#test-result-error) and more.
- * - [reporter.onEnd(result)](https://playwright.dev/docs/api/class-reporter#reporter-on-end) is called once after
- * all tests that should run had finished.
- * - [reporter.onExit()](https://playwright.dev/docs/api/class-reporter#reporter-on-exit) is called immediately
- * before the test runner exits.
- *
- * Additionally,
- * [reporter.onStdOut(chunk, test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-std-out) and
- * [reporter.onStdErr(chunk, test, result)](https://playwright.dev/docs/api/class-reporter#reporter-on-std-err) are
- * called when standard output is produced in the worker process, possibly during a test execution, and
- * [reporter.onError(error)](https://playwright.dev/docs/api/class-reporter#reporter-on-error) is called when
- * something went wrong outside of the test execution.
- *
- * If your custom reporter does not print anything to the terminal, implement
- * [reporter.printsToStdio()](https://playwright.dev/docs/api/class-reporter#reporter-prints-to-stdio) and return
- * `false`. This way, Playwright will use one of the standard terminal reporters in addition to your custom reporter
- * to enhance user experience.
- *
- * **Merged report API notes**
- *
- * When merging mutliple [`blob`](https://playwright.dev/docs/api/test-reporters#blob-reporter) reports via
- * [`merge-reports`](https://playwright.dev/docs/api/test-sharding#merge-reports-cli) CLI command, the same {@link Reporter} API is called to
- * produce final reports and all existing reporters should work without any changes. There some subtle differences
- * though which might affect some custom reporters.
- * - Projects from different shards are always kept as separate {@link TestProject} objects. E.g. if project
- * 'Desktop Chrome' was sharded across 5 machines then there will be 5 instances of projects with the same name in
- * the config passed to
- * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin).
- */
-export interface Reporter {
/**
- * Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise]
- * and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the
- * test runner.
- * @param result Result of the full test run, `status` can be one of:
- * - `'passed'` - Everything went as expected.
- * - `'failed'` - Any test has failed.
- * - `'timedout'` - The
- * [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout) has
- * been reached.
- * - `'interrupted'` - Interrupted by the user.
+ * The list of annotations applicable to the current test. Includes:
+ * - annotations defined on the test or suite via
+ * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) and
+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe);
+ * - annotations implicitly added by methods
+ * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip),
+ * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme)
+ * and
+ * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail);
+ * - annotations appended to
+ * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations) during the test
+ * execution.
+ *
+ * Annotations are available during test execution through
+ * [testInfo.annotations](https://playwright.dev/docs/api/class-testinfo#test-info-annotations).
+ *
+ * Learn more about [test annotations](https://playwright.dev/docs/test-annotations).
*/
- onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void;
+ annotations: Array<{
+ /**
+ * Annotation type, for example `'skip'` or `'fail'`.
+ */
+ type: string;
+
+ /**
+ * Optional description.
+ */
+ description?: string;
+ }>;
+
/**
- * Called once before running tests. All tests have been already discovered and put into a hierarchy of {@link
- * Suite}s.
- * @param config Resolved configuration.
- * @param suite The root suite that contains all projects, files and test cases.
+ * Expected test status.
+ * - Tests marked as
+ * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip)
+ * or
+ * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme)
+ * are expected to be `'skipped'`.
+ * - Tests marked as
+ * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail)
+ * are expected to be `'failed'`.
+ * - Other tests are expected to be `'passed'`.
+ *
+ * See also [testResult.status](https://playwright.dev/docs/api/class-testresult#test-result-status) for the actual
+ * status.
*/
- onBegin?(config: FullConfig, suite: Suite): void;
+ expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";
+
+ /**
+ * Unique test ID that is computed based on the test file name, test title and project name. Test ID can be used as a
+ * history ID.
+ */
+ id: string;
+
+ /**
+ * Location in the source where the test is defined.
+ */
+ location: Location;
+
+ /**
+ * Suite this test case belongs to.
+ */
+ parent: Suite;
/**
- * Called on some global error, for example unhandled exception in the worker process.
- * @param error The error.
+ * Contains the repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each` to
+ * the [command line](https://playwright.dev/docs/test-cli).
*/
- onError?(error: TestError): void;
+ repeatEachIndex: number;
/**
- * Called immediately before test runner exists. At this point all the reporters have received the
- * [reporter.onEnd(result)](https://playwright.dev/docs/api/class-reporter#reporter-on-end) signal, so all the reports
- * should be build. You can run the code that uploads the reports in this hook.
+ * Results for each run of this test.
*/
- onExit?(): Promise<void>;
+ results: Array<TestResult>;
/**
- * Called when something has been written to the standard error in the worker process.
- * @param chunk Output chunk.
- * @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].
- * @param result Result of the test run, this object gets populated while the test runs.
+ * The maximum number of retries given to this test in the configuration.
+ *
+ * Learn more about [test retries](https://playwright.dev/docs/test-retries#retries).
*/
- onStdErr?(chunk: string|Buffer, test: void|TestCase, result: void|TestResult): void;
+ retries: number;
/**
- * Called when something has been written to the standard output in the worker process.
- * @param chunk Output chunk.
- * @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].
- * @param result Result of the test run, this object gets populated while the test runs.
+ * The list of tags defined on the test or suite via
+ * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) or
+ * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe), as well as
+ * `@`-tokens extracted from test and suite titles.
+ *
+ * Learn more about [test tags](https://playwright.dev/docs/test-annotations#tag-tests).
*/
- onStdOut?(chunk: string|Buffer, test: void|TestCase, result: void|TestResult): void;
+ tags: Array<string>;
/**
- * Called when a test step started in the worker process.
- * @param test Test that the step belongs to.
- * @param result Result of the test run, this object gets populated while the test runs.
- * @param step Test step instance that has started.
+ * The timeout given to the test. Affected by
+ * [testConfig.timeout](https://playwright.dev/docs/api/class-testconfig#test-config-timeout),
+ * [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout),
+ * [test.setTimeout(timeout)](https://playwright.dev/docs/api/class-test#test-set-timeout),
+ * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow) and
+ * [testInfo.setTimeout(timeout)](https://playwright.dev/docs/api/class-testinfo#test-info-set-timeout).
*/
- onStepBegin?(test: TestCase, result: TestResult, step: TestStep): void;
+ timeout: number;
/**
- * Called when a test step finished in the worker process.
- * @param test Test that the step belongs to.
- * @param result Result of the test run.
- * @param step Test step instance that has finished.
+ * Test title as passed to the
+ * [test.(call)(title[, details, body])](https://playwright.dev/docs/api/class-test#test-call) call.
*/
- onStepEnd?(test: TestCase, result: TestResult, step: TestStep): void;
+ title: string;
/**
- * Called after a test has been started in the worker process.
- * @param test Test that has been started.
- * @param result Result of the test run, this object gets populated while the test runs.
+ * Returns type of the test.
*/
- onTestBegin?(test: TestCase, result: TestResult): void;
+ type: "test";
+}
+/**
+ * Information about an error thrown during test execution.
+ */
+export interface TestError {
/**
- * Called after a test has been finished in the worker process.
- * @param test Test that has been finished.
- * @param result Result of the test run.
+ * Error location in the source code.
*/
- onTestEnd?(test: TestCase, result: TestResult): void;
+ location?: Location;
/**
- * Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance
- * user experience. If your reporter does not print to the terminal, it is strongly recommended to return `false`.
+ * Error message. Set when [Error] (or its subclass) has been thrown.
*/
- printsToStdio?(): boolean;
-}
+ message?: string;
-export interface JSONReport {
- config: Omit<FullConfig, 'projects'> & {
- projects: {
- outputDir: string,
- repeatEach: number,
- retries: number,
- metadata: Metadata,
- id: string,
- name: string,
- testDir: string,
- testIgnore: string[],
- testMatch: string[],
- timeout: number,
- }[],
- };
- suites: JSONReportSuite[];
- errors: TestError[];
- stats: {
- startTime: string; // Date in ISO 8601 format.
- duration: number; // In milliseconds;
- expected: number;
- unexpected: number;
- flaky: number;
- skipped: number;
- }
-}
+ /**
+ * Source code snippet with highlighted error.
+ */
+ snippet?: string;
-export interface JSONReportSuite {
- title: string;
- file: string;
- column: number;
- line: number;
- specs: JSONReportSpec[];
- suites?: JSONReportSuite[];
-}
+ /**
+ * Error stack. Set when [Error] (or its subclass) has been thrown.
+ */
+ stack?: string;
-export interface JSONReportSpec {
- tags: string[],
- title: string;
- ok: boolean;
- tests: JSONReportTest[];
- id: string;
- file: string;
- line: number;
- column: number;
+ /**
+ * The value that was thrown. Set when anything except the [Error] (or its subclass) has been thrown.
+ */
+ value?: string;
}
-export interface JSONReportTest {
- timeout: number;
- annotations: { type: string, description?: string }[],
- expectedStatus: TestStatus;
- projectName: string;
- projectId: string;
- results: JSONReportTestResult[];
- status: 'skipped' | 'expected' | 'unexpected' | 'flaky';
-}
+/**
+ * A result of a single {@link TestCase} run.
+ */
+export interface TestResult {
+ /**
+ * The list of files or buffers attached during the test execution through
+ * [testInfo.attachments](https://playwright.dev/docs/api/class-testinfo#test-info-attachments).
+ */
+ attachments: Array<{
+ /**
+ * Attachment name.
+ */
+ name: string;
-export interface JSONReportError {
- message: string;
- location?: Location;
-}
+ /**
+ * Content type of this attachment to properly present in the report, for example `'application/json'` or
+ * `'image/png'`.
+ */
+ contentType: string;
-export interface JSONReportTestResult {
- workerIndex: number;
- status: TestStatus | undefined;
- duration: number;
- error: TestError | undefined;
- errors: JSONReportError[];
- stdout: JSONReportSTDIOEntry[];
- stderr: JSONReportSTDIOEntry[];
- retry: number;
- steps?: JSONReportTestStep[];
- startTime: string; // Date in ISO 8601 format.
- attachments: {
- name: string;
+ /**
+ * Optional path on the filesystem to the attached file.
+ */
path?: string;
- body?: string;
- contentType: string;
- }[];
- errorLocation?: Location;
-}
-export interface JSONReportTestStep {
- title: string;
- duration: number;
- error: TestError | undefined;
- steps?: JSONReportTestStep[];
-}
+ /**
+ * Optional attachment body used instead of a file.
+ */
+ body?: Buffer;
+ }>;
-export type JSONReportSTDIOEntry = { text: string } | { buffer: string };
+ /**
+ * Running time in milliseconds.
+ */
+ duration: number;
-// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
-export {};
+ /**
+ * First error thrown during test execution, if any. This is equal to the first element in
+ * [testResult.errors](https://playwright.dev/docs/api/class-testresult#test-result-errors).
+ */
+ error?: TestError;
+ /**
+ * Errors thrown during the test execution.
+ */
+ errors: Array<TestError>;
-/**
- * Represents a location in the source code where {@link TestCase} or {@link Suite} is defined.
- */
-export interface Location {
/**
- * Column number in the source file.
+ * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have
+ * a different `parallelIndex`.
*/
- column: number;
+ parallelIndex: number;
/**
- * Path to the source file.
+ * When test is retries multiple times, each retry attempt is given a sequential number.
+ *
+ * Learn more about [test retries](https://playwright.dev/docs/test-retries#retries).
*/
- file: string;
+ retry: number;
/**
- * Line number in the source file.
+ * Start time of this particular test run.
*/
- line: number;
-}
+ startTime: Date;
-/**
- * Information about an error thrown during test execution.
- */
-export interface TestError {
/**
- * Error location in the source code.
+ * The status of this test result. See also
+ * [testCase.expectedStatus](https://playwright.dev/docs/api/class-testcase#test-case-expected-status).
*/
- location?: Location;
+ status: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";
/**
- * Error message. Set when [Error] (or its subclass) has been thrown.
+ * Anything written to the standard error during the test run.
*/
- message?: string;
+ stderr: Array<string|Buffer>;
/**
- * Source code snippet with highlighted error.
+ * Anything written to the standard output during the test run.
*/
- snippet?: string;
+ stdout: Array<string|Buffer>;
/**
- * Error stack. Set when [Error] (or its subclass) has been thrown.
+ * List of steps inside this test run.
*/
- stack?: string;
+ steps: Array<TestStep>;
/**
- * The value that was thrown. Set when anything except the [Error] (or its subclass) has been thrown.
+ * Index of the worker where the test was run. If the test was not run a single time, for example when the user
+ * interrupted testing, the only result will have a `workerIndex` equal to `-1`.
+ *
+ * Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test.
*/
- value?: string;
+ workerIndex: number;
}
/**
diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.ts
index 129faf30fc..e5bf37cdc8 100644
--- a/utils/generate_types/overrides-testReporter.d.ts
+++ b/utils/generate_types/overrides-testReporter.d.ts
@@ -29,19 +29,6 @@ export interface FullProject<TestArgs = {}, WorkerArgs = {}> {
use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
}
-export interface Suite {
- type: 'root' | 'project' | 'file' | 'describe';
-}
-
-export interface TestCase {
- type: 'test';
- expectedStatus: TestStatus;
-}
-
-export interface TestResult {
- status: TestStatus;
-}
-
/**
* Result of the full test run.
*/