Serenity
Implements
Index
Constructors
constructor
Methods
configure
Parameters
config: SerenityConfig
Returns void
engage
Re-configures Serenity/JS with a new Cast of actors you want to use in any subsequent calls to actorCalled.
For your convenience, use engage function instead, which provides an alternative to calling Actor.whoCan directly in your tests and is typically invoked in a “before all” or “before each” hook of your test runner of choice.
If your implementation of the Cast interface is stateless, you can invoke this function just once before your entire test suite is executed, see
However, if your Cast holds state that you want to reset before each scenario, it’s better to invoke
engage
before each test using:beforeEach
in JasminebeforeEach
in Mocha,Before
in Cucumber.js
Engaging a cast of actors
import { Actor, Cast } from '@serenity-js/core';
class Actors implements Cast {
prepare(actor: Actor) {
return actor.whoCan(
// ... abilities you'd like the Actor to have
);
}
}
engage(new Actors());Using with Mocha test runner
import { beforeEach } from 'mocha'
beforeEach(() => engage(new Actors()))Using with Jasmine test runner
import 'jasmine'
beforeEach(() => engage(new Actors()))Using with Cucumber.js test runner
import { Before } from '@cucumber/cucumber'
Before(() => engage(new Actors()))Learn more
Parameters
actors: Cast
Returns void
theActorCalled
Instantiates or retrieves an Actor called
name
if one has already been instantiated.For your convenience, use actorCalled function instead.
Usage with Mocha
import { describe, it } from 'mocha';
import { actorCalled } from '@serenity-js/core';
describe('Feature', () => {
it('should have some behaviour', () =>
actorCalled('James').attemptsTo(
// ... activities
))
})Usage with Jasmine
import 'jasmine';
import { actorCalled } from '@serenity-js/core';
describe('Feature', () => {
it('should have some behaviour', () =>
actorCalled('James').attemptsTo(
// ... activities
))
})Usage with Cucumber
import { actorCalled } from '@serenity-js/core';
import { Given } from '@cucumber/cucumber';
Given(/(.*?) is a registered user/, (name: string) =>
actorCalled(name).attemptsTo(
// ... activities
))Learn more
Parameters
name: string
The name of the actor to instantiate or retrieve
Returns Actor
theActorInTheSpotlight
Retrieves an actor who was last instantiated or retrieved using Serenity.theActorCalled.
This function is particularly useful when automating Cucumber scenarios.
For your convenience, use actorInTheSpotlight function instead.
Usage with Cucumber
import { actorCalled } from '@serenity-js/core';
import { Given, When } from '@cucumber/cucumber';
Given(/(.*?) is a registered user/, (name: string) =>
actorCalled(name).attemptsTo(
// ... activities
))
When(/(?:he|she|they) browse their recent orders/, () =>
actorInTheSpotlight().attemptsTo(
// ... activities
))Learn more
Returns Actor
announce
Parameters
rest...events: DomainEvent[]
Returns void
currentTime
Returns current wall clock time.
Returns Timestamp
assignNewSceneId
Returns CorrelationId
currentSceneId
Returns CorrelationId
assignNewActivityId
Parameters
activityDetails: ActivityDetails
Returns CorrelationId
createError
Type parameters
- RE: RuntimeError
Parameters
errorType: new (...args: any[]) => RE
options: ErrorOptions
Returns RE
waitForNextCue
Returns Promise<void>
cwd
Returns Path
Configures Serenity/JS. Every call to this function replaces the previous configuration provided, so this function should be called exactly once in your test suite.