delete after..
This commit is contained in:
parent
765d5ac73f
commit
c8b52b37ae
|
|
@ -725,21 +725,17 @@ export const test = base.extend({
|
|||
|
||||
## Adding global beforeEach/afterEach hooks
|
||||
|
||||
[`method: Test.beforeEach`] and [`method: Test.afterEach`] hooks run before/after each test declared in the same file and same [`method: Test.describe`] block (if any). If you want to declare hooks that run before/after each test globally, you can define them as auto fixtures with `scope: 'test'` like this:
|
||||
[`method: Test.beforeEach`] and [`method: Test.afterEach`] hooks run before/after each test declared in the same file and same [`method: Test.describe`] block (if any). If you want to declare hooks that run before/after each test globally, you can declare them as auto fixtures with `scope: 'test'` like this:
|
||||
|
||||
```ts title="fixtures.ts"
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
export const test = base.extend({
|
||||
sharedBeforeEach: [async ({ page, baseURL }, use) => {
|
||||
await page.goto(baseURL);
|
||||
forEachTest: [async ({ page, baseURL }, use) => {
|
||||
await page.goto('http://localhost:8000');
|
||||
await use();
|
||||
}, { scope: 'test', auto: true } ], // starts automatically before every test, we pass "auto" for that.
|
||||
|
||||
sharedAfterEach: [async ({ page }, use) => {
|
||||
await use();
|
||||
console.log('Test final URL:', page.url());
|
||||
}, { scope: 'test', auto: true } ], // starts automatically after every test, we pass "auto" for that.
|
||||
console.log('Last URL:', page.url());
|
||||
}, { scope: 'test', auto: true } ], // starts automatically for every test, we pass "auto" for that.
|
||||
});
|
||||
```
|
||||
|
||||
|
|
@ -756,21 +752,17 @@ test('basic', async ({ page, baseURL }) => {
|
|||
|
||||
## Adding global beforeAll/afterAll hooks
|
||||
|
||||
[`method: Test.beforeAll`] and [`method: Test.afterAll`] hooks run before/after all tests declared in the same file and same [`method: Test.describe`] block (if any) once per worker process. If you want to declare hooks
|
||||
that run before/after all tests in every file, you can define them as auto fixtures with `scope: 'worker'` as follows:
|
||||
[`method: Test.beforeAll`] and [`method: Test.afterAll`] hooks run before/after all tests declared in the same file and same [`method: Test.describe`] block (if any), once per worker process. If you want to declare hooks
|
||||
that run before/after all tests in every file, you can declare them as auto fixtures with `scope: 'worker'` as follows:
|
||||
|
||||
```ts title="fixtures.ts"
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
export const test = base.extend({
|
||||
sharedBeforeAll: [async ({ browser }, use) => {
|
||||
forEachWorker: [async ({ browser }, use) => {
|
||||
console.log('Before All', browser.version());
|
||||
await use();
|
||||
}, { scope: 'worker', auto: true } ], // starts automatically for every worker, we pass "auto" for that.
|
||||
|
||||
sharedAfterAll: [async ({ browser }, use) => {
|
||||
console.log('After All', browser.version());
|
||||
await use();
|
||||
}, { scope: 'worker', auto: true } ], // starts automatically for every worker, we pass "auto" for that.
|
||||
});
|
||||
```
|
||||
|
|
@ -785,5 +777,4 @@ test('basic', async ({ }) => {
|
|||
// ...
|
||||
});
|
||||
```
|
||||
Note that the fixtures will still run once per [worker process](./test-parallel.md#worker-processes) but you don't need to redeclare them in every file.
|
||||
|
||||
Note that the fixtures will still run once per [worker process](./test-parallel.md#worker-processes), but you don't need to redeclare them in every file.
|
||||
|
|
|
|||
Loading…
Reference in a new issue