externalabstractCast
Index
Constructors
Methods
Constructors
externalconstructor
Returns Cast
Methods
staticexternalwhere
externalabstractprepare
Configures an
Actor
instantiated whenStage.actor
is invoked.Parameters
Returns Actor
Configures an Actor
instantiated when Stage.actor
is invoked.
Serenity/JS uses the concept of a cast of actors to centralise the process of configuring the actors and assigning their abilities.
When you invoke
actorCalled
for the first time in a test scenario, Serenity/JS instantiates a new actor and passes it through theCast.prepare
method. Specifying a custom cast gives you an opportunity to configure the actor with the abilities they need before it's returned to the caller, or configure the actors differently depending on their name. It also helps you to avoid having to configure abilities individually in every test scenario.A cast is responsible for assigning abilities to actors in a central location.
Configuring a cast of actors for the entire test suite
When working with relatively simple scenarios where all the actors should always receive the same set of abilities, you can
engage
Serenity/JS to use a genericCast.where
:If you're using Serenity/JS with one of the supported test runners, you might prefer to use your test runner's native configuration mechanism instead of invoking
engage
explicitly.Calling
configure
resets the entire Serenity/JS configuration and should be done exactly once in your entire test suite. If you want to retain the configuration but reset the cast, useengage
instead.Learn more about configuring Serenity/JS with:
Engaging a cast of actors for the specific scenario
If you want to retain Serenity/JS configuration, but set a different cast for the given test scenario you should use
engage
instead ofconfigure
.This approach is useful for example when your entire test suite is dedicated to interacting with the system under test via its REST APIs, and you have a handful of scenarios that need a web browser.
Writing custom casts for complex scenarios
In complex scenarios that involve multiple actors with different abilities, you should create a custom implementation of the cast.
Examples of such scenarios include those where actors use separate browser instances, interact with different REST APIs, or start with different data in their notepads.
Defining a custom cast of actors interacting with a Web UI
Preparing actors differently based on their name