How to use @serenity-js/assertions - 10 common examples

To help you get started, we’ve selected a few @serenity-js/assertions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jan-molak / serenity-js / packages / protractor / spec / screenplay / questions / LastScriptExecution.spec.ts View on Github external
it('returns null if the script did not return any result', () => Joe.attemptsTo(
            Navigate.to(page),

            ExecuteScript.sync(`
                /* do nothing */
            `),

            Ensure.that(LastScriptExecution.result(), equals(null)),
        ));
    });
github jan-molak / serenity-js / packages / local-server / spec / servers.spec.ts View on Github external
}

            class Actors implements DressingRoom {
                prepare(actor: Actor): Actor {
                    return actor.whoCan(
                        ManageALocalServer.runningAHttpListener(handler()),
                        CallAnApi.using(axios.create()),
                    );
                }
            }

            Nadia = stage(new Actors()).theActorCalled('Nadia');

            return expect(Nadia.attemptsTo(
                StartLocalServer.onRandomPort(),
                Ensure.that(LocalServer.url(), startsWith('http://127.0.0.1')),
                Send.a(GetRequest.to(LocalServer.url())),
                Ensure.that(LastResponse.status(), equals(200)),
                Ensure.that(LastResponse.body(), equals('Hello World!')),
            )).to.be.fulfilled;                                                  // tslint:disable-line:no-unused-expression
        });
github jan-molak / serenity-js / packages / serenity-bdd / src / cli / screenplay / tasks / InvokeSerenityBDD.ts View on Github external
.then(([ args, props ]) =>
                actor.attemptsTo(
                    Check
                        .whether(FileExists.at(this.pathToArtifact), equals(false))
                        .andIfSo(TerminateFlow.because(
                            `I couldn't access the Serenity BDD CLI at ${ this.pathToArtifact.value }. ` +
                            `Did you remember to run \`serenity-bdd update\`?`,
                        )),
                    // todo: check if reports exist before invoking the jar?
                    Spawn.the(new JavaExecutable(), ...props, '-jar', this.pathToArtifact.value, ...args),
                ),
        );
github jan-molak / serenity-js / examples / cucumber-rest-api-level-testing / features / support / screenplay / tasks / RequestCalculationOf.ts View on Github external
export const RequestCalculationOf = (expression: string) =>
    Task.where(`#actor requests calculation of ${ expression }`,
        Send.a(
            PostRequest.to('/api/calculations').with(expression).using({ headers: { 'Content-Type': 'text/plain' }}),
        ),
        Ensure.that(LastResponse.status(), equals(201)),
        Ensure.that(LastResponse.header('location'), startsWith('/api/calculations/')),
    );
github jan-molak / serenity-js / examples / cucumber-rest-api-level-testing / features / support / screenplay / tasks / RequestCalculationOf.ts View on Github external
export const RequestCalculationOf = (expression: string) =>
    Task.where(`#actor requests calculation of ${ expression }`,
        Send.a(
            PostRequest.to('/api/calculations').with(expression).using({ headers: { 'Content-Type': 'text/plain' }}),
        ),
        Ensure.that(LastResponse.status(), equals(201)),
        Ensure.that(LastResponse.header('location'), startsWith('/api/calculations/')),
    );
github jan-molak / serenity-js / packages / protractor / spec / screenplay / questions / Browser.spec.ts View on Github external
it('clears the log upon invocation', () => Bernie.attemptsTo(
        Navigate.to(pageFromTemplate(`
            
                
                    <button id="trigger">Print to console</button>
                
            
        `)),

        Click.on(Trigger),
        Ensure.that(Browser.log(), property('length', equals(1))),

        Click.on(Trigger),
        Ensure.that(Browser.log(), property('length', equals(1))),
    ));
});
github jan-molak / serenity-js / packages / protractor / spec / screenplay / interactions / execute-script / ExecuteSynchronousScript.spec.ts View on Github external
it('emits the events so that the details of the script being executed can be reported', () => {
        const
            frozenClock = new Clock(() => new Date('1970-01-01')),

            theStage = stage(new UIActors(), frozenClock),
            actor = theStage.theActorCalled('Ashwin');

        sinon.spy(theStage, 'announce');

        return actor.attemptsTo(
            ExecuteScript.sync(`console.log('hello world');`),
            Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('hello world')))),
        ).then(() => {
            const events = (theStage.announce as sinon.SinonSpy).getCalls().map(call => call.lastArg);

            expect(events).to.have.lengthOf(5);
            expect(events[ 0 ]).to.be.instanceOf(ActivityStarts);
            expect(events[ 1 ]).to.be.instanceOf(ArtifactGenerated);
            expect(events[ 2 ]).to.be.instanceOf(ActivityFinished);

            const artifactGenerated = events[ 1 ] as ActivityRelatedArtifactGenerated;

            expect(artifactGenerated.name.value).to.equal(`Script source`);

            expect(artifactGenerated.artifact.equals(TextData.fromJSON({
                contentType: 'text/javascript;charset=UTF-8',
                data: 'console.log(\'hello world\');',
            }))).to.equal(true, JSON.stringify(artifactGenerated.artifact.toJSON()));
github jan-molak / serenity-js / packages / protractor / spec / screenplay / questions / Browser.spec.ts View on Github external
it('allows the actor to read the browser log entries', () =&gt; Bernie.attemptsTo(
        Navigate.to(pageFromTemplate(`
            
                
                    
                
            
        `)),

        Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('Hello from the console!')))),
    ));
github jan-molak / serenity-js / packages / protractor / spec / screenplay / questions / Cookie.spec.ts View on Github external
it('returns an undefined when it can\'t retrieve it', () => Sid.attemptsTo(
                Navigate.to(cookieCutterURLFor('/cookie?name=favourite&value=chocolate-chip')),
                Ensure.that(Cookie.expiryDateOf('not-so-favourite'), equals(undefined)),
            ));
github jan-molak / serenity-js / packages / protractor / spec / screenplay / questions / Text.spec.ts View on Github external
it('allows the actor to read the text of all DOM elements matching the locator', () => Bernie.attemptsTo(
            Navigate.to(testPage),

            Ensure.that(Text.ofAll(Shopping_List_Items), equals(['milk', 'oats'])),
        ));