Test.after Method

Defines the after test hook. After hooks run after the end of the test, but before TestCafe closes the browser.

Note

A test.after declaration may cause a hook conflict.

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

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

TestCafe executes test hooks in the same browsers as the test - before and after the test itself.

Use the test.before method to run hook code before the test.

Conflicting Hooks

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

The globaltest.after hook follows local after hooks.

See: Hook Order and Priority.

Example

fixture`Test.after`
    .page`https://devexpress.github.io/testcafe/example/`;

test
    .after(async t => {
        await t.click('[data-testid="remote-testing-checkbox"]');
    })('Click on checkbox', async () => {
        /* ... */
    });