Fixture.beforeEach Method

Defines the beforeEach fixture hook. beforeEach hooks run before each of the tests in the fixture, right after the browser loads the test page.


A fixture.beforeEach declaration may cause a hook conflict.

fixture.beforeEach( 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.

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

TestCafe executes beforeEach hooks in the same browsers as the test, but before the test itself.

Use the fixture.afterEach method to run hook code after each of the fixture tests.

Conflicting Hooks

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

Test-specific test.before hooks override the fixture-wide beforeEach hook.

See: Test Hook Order and Priority.


fixture `My fixture`
    .page ``
    .beforeEach( async t => {
        await t