Multi-actor scenarios
Some workflows involve more than one participant, such as a buyer placing an order while a seller fulfils it, or a support agent responding to a customer request. Serenity/JS represents each participant as an Actor and, unless their work needs separate browser state or authentication, they share the Playwright Test browser session.
Using multiple actors in a scenario
To inject multiple actors into your test scenario, use the actorCalled fixture:
./spec/todo_app.spec.ts
import { describe, it, beforeEach } from '@serenity-js/playwright-test'
import { Navigate } from '@serenity-js/web'
import { Ensure, equals } from '@serenity-js/assertions'
import { TodoApp } from './screenplay/TodoApp'
describe('Todo App', () => {
describe('Guest user', () => {
it('shares the list with other guests using the same browser', async ({ actorCalled }) => {
await actorCalled('Alice').attemptsTo(
Navigate.to('https://todo-app.serenity-js.org/#/'),
TodoApp.recordItem('Read a book'),
Ensure.that(TodoApp.recordedItems(), equals([
'Read a book'
])),
)
// By default, Alice and Bob use the same browser session
// so Bob sees the same list as Alice
await actorCalled('Bob').attemptsTo(
Ensure.that(TodoApp.recordedItems(), equals([
'Read a book'
])),
)
})
})
})
Multi-browser test scenarios
By default, all actors share the same browser session. To make them use independent browsers, see Using multiple browsers.
What you learnt
- Use the
actorCalledfixture to introduce multiple named actors into a scenario. - By default, all actors share the same browser session (same
pageinstance). - Give actors separate browsing abilities when they need independent browser state.
Next step
Learn how to customise actor abilities, including using multiple browsers and sharing notes between actors.