Skip to content

Commit

Permalink
Merge branch 'features/execute-script'
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-molak committed May 12, 2024
2 parents 02fabc5 + 7faec10 commit 52b061e
Show file tree
Hide file tree
Showing 20 changed files with 27,614 additions and 11,093 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ rules:
Prop: true
Props: true
props: true
Ref: true
Refs: true
ref: true
refs: true
TOC: true
toc: true
temp: true
Expand Down
1 change: 1 addition & 0 deletions integration/playwright-test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules
# Build artifacts
lib
playwright-report
test-results
output
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ensure, equals } from '@serenity-js/assertions';
import { actorCalled, Clock, Question, Serenity, serenity } from '@serenity-js/core';
import { ActivityFinished, ActivityRelatedArtifactGenerated, ActivityStarts, ArtifactGenerated, SceneFinishes, SceneStarts } from '@serenity-js/core/lib/events';
import { TextData } from '@serenity-js/core/lib/model';
import { By, ExecuteScript, LastScriptExecution, Navigate, PageElement, Switch, Value } from '@serenity-js/web';
import { By, ExecuteScript, LastScriptExecution, Navigate, PageElement, PageElements, Switch, Value } from '@serenity-js/web';

import { defaultCardScenario, sceneId } from '../../../stage/crew/photographer/fixtures';

Expand Down Expand Up @@ -118,7 +118,7 @@ describe('ExecuteAsynchronousScript', function () {
Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute an asynchronous script with a Target argument', () =>
it('allows the actor to execute an asynchronous script with a PageElement argument', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

Expand All @@ -136,6 +136,98 @@ describe('ExecuteAsynchronousScript', function () {
Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

describe('when working with page elements', () => {
it('allows the actor to execute a synchronous script with a PageElement argument', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.async(`
var name = arguments[0];
var field = arguments[1];
var callback = arguments[arguments.length - 1];
setTimeout(function () {
field.value = name;
callback();
}, 100);
`).withArguments(actorCalled('Joe').name, Sandbox.Input),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with a record of PageElement objects', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.async(`
var name = arguments[0];
var field = arguments[1].include[0];
var callback = arguments[arguments.length - 1];
setTimeout(function () {
field.value = name;
callback();
}, 100);
`).withArguments(actorCalled('Joe').name, Question.fromObject({ include: [ Sandbox.Input ] })),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with an array of PageElement objects', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.async(`
var name = arguments[0];
var field = arguments[1][0];
var callback = arguments[arguments.length - 1];
setTimeout(function () {
field.value = name;
callback();
}, 100);
`).withArguments(actorCalled('Joe').name, Question.fromArray([ Sandbox.Input ])),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with a PageElements argument', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.async(`
var name = arguments[0];
var field = arguments[1][0];
var callback = arguments[arguments.length - 1];
setTimeout(function () {
field.value = name;
callback();
}, 100);
`).withArguments(actorCalled('Joe').name, PageElements.located(By.css('input')) ),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with a PageElement determined by PEQL', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.async(`
var name = arguments[0];
var field = arguments[1];
var callback = arguments[arguments.length - 1];
setTimeout(function () {
field.value = name;
callback();
}, 100);
`).withArguments(actorCalled('Joe').name, PageElements.located(By.css('input')).first() ),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));
});

it('provides a sensible description of the interaction being performed when invoked without arguments', () => {
expect(ExecuteScript.async(`
arguments[arguments.length - 1]();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ensure, equals, includes } from '@serenity-js/assertions';
import { actorCalled, Clock, Question, Serenity, serenity } from '@serenity-js/core';
import { ActivityFinished, ActivityRelatedArtifactGenerated, ActivityStarts, ArtifactGenerated, SceneFinishes, SceneStarts } from '@serenity-js/core/lib/events';
import { TextData } from '@serenity-js/core/lib/model';
import { By, ExecuteScript, LastScriptExecution, Navigate, PageElement, Switch, Value } from '@serenity-js/web';
import { By, ExecuteScript, LastScriptExecution, Navigate, PageElement, PageElements, Switch, Value } from '@serenity-js/web';

import { defaultCardScenario, sceneId } from '../../../stage/crew/photographer/fixtures';

Expand Down Expand Up @@ -100,19 +100,77 @@ describe('ExecuteSynchronousScript', function () {
Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with a Target argument', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),
describe('when working with page elements', () => {
it('allows the actor to execute a synchronous script with a PageElement argument', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.sync(`
var name = arguments[0];
var field = arguments[1];
ExecuteScript.sync(`
var name = arguments[0];
var field = arguments[1];
field.value = name;
`).withArguments(actorCalled('Joe').name, Sandbox.Input),

field.value = name;
`).withArguments(actorCalled('Joe').name, Sandbox.Input),
Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));
it('allows the actor to execute a synchronous script with a record of PageElement objects', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.sync(`
var name = arguments[0];
var field = arguments[1].include[0];
field.value = name;
`).withArguments(actorCalled('Joe').name, Question.fromObject({ include: [ Sandbox.Input ] })),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with an array of PageElement objects', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.sync(`
var name = arguments[0];
var field = arguments[1][0];
field.value = name;
`).withArguments(actorCalled('Joe').name, Question.fromArray([ Sandbox.Input ])),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with a PageElements argument', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.sync(`
var name = arguments[0];
var field = arguments[1][0];
field.value = name;
`).withArguments(actorCalled('Joe').name, PageElements.located(By.css('input')) ),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));

it('allows the actor to execute a synchronous script with a PageElement determined by PEQL', () =>
actorCalled('Joe').attemptsTo(
Navigate.to('/screenplay/interactions/execute-script/input_field.html'),

ExecuteScript.sync(`
var name = arguments[0];
var field = arguments[1];
field.value = name;
`).withArguments(actorCalled('Joe').name, PageElements.located(By.css('input')).first() ),

Ensure.that(Value.of(Sandbox.Input), equals(actorCalled('Joe').name)),
));
});

it('provides a sensible description of the interaction being performed when invoked without arguments', () => {
expect(ExecuteScript.sync(`
Expand Down
Loading

0 comments on commit 52b061e

Please sign in to comment.