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.

Note

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 hook code.
t Object The test controller object with access to the 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 the global before hook before it executes other before hooks.

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

See: Hook Order and Priority.

Example

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