liveBook · Manning

Task

As explained in BDD in Action, Second Edition

A Screenplay task is a reusable actor-behavior abstraction representing a meaningful activity, composed from interactions or other tasks.

A test that lists every click and field entry can hide the business action it is meant to verify. A Screenplay task gives that action a name: an actor performs a meaningful activity, while the task groups the interactions or smaller tasks needed to accomplish it. A task can contain just one interaction or represent an entire workflow. section 12.9 section 12.9.1

Build tasks from the goal down to the interface:

  • Name the goal in domain language, such as signing up, so a scenario communicates intent rather than a sequence of UI operations. section 15.1.2
  • Break the goal into subtasks. Signing up can mean locating the registration form, filling it out, and submitting it. section 15.1.1
  • Implement the lowest-level activities with interactions. A task can navigate to a page and click Register; those interactions use an actor’s abilities to reach the system. section 15.1.3
  • Pass details as parameters when the same activity must handle different cases. Reuse a sign-up task for valid registration or a duplicate-email scenario without duplicating its workflow. section 15.1.6

A small task with a useful name

A task named “Navigate to the home page” can wrap an Open.url() interaction. Other actors can then request the same activity without knowing the URL. Its description also makes execution reports more informative than a list of clicks and selectors. section 12.9.1

Listing 15.1 Implementing a pending task to SignUp
import { Task } from '@serenity-js/core'
 
const LocateRegistrationForm = () =>
    Task.where('#actor locates registration form')
 
const FillOutRegistrationForm = (travelerDetails: TravelerDetails) =>
    Task.where('#actor fills out registration form')
 
const SubmitRegistrationForm = () =>
    Task.where('#actor submits registration form')
 
const SignUp = (travelerDetails: TravelerDetails) =>
    Task.where('#actor signs up',
        LocateRegistrationForm(),
        FillOutRegistrationForm(travelerDetails),
        SubmitRegistrationForm(),
    )

The SignUp definition composes three named subtasks and passes traveler details to the form-filling task. Empty subtask definitions can mark work as pending while preserving the intended business workflow. section 15.1.2

Keep the task’s promise distinct from its implementation. A higher-level workflow can reuse the goal of locating a form without depending on how it is located; tasks that achieve the same goal can also be substituted. Use questions to check the resulting system state rather than treating the task name as an assertion. section 15.1.6 section 12.11

How BDD in Action, Second Edition covers it

How deep it goes
Works from named goals through subtasks and parameters to interaction composition, including pending implementations and concrete registration workflows.
Examples
Uses home-page navigation, registration-form interactions, and valid and duplicate-email sign-up scenarios.
What it assumes
Assumes familiarity with acceptance-test scenarios and basic code examples while defining the Screenplay elements and showing how tasks are assembled.
What you can do after
Build it from scratch with Task.where(), composing reusable activities and parameterizing them for different sign-up scenarios.
How it connects
Connects tasks to actors, interactions, abilities, questions, Cucumber step definitions, and domain-specific language.

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.