Skip to main content

beforeAll

Callable

  • beforeAll(inner: (args: PlaywrightTestArgs & PlaywrightTestOptions & Omit<SerenityOptions, actors> & SerenityFixtures & PlaywrightWorkerArgs & PlaywrightWorkerOptions & object, testInfo: TestInfo) => any): void
  • beforeAll(title: string, inner: (args: PlaywrightTestArgs & PlaywrightTestOptions & Omit<SerenityOptions, actors> & SerenityFixtures & PlaywrightWorkerArgs & PlaywrightWorkerOptions & object, testInfo: TestInfo) => any): void

  • Declares a beforeAll hook that is executed once per worker process before all tests.

    When called in the scope of a test file, runs before all tests in the file. When called inside a test.describe([title, details, callback]) group, runs before all tests in the group.

    You can use test.afterAll([title, hookFunction]) to teardown any resources set up in beforeAll.

    • test.beforeAll(hookFunction)
    • test.beforeAll(title, hookFunction)

    Details

    When multiple beforeAll hooks are added, they will run in the order of their registration.

    Note that worker process is restarted on test failures, and beforeAll hook runs again in the new worker. Learn more about workers and failures.

    Playwright will continue running all applicable hooks even if some of them have failed.

    Usage

    // example.spec.ts
    import { test, expect } from '@playwright/test';

    test.beforeAll(async () => {
    console.log('Before tests');
    });

    test.afterAll(async () => {
    console.log('After tests');
    });

    test('my test', async ({ page }) => {
    // ...
    });

    Alternatively, you can declare a hook with a title.

    // example.spec.ts
    test.beforeAll('Setup', async () => {
    console.log('Before tests');
    });

    Parameters

    • inner: (args: PlaywrightTestArgs & PlaywrightTestOptions & Omit<SerenityOptions, actors> & SerenityFixtures & PlaywrightWorkerArgs & PlaywrightWorkerOptions & object, testInfo: TestInfo) => any

    Returns void