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.


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 the hook code.
t Object The test controller used to access 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

TestCafe executes global hooks before it executes fixture hooks and test hooks.

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

See: Test Hook Order and Priority.


fixture `My fixture`
    .page ``
    .afterEach( async t => {