Skip to main content

externalSerenityWorkerFixtures

Serenity/JS-specific worker-scope Playwright Test fixtures injected into your test scenarios.

Example test scenario

import { Ensure, equals } from '@serenity-js/assertions'
import { beforeAll, describe, it } from '@serenity-js/playwright-test'
import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'

describe('GitHub', () => {

beforeAll('Ensure system is ready to test', async ({ actorCalled }) => {
await actorCalled('Stagehand')
.whoCan(CallAnApi.at('https://www.githubstatus.com/api/v2/'))
.attemptsTo(
Send.a(GetRequest.to('status.json')),
Ensure.that(
LastResponse.status(),
equals(200)
),
Ensure.that(
LastResponse.body().status.description,
equals('All Systems Operational')
),
);
});
});

Learn more

Index

Properties

externalplatform

platform: { name: string; version: string }

Information about the operating system platform where the Playwright Test worker process runs.

Returns an object with:

  • name - The platform name: 'Windows', 'macOS', or 'Linux'
  • version - The OS version string from os.release()

This information is used to tag test scenarios with platform metadata for reporting purposes.


Type declaration

  • externalname: string
  • externalversion: string

externalserenity

serenity: Serenity

The root Serenity instance for this worker.

Provides access to the Serenity/JS framework for advanced use cases, such as:

In most test scenarios, you won't need to interact with the serenity fixture directly. Instead, use the actor or actorCalled fixtures.

Learn more

externalactorCalled

actorCalled: (name: string) => Actor

Uses the provided cast of actors to instantiate an Actor called name and inject it into a test scenario.

Retrieves an existing actor if one has already been instantiated.

Learn more


Type declaration

    • Parameters

      • externalname: string

      Returns Actor

externalinteractionTimeout

interactionTimeout: number | Duration

The maximum default amount of time allowed for interactions such as Wait.until to complete.

Defaults to 5 seconds, can be overridden per interaction.

Learn more

externalextraWorkerAbilities

extraWorkerAbilities: Ability[] | (actorName: string) => Ability[]

Extra abilities given to actors at the worker scope, on top of the default ones provided by the actors fixture.

Unlike extraAbilities, which are test-scoped, extraWorkerAbilities persist across all tests within the same worker process. This is useful for abilities that are expensive to create or that maintain state across tests.

Extra abilities for all actors

To give the same set of extra abilities to all the actors, provide an array of Ability objects:

// playwright.config.ts
import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
import { defineConfig } from '@playwright/test'
import { MySharedAbility } from './MySharedAbility'

export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
use: {
extraWorkerAbilities: [ new MySharedAbility() ],
},
})

Extra abilities for selected actors

To give extra abilities only to selected actors, provide a function that maps the actor name to an array of Ability objects:

// playwright.config.ts
import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
import { defineConfig } from '@playwright/test'
import { MySharedAbility } from './MySharedAbility'

export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
use: {
extraWorkerAbilities: (actorName: string) => {
return actorName === 'Admin'
? [ new MySharedAbility() ]
: [];
},
},
})

Learn more