Skip to main content

externalSerenity

Implements

Index

Constructors

externalconstructor

  • Parameters

    • externalclock: Clock = ...
    • externalcwd: string = ...

    Returns Serenity

Methods

externalconfigure

  • 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.


    Parameters

    Returns void

externalengage

  • engage(actors: Cast): void
  • 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:

    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

  • theActorCalled(name: string): Actor
  • 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

    • externalname: string

      The name of the actor to instantiate or retrieve

    Returns Actor

externaltheActorInTheSpotlight

  • theActorInTheSpotlight(): Actor
  • 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

    Returns void

externalcurrentTime

  • Returns current wall clock time.


    Returns Timestamp

externalassignNewSceneId

  • assignNewSceneId(): CorrelationId
  • Returns CorrelationId

externalcurrentSceneId

  • currentSceneId(): CorrelationId
  • Returns CorrelationId

externalassignNewActivityId

  • assignNewActivityId(activityDetails: ActivityDetails): CorrelationId
  • Parameters

    • externalactivityDetails: ActivityDetails

    Returns CorrelationId

externalcreateError

  • createError<RE>(errorType: new (...args: any[]) => RE, options: ErrorOptions): RE
  • Type parameters

    Parameters

    • externalerrorType: new (...args: any[]) => RE
      • externaloptions: ErrorOptions

      Returns RE

    externalwaitForNextCue

    • waitForNextCue(): Promise<void>
    • @package

      Returns Promise<void>

    externalcwd

    • cwd(): Path
    • Returns Path