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 used to access 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

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.

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 () => {
        /* ... */
    });