docs: enhance hooks example to illustrate after hooks behavior (#26846)

Fixes https://github.com/microsoft/playwright/issues/26821
This commit is contained in:
Andrey Lushnikov 2023-09-01 17:18:31 -07:00 committed by GitHub
parent 1c5f53f216
commit afd4363aab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ test.describe('suite', () => {
test('first good', async ({ page }) => { /* ... */ });
test('second flaky', async ({ page }) => { /* ... */ });
test('third good', async ({ page }) => { /* ... */ });
test.afterAll(async () => { /* ... */ });
});
```
@ -28,25 +29,30 @@ When **all tests pass**, they will run in order in the same worker process.
* `first good` passes
* `second flaky` passes
* `third good` passes
* `afterAll` hook runs
Should **any test fail**, Playwright Test will discard the entire worker process along with the browser and will start a new one. Testing will continue in the new worker process starting with the next test.
* Worker process #1 starts
* `beforeAll` hook runs
* `first good` passes
* `second flaky` fails
* `afterAll` hook runs
* Worker process #2 starts
* `beforeAll` hook runs again
* `third good` passes
* `afterAll` hook runs
If you **enable [retries](#retries)**, second worker process will start by retrying the failed test and continue from there.
* Worker process #1 starts
* `beforeAll` hook runs
* `first good` passes
* `second flaky` fails
* `afterAll` hook runs
* Worker process #2 starts
* `beforeAll` hook runs again
* `second flaky` is retried and passes
* `third good` passes
* `afterAll` hook runs
This scheme works perfectly for independent tests and guarantees that failing tests can't affect healthy ones.