Skip to main content

SerenityFixtures

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

Example test scenario

import { Ensure, equals } from '@serenity-js/assertions'
import { describe, it, test } from '@serenity-js/playwright-test'
import { Photographer, TakePhotosOfFailures } from '@serenity-js/web'

describe(`Recording items`, () => {

test.use({
defaultActorName: 'Serena',
crew: [
Photographer.whoWill(TakePhotosOfFailures),
],
})

describe(`Todo List App`, () => {

it(`should allow me to add a todo item`, async ({ actor }) => {
await actor.attemptsTo(
startWithAnEmptyList(),

recordItem('Buy some milk'),

Ensure.that(itemNames(), equals([
'Buy some milk',
])),
)
})
})
})

Learn more

Index

Properties

serenity

serenity: Serenity

Retrieves the root object of the Serenity/JS framework.

platform

platform: { name: string; version: string }

Name and version of the operating system that Playwright Test worker process runs on.


Type declaration

  • name: string
  • version: string

actors

actors: Cast

A cast of Serenity/JS actors to be used instead of the default cast when instantiating actor and invoking actorCalled.

Overriding the default cast of Serenity/JS actors

import { Cast, TakeNotes } from '@serenity-js/core'
import { Ensure, equals } from '@serenity-js/assertions'
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
import { describe, it, test } from '@serenity-js/playwright-test'

describe(`Recording items`, () => {

test.use({
defaultActorName: 'Serena',
actors: ({ browser, contextOptions }, use) => {
const cast = Cast.where(actor =>
actor.whoCan(
BrowseTheWebWithPlaywright.using(browser, contextOptions),
TakeNotes.usingAnEmptyNotepad(),
)
)

// Make sure to pass your custom cast to Playwright `use` callback
use(cast)
},
})

describe(`Todo List App`, () => {

it(`should allow me to add a todo item`, async ({ actor }) => {
await actor.attemptsTo(
startWithAnEmptyList(),

recordItem('Buy some milk'),

Ensure.that(itemNames(), equals([
'Buy some milk',
])),
)
})
})
})

actorCalled

actorCalled: (name: string) => Actor

Type declaration

    • (name: string): Actor

actor

actor: Actor

Default actor injected into a test scenario.

Using actor fixture is equivalent to invoking actorCalled with defaultActorName.

Learn more