Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat(protractor): LastScriptExecution.result() gives access to the va…
…lue returned by the script pass
- Loading branch information
Showing
with
239 additions
and 15 deletions.
- +2 −1 packages/core/src/errors/RuntimeError.ts
- +4 −4 packages/core/src/screenplay/actor/Actor.ts
- +12 −1 packages/protractor/spec/screenplay/interactions/execute-script/ExecuteAsynchronousScript.spec.ts
- +0 −1 packages/protractor/spec/screenplay/interactions/execute-script/ExecuteScriptFromUrl.spec.ts
- +12 −2 packages/protractor/spec/screenplay/interactions/execute-script/ExecuteSynchronousScript.spec.ts
- +102 −0 packages/protractor/spec/screenplay/interactions/execute-script/LastScriptExecution.spec.ts
- +33 −3 packages/protractor/src/screenplay/abilities/BrowseTheWeb.ts
- +56 −2 packages/protractor/src/screenplay/interactions/execute-script/ExecuteScript.ts
- +16 −0 packages/protractor/src/screenplay/interactions/execute-script/LastScriptExecution.ts
- +1 −0 packages/protractor/src/screenplay/interactions/execute-script/index.ts
- +1 −1 packages/protractor/src/screenplay/interactions/index.ts
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,102 @@ | ||
import { expect } from '@integration/testing-tools'; | ||
import { Ensure, equals } from '@serenity-js/assertions'; | ||
import { Actor, LogicError } from '@serenity-js/core'; | ||
import { by, error, protractor } from 'protractor'; | ||
import { BrowseTheWeb, Enter, ExecuteScript, LastScriptExecution, Navigate, Target } from '../../../../src'; | ||
import { pageFromTemplate } from '../../../fixtures'; | ||
|
||
/** @test {LastScriptExecution} */ | ||
describe('LastScriptExecution', function() { | ||
|
||
const Joe = () => Actor.named('Joe').whoCan( | ||
BrowseTheWeb.using(protractor.browser), | ||
); | ||
|
||
const page = pageFromTemplate(` | ||
<html> | ||
<body> | ||
<form> | ||
<input type="text" id="name" /> | ||
</form> | ||
</body> | ||
</html> | ||
`); | ||
|
||
class Sandbox { | ||
static Input = Target.the('input field').located(by.id('name')); | ||
} | ||
|
||
describe('when used with ExecuteScript.sync', () => { | ||
|
||
/** @test {ExecuteScript.sync} */ | ||
/** @test {ExecuteSynchronousScript} */ | ||
/** @test {LastScriptExecution} */ | ||
it('allows the actor to retrieve the result of the script execution', () => Joe().attemptsTo( | ||
Navigate.to(page), | ||
|
||
Enter.theValue(Joe().name).into(Sandbox.Input), | ||
|
||
ExecuteScript.sync(` | ||
var field = arguments[0]; | ||
return field.value; | ||
`).withArguments(Sandbox.Input), | ||
|
||
Ensure.that(LastScriptExecution.result<string>(), equals(Joe().name)), | ||
)); | ||
|
||
/** @test {ExecuteScript.sync} */ | ||
/** @test {ExecuteSynchronousScript} */ | ||
/** @test {LastScriptExecution} */ | ||
it('returns null if the script did not return any result', () => Joe().attemptsTo( | ||
Navigate.to(page), | ||
|
||
ExecuteScript.sync(` | ||
/* do nothing */ | ||
`), | ||
|
||
Ensure.that(LastScriptExecution.result<null>(), equals(null)), | ||
)); | ||
}); | ||
|
||
describe('when used with ExecuteScript.async', () => { | ||
|
||
/** @test {ExecuteScript.async} */ | ||
/** @test {ExecuteAsynchronousScript} */ | ||
/** @test {LastScriptExecution} */ | ||
it('allows the actor to retrieve the result of the script execution', () => Joe().attemptsTo( | ||
Navigate.to(page), | ||
|
||
Enter.theValue(Joe().name).into(Sandbox.Input), | ||
|
||
ExecuteScript.async(` | ||
var field = arguments[0]; | ||
var callback = arguments[arguments.length - 1]; | ||
callback(field.value); | ||
`).withArguments(Sandbox.Input), | ||
|
||
Ensure.that(LastScriptExecution.result<string>(), equals(Joe().name)), | ||
)); | ||
|
||
/** @test {ExecuteScript.async} */ | ||
/** @test {ExecuteAsynchronousScript} */ | ||
/** @test {LastScriptExecution} */ | ||
it('returns null if the script did not return any result', () => Joe().attemptsTo( | ||
Navigate.to(page), | ||
|
||
ExecuteScript.async(` | ||
var callback = arguments[arguments.length - 1]; | ||
callback(); | ||
`), | ||
|
||
Ensure.that(LastScriptExecution.result<null>(), equals(null)), | ||
)); | ||
}); | ||
|
||
/** @test {ExecuteAsynchronousScript} */ | ||
/** @test {LastScriptExecution} */ | ||
it(`complains if the script hasn't been executed yet`, () => expect(Joe().attemptsTo( | ||
Navigate.to(page), | ||
|
||
Ensure.that(LastScriptExecution.result<string>(), equals(Joe().name)), | ||
)).to.be.rejectedWith(LogicError, 'Make sure to execute a script before checking on the result')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,16 @@ | ||
import { Question } from '@serenity-js/core'; | ||
import { BrowseTheWeb } from '../../abilities'; | ||
|
||
export class LastScriptExecution { | ||
|
||
/** | ||
* @desc | ||
* Enables asserting on the result of a function executed via {@link ExecuteScript}. | ||
* | ||
* @returns {Question<Promise<R>>} | ||
*/ | ||
static result<R>(): Question<Promise<R>> { | ||
return Question.about(`last script execution result`, actor => | ||
BrowseTheWeb.as(actor).getLastScriptExecutionResult()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1,3 +1,4 @@ | ||
export * from './ExecuteScript'; | ||
export * from './ExecuteScriptFromUrl'; | ||
export * from './ExecuteScriptWithArguments'; | ||
export * from './LastScriptExecution'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters