Generates a human-friendly description to be used when reporting this Activity.
Note: When this activity is reported, token
#actorin the description will be replaced with the name of the actor performing this Activity.
#actor clicks on a buttonbecomes
Wendy clicks on a button.
location: FileSystemLocation = ...
Tasks model sequences of activities and help you capture meaningful steps of an actor workflow in your domain.
Typically, tasks correspond to higher-level, business domain-specific activities like to
TransferFunds, and so on. However, higher-level tasks can and should be composed of lower-level tasks. For example, a task to
SignUpcould be composed of tasks to
The lowest-level tasks in your abstraction hierarchy should be composed of interactions. For example, a low-level task to
ProvideUsernamecould be composed of an interaction to Enter the value into a form field and Press the Key.Enter.
Tasks are the core building block of the Screenplay Pattern, along with Actors, Abilities, Interactions, and Questions.
Learn more about:
Defining a task
Defining a not implemented task
Note that calling Task.where method without providing the sequence of activities produces a Task that’s marked as “pending” in the test report.
This feature is useful when you want to quickly write down a task that will be needed in the scenario, but you’re not yet sure what activities it will involve.
Composing activities into tasks
The purpose of tasks is to help you capture domain vocabulary by associating domain meaning with a sequence of activities. From the implementation perspective, tasks help you give a meaningful description to such sequence and provide a way to easily reuse activities across your code base.
Tasks associate domain meaning with a sequence of lower-level activities and provide a mechanism for code reuse.
For example, a task to find a flight connection from London to New York could be modelled as a sequence of the following lower-level activities:
The easiest way to implement such task, and any custom Serenity/JS task for this matter, is to use the Task.where method to compose the lower-level activities:
Furthermore, if the actor was interacting with a web UI, a task to specify origin city could again be composed of other activities:
Conversely, a task to specify destination city could be composed of:
Conveniently, Serenity/JS modules provide low-level activities that allow actors to interact with the various interfaces of the system under test. For example, Serenity/JS Web module ships with activities such as Click or Enter, which we can incorporate into our task definitions just like any other activities:
As you can already see, tasks to specify origin city and specify destination city are almost identical, save for the name of the widget and the text value the actor is supposed to enter. Serenity/JS task-based code reuse model means that we can clean up such duplicated implementation by extracting a parameterised task, in this case called
As you work with Serenity/JS, you’ll notice that the ideas of functional decomposition, so thinking of tasks as sequences of lower-level activities, as well as functional composition, so implementing reusable activities and composing them into higher-level tasks, are at the heart of the Screenplay Pattern. You’ll also notice that the entire Serenity/JS framework does it best to help your team follow this approach.
What makes the Serenity/JS task-based code reuse model so powerful at scale is the observation that:
What this means in practice is that by investing your time in properly designing relatively few reusable tasks to test your system, you give your team a significant productivity boost and leverage when producing high-level test scenarios.
On top of that, this design approach results not only in simpler test scenarios that reduce the cognitive load on the reader as they require them to process the scenario only one level of abstraction at the time. It also allows for the test to take shortcuts in well-defined points of the workflow - use a REST API request to create a test user account instead of going through the registration form.