liveBook · Manning

Ability

As explained in BDD in Action, Second Edition

An ability is a Screenplay capability that enables an actor to interact with a system through a particular mechanism, such as a browser or API.

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

How BDD in Action, Second Edition covers it

How deep it goes
Explains abilities as extensible Adapter wrappers and shows browser, API, question, and integration configurations.
Examples
Demonstrates Chrome WebDriver, REST access, current-URL retrieval, Playwright configuration, and composed web interactions.
What it assumes
Assumes Screenplay actors, interactions, questions, and tasks, while defining how actors gain system-specific capabilities.
What you can do after
Apply it via Screenplay by assigning actors browser or API abilities and letting interactions and questions use them.
How it connects
Connects actors, interactions, questions, tasks, the Adapter Pattern, WebDriver, REST APIs, and browser integration tools.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.