An ability is a Screenplay capability that lets an actor interact with a system through a particular mechanism, such as a web browser, REST API, database, or mainframe. Actors use abilities to perform interactions and answer questions about system state. section 12.2 section 12.6
Abilities connect actor behavior to interface-specific systems:
- BrowseTheWeb gives an actor access to a browser and its WebDriver instance. section 12.6
- CallAnApi gives an actor the capability to query a REST endpoint. section 12.6
- Questions use an actor’s abilities to query the system from that actor’s perspective. section 12.8
- New abilities can extend the model without changing the actor implementation for each additional system. section 12.6
An ability acts as an Adapter: a thin wrapper around a browser driver, HTTP client, database client, or other low-level integration. Tasks and interactions can therefore express actor behavior without exposing every tool-specific API. section 12.6 section 15.1.3
WebDriver driver = new ChromeDriver(); #1
Actor sally = Actor.named("Sally"); #2
sally.can(BrowseTheWeb.with(driver)); #3
A compact example assigns a Chrome WebDriver instance to an actor through BrowseTheWeb. section 12.6
Listing 14.1 Configuring a generic cast of actors to use Playwright
import { BeforeAll, AfterAll } from '@cucumber/cucumber'
import { configure, Cast } from '@serenity-js/core'
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
import * as playwright from 'playwright'
let browser: playwright.Browser
BeforeAll(async () => { #1
browser = await playwright.chromium.launch({ #2
headless: true,
})
configure({ #3
actors: Cast.whereEveryoneCan(
BrowseTheWebWithPlaywright.using(browser), #4
)
})
})
AfterAll(async () => { #5
await browser.close()
})
A Serenity/JS configuration gives every actor a shared Playwright-backed web ability while keeping browser setup and cleanup in lifecycle hooks. section 14.2.2
