Fixture.afterEach Method

Defines the afterEach fixture hook. afterEach hooks run after each of the tests in the fixture and before TestCafe closes the browser.

Note

A fixture.beforeEach declaration may cause a hook conflict.

fixture.afterEach( fn(t) ) → this
Parameter Type Description
fn Function An asynchronous hook function that contains hook code.
t Object The test controller object with access to the test run API.

afterEach hooks can include test actions and other Test Controller API methods.

TestCafe executes afterEach hooks in the same browsers as the test, right after the test itself.

Use the fixture.beforeEach method to run hook code before each of the tests in the fixture.

Conflicting Hooks

Test-specific test.after hooks override the fixture-wide afterEach hook.

The global test.after hook follows local after hooks.

See: Hook Order and Priority.

Example

fixture`Fixture.afterEach`
    .page`https://devexpress.github.io/testcafe/example/`
    .afterEach(async t => {
        await t.click('#submit-button');
    });