Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)),
));
});
}
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
});
.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),
),
);
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/')),
);
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/')),
);
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))),
));
});
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()));
it('allows the actor to read the browser log entries', () => Bernie.attemptsTo(
Navigate.to(pageFromTemplate(`
`)),
Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('Hello from the console!')))),
));
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)),
));
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'])),
));