Declares an afterEach hook that is executed after each test.
Details
When called in the scope of a test file, runs after each test in the file. When called inside a
test.describe(title, callback) group, runs after each
test in the group. If multiple afterEach hooks are added, they will run in the order of their registration.
You can access all the same Fixtures as the test function itself, and also the TestInfo object that
gives a lot of useful information. For example, you can check whether the test succeeded or failed.
Usage
// example.spec.ts import{ test, expect }from'@playwright/test'; test.afterEach(async({ page }, testInfo)=>{ console.log(`Finished ${testInfo.title} with status ${testInfo.status}`); if(testInfo.status!== testInfo.expectedStatus) console.log(`Did not run as expected, ended up at ${page.url()}`); }); test('my test',async({ page })=>{ // ... });
Declares an
afterEach
hook that is executed after each test.Details
When called in the scope of a test file, runs after each test in the file. When called inside a test.describe(title, callback) group, runs after each test in the group. If multiple
afterEach
hooks are added, they will run in the order of their registration.You can access all the same Fixtures as the test function itself, and also the TestInfo object that gives a lot of useful information. For example, you can check whether the test succeeded or failed.
Usage