externalSerenityFixtures
Index
Properties
externaldefaultActorName
Configures the name given to the default Serenity/JS actor
injected into a test scenario.
Learn more
- Declaring a Serenity/JS test scenario
SerenityFixtures
externalcrew
Configures the stage crew members to be instantiated in Playwright Test worker processes.
By default, Serenity/JS registers a Photographer.whoWill(TakePhotosOfFailures),
so that any test failures are automatically accompanied by a screenshot.
If you prefer a different behaviour, you can configure the crew with an empty array to disable taking screenshots altogether (crew: []),
or with a Photographer who uses a different PhotoTakingStrategy, like to TakePhotosOfInteractions.
Example
// playwright.config.ts
import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
import { defineConfig } from '@playwright/test'
export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
use: {
crew: [
[ '@serenity-js/web:Photographer', { strategy: 'TakePhotosOfFailures' } ]
],
},
});
Learn more
externalcueTimeout
Sets the cueTimeout to a given duration or a numeric value in milliseconds.
Defaults to 5 seconds.
Learn more
externalinteractionTimeout
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
externalextraContextOptions
Convenience properties to be used with the ability
to BrowseTheWebWithPlaywright,
in addition to Playwright BrowserContextOptions:
Using extraContextOptions with the default cast of Serenity/JS actors
// playwright.config.ts
import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
import { defineConfig } from '@playwright/test'
export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
use: {
extraContextOptions: {
defaultNavigationTimeout: 30_000,
}
// Since `actors` property is not defined,
// `extraContextOptions` will be passed to the default cast of Serenity/JS actors
// and injected into the ability to `BrowseTheWebWithPlaywright`
// that each actor receives.
},
})
Using extraContextOptions with a custom cast of Serenity/JS actors
// playwright.config.ts
import type { SerenityFixtures, SerenityWorkerFixtures } from '@serenity-js/playwright-test'
import { defineConfig } from '@playwright/test'
export default defineConfig<SerenityFixtures, SerenityWorkerFixtures>({
use: {
extraContextOptions: {
defaultNavigationTimeout: 30_000,
}
// Custom cast of actors receives the default `contextOptions` and
// the `extraContextOptions` with the additional Serenity/JS properties.
actors: async ({ browser, contextOptions, extraContextOptions }, use) => {
const cast = Cast.where(actor => actor.whoCan(
BrowseTheWebWithPlaywright.using(browser, contextOptions, extraContextOptions),
TakeNotes.usingAnEmptyNotepad(),
))
await use(cast)
},
},
})
Learn more
externalextraAbilities
Extra abilities given to the actors on top of the default ones provided by the actors fixture.
Extra abilities for all actors
To give the same set of extra abilities to all the actors, make your extraAbilities fixture
return an array of Ability objects.
import { type Ability } from '@serenity-js/core';
import { describe, it, test } from '@serenity-js/playwright-test';
import { MyAbility } from './MyAbility';
describe(`My feature`, () => {
test.use({
extraAbilities: [ new MyAbility() ]
});
it(`...`, async({ actor }) => {
// ...
});
});
Extra abilities for selected actors
To give extra abilities only to selected actors, make your extraAbilities fixture return a (actorName: string) => Ability[] function that maps
the actor name to an array of Ability objects.
import { describe, it, test } from '@serenity-js/playwright-test';
import { MyAbility } from './MyAbility';
describe(`My feature`, () => {
test.use({
extraAbilities: async ({ }, use) => {
await use((actorName: string) => {
// Alice gets the extra abilities, but others don't
return actorName === 'Alice'
? [ new MyAbility() ]
: [];
})
}
});
it(`...`, async({ actor }) => {
// ...
});
});
externalactors
A cast of Serenity/JS actors to be used instead of the default cast
when instantiating actor
and invoking actorCalled.
Serenity/JS test APIs offer fixtures that set up the default cast of actors for you, which should be sufficient in most web and HTTP API testing scenarios.
Each one of the default actors receives the following abilities:
BrowseTheWebWithPlaywright, connected to PlaywrightpagefixtureTakeNotesCallAnApi, pointing at thebaseURLand using anyproxysettings in your Playwright config file.
The easiest way to give your actors additional abilities is to use the extraAbilities fixture.
Overriding the default cast of Serenity/JS actors
import { Ensure, equals } from '@serenity-js/assertions'
import { Cast, TakeNotes } from '@serenity-js/core'
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
import { CallAnApi } from '@serenity-js/rest'
import { describe, it, test } from '@serenity-js/playwright-test'
interface MyNotes {
username: string;
}
describe(`Recording items`, () => {
test.use({
extraContextOptions: {
defaultNavigationTimeout: 30_000,
},
actors: async ({ axios, extraAbilities, extraContextOptions, extraHTTPHeaders, page }, use) => {
const cast = Cast.where(actor => {
const abilities = Array.isArray(extraAbilities)
? extraAbilities
: extraAbilities(actor.name);
return actor.whoCan(
BrowseTheWebWithPlaywright.usingPage(page, extraContextOptions),
TakeNotes.using<MyNotes>(Notepad.with({
username: 'example.username'
}),
CallAnApi.using(axios),
...abilities,
)
})
// Make sure to pass your custom cast to Playwright `use` callback
await 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',
])),
)
})
})
})
#### Learn more
- Declaring a Serenity/JS [test scenario](/api/playwright-test/function/it/)
- [`SerenityFixtures`](/api/playwright-test/interface/SerenityFixtures/)
externalactor
Default actor injected into a test scenario.
Using actor fixture is equivalent to invoking actorCalled
with defaultActorName.
Learn more
actorCalleddefaultActorName- Declaring a Serenity/JS test scenario
Serenity/JS-specific Playwright Test fixtures injected into your test scenarios.
Configuring Serenity/JS using a test file
Configuring Serenity/JS using Playwright configuration file
Learn more
PlaywrightTestConfigCastSerenityFixtures