externalActorLifecycleManager
Index
Constructors
externalconstructor
Parameters
Returns ActorLifecycleManager
Methods
externalconfigure
externalassignTo
Associates this manager with a
Stageinstance.This method is called automatically by the
Stageduring construction. It establishes the bidirectional relationship between the manager and the stage, allowing the manager to emit domain events when actors enter the stage or are spotlighted.Parameters
externalstage: Stage
The Stage instance to associate with this manager
Returns void
externalengage
externalcurrentCast
publicexternalactor
Instantiates a new
Actoror fetches an existing one identified by their name if they've already been instantiated.When a new actor is instantiated, an
ActorEntersStageevent is announced. When the spotlight shifts to a different actor (or the same actor in a different scene), anActorSpotlightedevent is announced.Actors are first looked up in the
'background'focus area, then in'foreground'. New actors are always created in the current focus area.Parameters
externalname: string
Case-sensitive name of the Actor, e.g.
Alice
Returns Actor
The actor with the given name
publicexternalhasActorInTheSpotlight
Returns
trueif there is anActorin the spotlight,falseotherwise.Returns boolean
trueif an actor is currently spotlighted
publicexternalactorInTheSpotlight
externalswitchFocus
Switches the focus to the specified stage area.
Actors created after this call will be added to the specified area. This method is typically called automatically by the
Stagein response toSceneStartsandSceneFinishesevents.Test runner adapters can also call this method directly to control actor lifecycle when scene events are not available (e.g., in Playwright Test where the reporter runs in a separate process).
Parameters
externalfocus: StageFocus
The focus area to switch to:
'foreground'for scene-scoped actors,'background'for test run-scoped actors
Returns void
externalcurrentFocus
Returns the current focus area.
Returns StageFocus
The current focus:
'foreground'or'background'
externalactorsIn
Returns all actors in the specified focus area.
This method is used by the
Stageto retrieve actors for dismissal when scenes or test runs finish.Parameters
externalfocus: StageFocus
The focus area to retrieve actors from
Returns Actor[]
An array of actors in the specified focus area
externalclearSpotlightIfIn
Clears the spotlight if the current actor is in the specified focus area.
This ensures that after actors in a focus area are dismissed, the spotlight doesn't reference a dismissed actor.
Parameters
externalfocus: StageFocus
The focus area to check
Returns void
externalclearActorsIn
Clears all actors from the specified focus area.
This method is called by the
Stageafter actors have been dismissed to remove them from the internal tracking maps.Parameters
externalfocus: StageFocus
The focus area to clear
Returns void
Manages the lifecycle of actors on the stage, including their creation, retrieval, and tracking of which actors are in the foreground (scene-scoped) versus background (test run-scoped).
The
ActorLifecycleManageris responsible for:Default behaviour
By default, actors created before the actual test scenario starts, e.g. in beforeAll hooks, are placed in the
'background'focus area. When aSceneStartsevent is announced, the focus switches to'foreground'. When aSceneFinishesevent is announced, foreground actors are dismissed, their abilities discarded and focus returns to'background'.Custom lifecycle management
Test runner adapters like
@serenity-js/playwright-test, where test execution and reporting happen in separate processes, can inject a customActorLifecycleManagerinstance to control actor lifecycle programmatically.Learn more
StageCastActor