Test.before Method

Executes the specified code before the test starts (the before test hook).

test.before( fn(t) )
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.

If a test runs in several browsers, the hook is executed in each browser.

When the hook runs, the tested webpage is loaded, so that you can use test actions and other test run API inside the hook.

If test.before is specified, it overrides the corresponding fixture.before, so that the latter is not executed.

fixture `My fixture`
    .page `http://example.com`;

test
    .before( async t => {
        await t
            .useRole(admin)
            .click('#open-management-console');
    })
    ('MyTest', async t => { /* ... */ });

To specify code executed after the test, use the test.after method.