docs: an overview of reporter methods (#8948)

This commit is contained in:
Dmitry Gozman 2021-09-15 15:29:06 -07:00 committed by GitHub
parent 2380b07f30
commit 545d793956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -55,7 +55,7 @@ class MyReporter implements Reporter {
export default MyReporter;
```
Now use this reporter with [`property: TestConfig.reporter`].
Now use this reporter with [`property: TestConfig.reporter`]. Learn more about [using reporters](./test-reporters.md).
```js js-flavor=js
// playwright.config.js
@ -79,7 +79,15 @@ const config: PlaywrightTestConfig = {
export default config;
```
Learn more about [reporters](./test-reporters.md).
Here is a typical order of reporter calls:
* [`method: Reporter.onBegin`] is called once with a root suite that contains all other suites and tests. Learn more about [suites hierarchy][Suite].
* [`method: Reporter.onTestBegin`] is called for each test run. It is given a [TestCase] that is executed, and a [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.
* [`method: Reporter.onStepBegin`] and [`method: Reporter.onStepEnd`] are called for each executed step inside the test. When steps are executed, test run has not finished yet.
* [`method: Reporter.onTestEnd`] is called when test run has finished. By this time, [TestResult] is complete and you can use [`property: TestResult.status`], [`property: TestResult.error`] and more.
* [`method: Reporter.onEnd`] is called once after all tests that should run had finished.
Additionally, [`method: Reporter.onStdOut`] and [`method: Reporter.onStdErr`] are called when standard output is produced in the worker process, possibly during a test execution,
and [`method: Reporter.onError`] is called when something went wrong outside of the test execution.
## method: Reporter.onBegin

View File

@ -306,6 +306,7 @@ export interface FullResult {
* ```
*
* 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).
*
* ```ts
* // playwright.config.ts
@ -317,7 +318,29 @@ export interface FullResult {
* export default config;
* ```
*
* Learn more about [reporters](https://playwright.dev/docs/test-reporters).
* 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][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 [TestCase] that is executed, and a [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, [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.
*
* 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.
*/
export interface Reporter {
/**