Skip to main content

Serenity

Implements

Index

Constructors

constructor

Methods

configure

  • 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

engage

  • 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

    Returns void

theActorCalled

  • 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

    • name: string

      The name of the actor to instantiate or retrieve

    Returns Actor

theActorInTheSpotlight

  • 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

announce

  • Parameters

    Returns void

currentTime

  • Returns current wall clock time.


    Returns Timestamp

assignNewSceneId

  • assignNewSceneId(): CorrelationId
  • Returns CorrelationId

currentSceneId

  • currentSceneId(): CorrelationId
  • Returns CorrelationId

assignNewActivityId

  • assignNewActivityId(activityDetails: ActivityDetails): CorrelationId
  • Parameters

    • activityDetails: ActivityDetails

    Returns CorrelationId

createError

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

waitForNextCue

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

    Returns Promise<void>

cwd

  • cwd(): Path
  • Returns Path