externalSerenity
Implements
Index
Constructors
externalconstructor
Methods
externalconfigure
Parameters
externalconfig: SerenityConfig
Returns void
externalengage
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 callingActor.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
externalactors: Cast
Returns void
externaltheActorCalled
Instantiates or retrieves an
Actor
calledname
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
externalname: string
The name of the actor to instantiate or retrieve
Returns Actor
externaltheActorInTheSpotlight
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
externalannounce
Parameters
externalrest...events: DomainEvent[]
Returns void
externalcurrentTime
Returns current wall clock time.
Returns Timestamp
externalassignNewSceneId
Returns CorrelationId
externalcurrentSceneId
Returns CorrelationId
externalassignNewActivityId
Parameters
externalactivityDetails: ActivityDetails
Returns CorrelationId
externalcreateError
Type parameters
- RE: RuntimeError
Parameters
externalerrorType: new (...args: any[]) => RE
externaloptions: ErrorOptions
Returns RE
externalwaitForNextCue
Returns Promise<void>
externalcwd
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.