@serenity-js/web 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/LICENSE.md +201 -0
- package/NOTICE.md +1 -0
- package/README.md +21 -0
- package/lib/errors/CookieMissingError.d.ts +4 -0
- package/lib/errors/CookieMissingError.js +11 -0
- package/lib/errors/CookieMissingError.js.map +1 -0
- package/lib/errors/index.d.ts +1 -0
- package/lib/errors/index.js +14 -0
- package/lib/errors/index.js.map +1 -0
- package/lib/expectations/ElementExpectation.d.ts +11 -0
- package/lib/expectations/ElementExpectation.js +27 -0
- package/lib/expectations/ElementExpectation.js.map +1 -0
- package/lib/expectations/index.d.ts +6 -0
- package/lib/expectations/index.js +19 -0
- package/lib/expectations/index.js.map +1 -0
- package/lib/expectations/isActive.d.ts +15 -0
- package/lib/expectations/isActive.js +22 -0
- package/lib/expectations/isActive.js.map +1 -0
- package/lib/expectations/isClickable.d.ts +20 -0
- package/lib/expectations/isClickable.js +30 -0
- package/lib/expectations/isClickable.js.map +1 -0
- package/lib/expectations/isEnabled.d.ts +14 -0
- package/lib/expectations/isEnabled.js +20 -0
- package/lib/expectations/isEnabled.js.map +1 -0
- package/lib/expectations/isPresent.d.ts +15 -0
- package/lib/expectations/isPresent.js +22 -0
- package/lib/expectations/isPresent.js.map +1 -0
- package/lib/expectations/isSelected.d.ts +14 -0
- package/lib/expectations/isSelected.js +23 -0
- package/lib/expectations/isSelected.js.map +1 -0
- package/lib/expectations/isVisible.d.ts +14 -0
- package/lib/expectations/isVisible.js +26 -0
- package/lib/expectations/isVisible.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/lib/input/Key.d.ts +73 -0
- package/lib/input/Key.js +84 -0
- package/lib/input/Key.js.map +1 -0
- package/lib/input/index.d.ts +1 -0
- package/lib/input/index.js +14 -0
- package/lib/input/index.js.map +1 -0
- package/lib/screenplay/abilities/BrowseTheWeb.d.ts +58 -0
- package/lib/screenplay/abilities/BrowseTheWeb.js +19 -0
- package/lib/screenplay/abilities/BrowseTheWeb.js.map +1 -0
- package/lib/screenplay/abilities/BrowserCapabilities.d.ts +5 -0
- package/lib/screenplay/abilities/BrowserCapabilities.js +3 -0
- package/lib/screenplay/abilities/BrowserCapabilities.js.map +1 -0
- package/lib/screenplay/abilities/index.d.ts +2 -0
- package/lib/screenplay/abilities/index.js +15 -0
- package/lib/screenplay/abilities/index.js.map +1 -0
- package/lib/screenplay/index.d.ts +4 -0
- package/lib/screenplay/index.js +17 -0
- package/lib/screenplay/index.js.map +1 -0
- package/lib/screenplay/interactions/Clear.d.ts +79 -0
- package/lib/screenplay/interactions/Clear.js +97 -0
- package/lib/screenplay/interactions/Clear.js.map +1 -0
- package/lib/screenplay/interactions/Click.d.ts +73 -0
- package/lib/screenplay/interactions/Click.js +85 -0
- package/lib/screenplay/interactions/Click.js.map +1 -0
- package/lib/screenplay/interactions/DoubleClick.d.ts +90 -0
- package/lib/screenplay/interactions/DoubleClick.js +101 -0
- package/lib/screenplay/interactions/DoubleClick.js.map +1 -0
- package/lib/screenplay/interactions/Enter.d.ts +73 -0
- package/lib/screenplay/interactions/Enter.js +86 -0
- package/lib/screenplay/interactions/Enter.js.map +1 -0
- package/lib/screenplay/interactions/EnterBuilder.d.ts +25 -0
- package/lib/screenplay/interactions/EnterBuilder.js +3 -0
- package/lib/screenplay/interactions/EnterBuilder.js.map +1 -0
- package/lib/screenplay/interactions/ExecuteScript.d.ts +206 -0
- package/lib/screenplay/interactions/ExecuteScript.js +312 -0
- package/lib/screenplay/interactions/ExecuteScript.js.map +1 -0
- package/lib/screenplay/interactions/Hover.d.ts +78 -0
- package/lib/screenplay/interactions/Hover.js +89 -0
- package/lib/screenplay/interactions/Hover.js.map +1 -0
- package/lib/screenplay/interactions/Navigate.d.ts +142 -0
- package/lib/screenplay/interactions/Navigate.js +198 -0
- package/lib/screenplay/interactions/Navigate.js.map +1 -0
- package/lib/screenplay/interactions/PageElementInteraction.d.ts +39 -0
- package/lib/screenplay/interactions/PageElementInteraction.js +54 -0
- package/lib/screenplay/interactions/PageElementInteraction.js.map +1 -0
- package/lib/screenplay/interactions/Press.d.ts +84 -0
- package/lib/screenplay/interactions/Press.js +171 -0
- package/lib/screenplay/interactions/Press.js.map +1 -0
- package/lib/screenplay/interactions/PressBuilder.d.ts +26 -0
- package/lib/screenplay/interactions/PressBuilder.js +3 -0
- package/lib/screenplay/interactions/PressBuilder.js.map +1 -0
- package/lib/screenplay/interactions/RightClick.d.ts +89 -0
- package/lib/screenplay/interactions/RightClick.js +100 -0
- package/lib/screenplay/interactions/RightClick.js.map +1 -0
- package/lib/screenplay/interactions/Scroll.d.ts +83 -0
- package/lib/screenplay/interactions/Scroll.js +97 -0
- package/lib/screenplay/interactions/Scroll.js.map +1 -0
- package/lib/screenplay/interactions/Select.d.ts +212 -0
- package/lib/screenplay/interactions/Select.js +291 -0
- package/lib/screenplay/interactions/Select.js.map +1 -0
- package/lib/screenplay/interactions/SelectBuilder.d.ts +33 -0
- package/lib/screenplay/interactions/SelectBuilder.js +3 -0
- package/lib/screenplay/interactions/SelectBuilder.js.map +1 -0
- package/lib/screenplay/interactions/Switch.d.ts +150 -0
- package/lib/screenplay/interactions/Switch.js +209 -0
- package/lib/screenplay/interactions/Switch.js.map +1 -0
- package/lib/screenplay/interactions/TakeScreenshot.d.ts +67 -0
- package/lib/screenplay/interactions/TakeScreenshot.js +86 -0
- package/lib/screenplay/interactions/TakeScreenshot.js.map +1 -0
- package/lib/screenplay/interactions/Wait.d.ts +143 -0
- package/lib/screenplay/interactions/Wait.js +242 -0
- package/lib/screenplay/interactions/Wait.js.map +1 -0
- package/lib/screenplay/interactions/WaitBuilder.d.ts +32 -0
- package/lib/screenplay/interactions/WaitBuilder.js +3 -0
- package/lib/screenplay/interactions/WaitBuilder.js.map +1 -0
- package/lib/screenplay/interactions/index.d.ts +16 -0
- package/lib/screenplay/interactions/index.js +29 -0
- package/lib/screenplay/interactions/index.js.map +1 -0
- package/lib/screenplay/models/Cookie.d.ts +117 -0
- package/lib/screenplay/models/Cookie.js +176 -0
- package/lib/screenplay/models/Cookie.js.map +1 -0
- package/lib/screenplay/models/CookieData.d.ts +89 -0
- package/lib/screenplay/models/CookieData.js +3 -0
- package/lib/screenplay/models/CookieData.js.map +1 -0
- package/lib/screenplay/models/ModalDialog.d.ts +9 -0
- package/lib/screenplay/models/ModalDialog.js +14 -0
- package/lib/screenplay/models/ModalDialog.js.map +1 -0
- package/lib/screenplay/models/Page.d.ts +83 -0
- package/lib/screenplay/models/Page.js +52 -0
- package/lib/screenplay/models/Page.js.map +1 -0
- package/lib/screenplay/models/PageElement.d.ts +30 -0
- package/lib/screenplay/models/PageElement.js +62 -0
- package/lib/screenplay/models/PageElement.js.map +1 -0
- package/lib/screenplay/models/PageElements.d.ts +20 -0
- package/lib/screenplay/models/PageElements.js +49 -0
- package/lib/screenplay/models/PageElements.js.map +1 -0
- package/lib/screenplay/models/index.d.ts +6 -0
- package/lib/screenplay/models/index.js +19 -0
- package/lib/screenplay/models/index.js.map +1 -0
- package/lib/screenplay/questions/Attribute.d.ts +83 -0
- package/lib/screenplay/questions/Attribute.js +103 -0
- package/lib/screenplay/questions/Attribute.js.map +1 -0
- package/lib/screenplay/questions/CssClasses.d.ts +93 -0
- package/lib/screenplay/questions/CssClasses.js +113 -0
- package/lib/screenplay/questions/CssClasses.js.map +1 -0
- package/lib/screenplay/questions/ElementQuestion.d.ts +34 -0
- package/lib/screenplay/questions/ElementQuestion.js +53 -0
- package/lib/screenplay/questions/ElementQuestion.js.map +1 -0
- package/lib/screenplay/questions/LastScriptExecution.d.ts +14 -0
- package/lib/screenplay/questions/LastScriptExecution.js +22 -0
- package/lib/screenplay/questions/LastScriptExecution.js.map +1 -0
- package/lib/screenplay/questions/Selected.d.ts +185 -0
- package/lib/screenplay/questions/Selected.js +210 -0
- package/lib/screenplay/questions/Selected.js.map +1 -0
- package/lib/screenplay/questions/Text.d.ts +99 -0
- package/lib/screenplay/questions/Text.js +131 -0
- package/lib/screenplay/questions/Text.js.map +1 -0
- package/lib/screenplay/questions/Value.d.ts +64 -0
- package/lib/screenplay/questions/Value.js +78 -0
- package/lib/screenplay/questions/Value.js.map +1 -0
- package/lib/screenplay/questions/index.d.ts +6 -0
- package/lib/screenplay/questions/index.js +19 -0
- package/lib/screenplay/questions/index.js.map +1 -0
- package/lib/stage/crew/index.d.ts +1 -0
- package/lib/stage/crew/index.js +14 -0
- package/lib/stage/crew/index.js.map +1 -0
- package/lib/stage/crew/photographer/Photographer.d.ts +83 -0
- package/lib/stage/crew/photographer/Photographer.js +102 -0
- package/lib/stage/crew/photographer/Photographer.js.map +1 -0
- package/lib/stage/crew/photographer/index.d.ts +2 -0
- package/lib/stage/crew/photographer/index.js +15 -0
- package/lib/stage/crew/photographer/index.js.map +1 -0
- package/lib/stage/crew/photographer/strategies/PhotoTakingStrategy.d.ts +28 -0
- package/lib/stage/crew/photographer/strategies/PhotoTakingStrategy.js +81 -0
- package/lib/stage/crew/photographer/strategies/PhotoTakingStrategy.js.map +1 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosBeforeAndAfterInteractions.d.ts +18 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosBeforeAndAfterInteractions.js +30 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosBeforeAndAfterInteractions.js.map +1 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosOfFailures.d.ts +17 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosOfFailures.js +28 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosOfFailures.js.map +1 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosOfInteractions.d.ts +19 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosOfInteractions.js +28 -0
- package/lib/stage/crew/photographer/strategies/TakePhotosOfInteractions.js.map +1 -0
- package/lib/stage/crew/photographer/strategies/index.d.ts +4 -0
- package/lib/stage/crew/photographer/strategies/index.js +17 -0
- package/lib/stage/crew/photographer/strategies/index.js.map +1 -0
- package/lib/stage/index.d.ts +1 -0
- package/lib/stage/index.js +14 -0
- package/lib/stage/index.js.map +1 -0
- package/package.json +85 -0
- package/src/errors/CookieMissingError.ts +7 -0
- package/src/errors/index.ts +1 -0
- package/src/expectations/ElementExpectation.ts +32 -0
- package/src/expectations/index.ts +6 -0
- package/src/expectations/isActive.ts +22 -0
- package/src/expectations/isClickable.ts +32 -0
- package/src/expectations/isEnabled.ts +19 -0
- package/src/expectations/isPresent.ts +21 -0
- package/src/expectations/isSelected.ts +24 -0
- package/src/expectations/isVisible.ts +28 -0
- package/src/index.ts +5 -0
- package/src/input/Key.ts +83 -0
- package/src/input/index.ts +1 -0
- package/src/screenplay/abilities/BrowseTheWeb.ts +89 -0
- package/src/screenplay/abilities/BrowserCapabilities.ts +5 -0
- package/src/screenplay/abilities/index.ts +2 -0
- package/src/screenplay/index.ts +4 -0
- package/src/screenplay/interactions/Clear.ts +102 -0
- package/src/screenplay/interactions/Click.ts +86 -0
- package/src/screenplay/interactions/DoubleClick.ts +102 -0
- package/src/screenplay/interactions/Enter.ts +92 -0
- package/src/screenplay/interactions/EnterBuilder.ts +28 -0
- package/src/screenplay/interactions/ExecuteScript.ts +345 -0
- package/src/screenplay/interactions/Hover.ts +90 -0
- package/src/screenplay/interactions/Navigate.ts +209 -0
- package/src/screenplay/interactions/PageElementInteraction.ts +59 -0
- package/src/screenplay/interactions/Press.ts +194 -0
- package/src/screenplay/interactions/PressBuilder.ts +29 -0
- package/src/screenplay/interactions/RightClick.ts +100 -0
- package/src/screenplay/interactions/Scroll.ts +99 -0
- package/src/screenplay/interactions/Select.ts +317 -0
- package/src/screenplay/interactions/SelectBuilder.ts +36 -0
- package/src/screenplay/interactions/Switch.ts +225 -0
- package/src/screenplay/interactions/TakeScreenshot.ts +89 -0
- package/src/screenplay/interactions/Wait.ts +264 -0
- package/src/screenplay/interactions/WaitBuilder.ts +34 -0
- package/src/screenplay/interactions/index.ts +16 -0
- package/src/screenplay/models/Cookie.ts +219 -0
- package/src/screenplay/models/CookieData.ts +97 -0
- package/src/screenplay/models/ModalDialog.ts +19 -0
- package/src/screenplay/models/Page.ts +147 -0
- package/src/screenplay/models/PageElement.ts +95 -0
- package/src/screenplay/models/PageElements.ts +70 -0
- package/src/screenplay/models/index.ts +6 -0
- package/src/screenplay/questions/Attribute.ts +112 -0
- package/src/screenplay/questions/CssClasses.ts +118 -0
- package/src/screenplay/questions/ElementQuestion.ts +60 -0
- package/src/screenplay/questions/LastScriptExecution.ts +21 -0
- package/src/screenplay/questions/Selected.ts +212 -0
- package/src/screenplay/questions/Text.ts +153 -0
- package/src/screenplay/questions/Value.ts +82 -0
- package/src/screenplay/questions/index.ts +6 -0
- package/src/stage/crew/index.ts +1 -0
- package/src/stage/crew/photographer/Photographer.ts +108 -0
- package/src/stage/crew/photographer/index.ts +2 -0
- package/src/stage/crew/photographer/strategies/PhotoTakingStrategy.ts +116 -0
- package/src/stage/crew/photographer/strategies/TakePhotosBeforeAndAfterInteractions.ts +28 -0
- package/src/stage/crew/photographer/strategies/TakePhotosOfFailures.ts +26 -0
- package/src/stage/crew/photographer/strategies/TakePhotosOfInteractions.ts +26 -0
- package/src/stage/crew/photographer/strategies/index.ts +4 -0
- package/src/stage/index.ts +1 -0
- package/tsconfig.eslint.json +10 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, Interaction, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
|
|
4
|
+
import { PageElement } from '../models';
|
|
5
|
+
import { PageElementInteraction } from './PageElementInteraction';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @desc
|
|
9
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
10
|
+
* perform a double-click on a given Web element.
|
|
11
|
+
*
|
|
12
|
+
* @example <caption>Example widget</caption>
|
|
13
|
+
* <!--
|
|
14
|
+
* The editor shows up when the user double-clicks
|
|
15
|
+
* on one of the properties of their profile
|
|
16
|
+
* and let's them change the value of that property.
|
|
17
|
+
* -->
|
|
18
|
+
* <div id="user-profile">
|
|
19
|
+
* <ul>
|
|
20
|
+
* <li id="display-name" ondblclick="edit(this)">User12345</li>
|
|
21
|
+
* <li id="email-address" ondblclick="edit(this)">tester@example.org</li>
|
|
22
|
+
* </ul>
|
|
23
|
+
* <form id="editor" class="hidden">
|
|
24
|
+
* <input type="text" value="" />
|
|
25
|
+
* </form>
|
|
26
|
+
* </div>
|
|
27
|
+
*
|
|
28
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
29
|
+
* import { by, Target } from '@serenity-js/webdriverio';
|
|
30
|
+
*
|
|
31
|
+
* class UserProfile {
|
|
32
|
+
* static displayName = Target.the('display name')
|
|
33
|
+
* .located(by.id('display-name'));
|
|
34
|
+
* static emailAddress = Target.the('email address')
|
|
35
|
+
* .located(by.id('email-address'));
|
|
36
|
+
* static editor = Target.the('editor')
|
|
37
|
+
* .located(by.id('editor'));
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* @example <caption>Double-clicking on an element</caption>
|
|
41
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
42
|
+
* import { BrowseTheWeb, DoubleClick, isVisible, Enter, Text, Wait } from '@serenity-js/webdriverio';
|
|
43
|
+
* import { Ensure, equals, not } from '@serenity-js/assertions';
|
|
44
|
+
*
|
|
45
|
+
* actorCalled('Dorothy')
|
|
46
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
47
|
+
* .attemptsTo(
|
|
48
|
+
* DoubleClick.on(UserProfile.displayName),
|
|
49
|
+
* Wait.until(UserProfile.editor, isVisible()),
|
|
50
|
+
*
|
|
51
|
+
* Enter.theValue('New username').into(UserProfile.editor),
|
|
52
|
+
*
|
|
53
|
+
* Ensure.that(Text.of(UserProfile.displayName), equals('New username')),
|
|
54
|
+
* Ensure.that(UserProfile.editor, not(isVisible()))
|
|
55
|
+
* );
|
|
56
|
+
*
|
|
57
|
+
* @see {@link Target}
|
|
58
|
+
*
|
|
59
|
+
* @extends {ElementInteraction}
|
|
60
|
+
*/
|
|
61
|
+
export class DoubleClick extends PageElementInteraction {
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @desc
|
|
65
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
66
|
+
*
|
|
67
|
+
* @param {Answerable<PageElement>} target
|
|
68
|
+
* The element to be double-clicked on
|
|
69
|
+
*
|
|
70
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
71
|
+
*/
|
|
72
|
+
static on(target: Answerable<PageElement>): Interaction {
|
|
73
|
+
return new DoubleClick(target);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {Answerable<PageElement>} target
|
|
78
|
+
* The element to be double-clicked on
|
|
79
|
+
*/
|
|
80
|
+
constructor(private readonly target: Answerable<PageElement>) {
|
|
81
|
+
super(formatted `#actor double-clicks on ${ target }`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @desc
|
|
86
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
87
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
88
|
+
*
|
|
89
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
90
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
91
|
+
*
|
|
92
|
+
* @returns {PromiseLike<void>}
|
|
93
|
+
*
|
|
94
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
95
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
96
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
97
|
+
*/
|
|
98
|
+
async performAs(actor: UsesAbilities & AnswersQuestions): Promise<void> {
|
|
99
|
+
const element = await this.resolve(actor, this.target);
|
|
100
|
+
return element.doubleClick();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
|
|
4
|
+
import { PageElement } from '../models';
|
|
5
|
+
import { EnterBuilder } from './EnterBuilder';
|
|
6
|
+
import { PageElementInteraction } from './PageElementInteraction';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @desc
|
|
10
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
11
|
+
* enter a value into a [form `input`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) field.
|
|
12
|
+
*
|
|
13
|
+
* @example <caption>Example widget</caption>
|
|
14
|
+
* <form>
|
|
15
|
+
* <input type="text" name="example" id="example" />
|
|
16
|
+
* </form>
|
|
17
|
+
*
|
|
18
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
19
|
+
* import { by, Target } from '@serenity-js/webdriverio';
|
|
20
|
+
*
|
|
21
|
+
* class Form {
|
|
22
|
+
* static exampleInput = Target.the('example input')
|
|
23
|
+
* .located(by.id('example'));
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @example <caption>Entering the value into a form field</caption>
|
|
27
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
28
|
+
* import { BrowseTheWeb, Enter } from '@serenity-js/webdriverio';
|
|
29
|
+
*
|
|
30
|
+
* actorCalled('Esme')
|
|
31
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
32
|
+
* .attemptsTo(
|
|
33
|
+
* Enter.theValue('Hello world!').into(Form.exampleInput),
|
|
34
|
+
* );
|
|
35
|
+
*
|
|
36
|
+
* @see {@link Target}
|
|
37
|
+
*
|
|
38
|
+
* @extends {ElementInteraction}
|
|
39
|
+
*/
|
|
40
|
+
export class Enter extends PageElementInteraction {
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @desc
|
|
44
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
45
|
+
*
|
|
46
|
+
* @param {Array<Answerable<string | number | string[] | number[]>>} value
|
|
47
|
+
* The value to be entered
|
|
48
|
+
*
|
|
49
|
+
* @returns {EnterBuilder}
|
|
50
|
+
*/
|
|
51
|
+
static theValue(...value: Array<Answerable<string | number | string[] | number[]>>): EnterBuilder {
|
|
52
|
+
return {
|
|
53
|
+
into: (field: Answerable<PageElement> /* todo Question<AlertPromise> | AlertPromise */) =>
|
|
54
|
+
new Enter(value, field),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {Array<Answerable<string | number | string[] | number[]>>} value
|
|
60
|
+
* The value to be entered
|
|
61
|
+
*
|
|
62
|
+
* @param {Answerable<PageElement>} field
|
|
63
|
+
* The field to enter the value into
|
|
64
|
+
*/
|
|
65
|
+
constructor(
|
|
66
|
+
private readonly value: Array<Answerable<string | number | string[] | number[]>>,
|
|
67
|
+
private readonly field: Answerable<PageElement> /* todo | Question<AlertPromise> | AlertPromise */,
|
|
68
|
+
) {
|
|
69
|
+
super(formatted `#actor enters ${ value.join(', ') } into ${ field }`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @desc
|
|
74
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
75
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
76
|
+
*
|
|
77
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
78
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
79
|
+
*
|
|
80
|
+
* @returns {Promise<void>}
|
|
81
|
+
*
|
|
82
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
83
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
84
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
85
|
+
*/
|
|
86
|
+
async performAs(actor: UsesAbilities & AnswersQuestions): Promise<void> {
|
|
87
|
+
const values = await Promise.all(this.value.map(part => actor.answer(part)));
|
|
88
|
+
const field = await this.resolve(actor, this.field);
|
|
89
|
+
|
|
90
|
+
return field.enterValue(values.flat());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Answerable, Interaction } from '@serenity-js/core';
|
|
2
|
+
|
|
3
|
+
import { PageElement } from '../models';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @desc
|
|
7
|
+
* Fluent interface to make the instantiation of
|
|
8
|
+
* the {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
9
|
+
* to {@link Enter} more readable.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link Enter}
|
|
12
|
+
*
|
|
13
|
+
* @interface
|
|
14
|
+
*/
|
|
15
|
+
export interface EnterBuilder {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @desc
|
|
19
|
+
* Instantiates an {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
20
|
+
* to {@link Enter}.
|
|
21
|
+
*
|
|
22
|
+
* @param {Answerable<PageElement>} field
|
|
23
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
24
|
+
*
|
|
25
|
+
* @see {@link Target}
|
|
26
|
+
*/
|
|
27
|
+
into: (field: Answerable<PageElement> /* | Question<AlertPromise> | AlertPromise */) => Interaction;
|
|
28
|
+
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, CollectsArtifacts, Interaction, LogicError, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
import { Name, TextData } from '@serenity-js/core/lib/model';
|
|
4
|
+
|
|
5
|
+
import { BrowseTheWeb } from '../abilities';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @desc
|
|
9
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
10
|
+
* execute a script within the context of the current browser window.
|
|
11
|
+
*
|
|
12
|
+
* Please see the tests below for usage examples.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link LastScriptExecution.result}
|
|
15
|
+
*/
|
|
16
|
+
export class ExecuteScript {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @desc
|
|
20
|
+
* Instantiates a version of this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
21
|
+
* configured to load a script from `sourceUrl`.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} sourceUrl
|
|
24
|
+
* The URL to load the script from
|
|
25
|
+
*
|
|
26
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
27
|
+
*/
|
|
28
|
+
static from(sourceUrl: string): Interaction {
|
|
29
|
+
return new ExecuteScriptFromUrl(sourceUrl);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @desc
|
|
34
|
+
* Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window.
|
|
35
|
+
* The script fragment will be executed as the body of an anonymous function.
|
|
36
|
+
* If the script is provided as a function object, that function will be converted to a string for injection
|
|
37
|
+
* into the target window.
|
|
38
|
+
*
|
|
39
|
+
* Any arguments provided in addition to the script will be included as script arguments and may be referenced
|
|
40
|
+
* using the `arguments` object. Arguments may be a `boolean`, `number`, `string`
|
|
41
|
+
* or {@link Target} (`Answerable<Element>`).
|
|
42
|
+
* Arrays and objects may also be used as script arguments as long as each item adheres
|
|
43
|
+
* to the types previously mentioned.
|
|
44
|
+
*
|
|
45
|
+
* Unlike executing synchronous JavaScript with {@link ExecuteScript#sync},
|
|
46
|
+
* scripts executed with this function must explicitly signal they are finished by invoking the provided callback.
|
|
47
|
+
*
|
|
48
|
+
* This callback will always be injected into the executed function as the last argument,
|
|
49
|
+
* and thus may be referenced with `arguments[arguments.length - 1]`.
|
|
50
|
+
*
|
|
51
|
+
* If the script invokes the `callback` with a return value, this will be made available
|
|
52
|
+
* via the {@link LastScriptExecution.result}.
|
|
53
|
+
*
|
|
54
|
+
* **Please note** that in order to signal an error in the `script` you need to throw an {@link Error}
|
|
55
|
+
* instead of passing it to the callback function.
|
|
56
|
+
*
|
|
57
|
+
* @example <caption>Executing an async script</caption>
|
|
58
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
59
|
+
*
|
|
60
|
+
* actor.attemptsTo(
|
|
61
|
+
* ExecuteScript.async(`
|
|
62
|
+
* var callback = arguments[arguments.length - 1];
|
|
63
|
+
*
|
|
64
|
+
* // do stuff
|
|
65
|
+
*
|
|
66
|
+
* callback(result)
|
|
67
|
+
* `)
|
|
68
|
+
* );
|
|
69
|
+
*
|
|
70
|
+
* @example <caption>Passing arguments to an async script</caption>
|
|
71
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
72
|
+
*
|
|
73
|
+
* actor.attemptsTo(
|
|
74
|
+
* ExecuteScript.async(`
|
|
75
|
+
* var name = arguments[0];
|
|
76
|
+
* var age = arguments[1];
|
|
77
|
+
* var callback = arguments[arguments.length - 1];
|
|
78
|
+
*
|
|
79
|
+
* // do stuff
|
|
80
|
+
*
|
|
81
|
+
* callback(result)
|
|
82
|
+
* `).withArguments('Bob', 24)
|
|
83
|
+
* );
|
|
84
|
+
*
|
|
85
|
+
* @example <caption>Passing Target arguments to an async script</caption>
|
|
86
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
87
|
+
*
|
|
88
|
+
* actor.attemptsTo(
|
|
89
|
+
* ExecuteScript.async(`
|
|
90
|
+
* var header = arguments[0]; // Target gets converted to a WebElement
|
|
91
|
+
* var callback = arguments[arguments.length - 1];
|
|
92
|
+
*
|
|
93
|
+
* callback(header.innerText)
|
|
94
|
+
* `).withArguments(Target.the('header').located(by.css('h1')))
|
|
95
|
+
* );
|
|
96
|
+
*
|
|
97
|
+
* @example <caption>Executing async script as function</caption>
|
|
98
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
99
|
+
*
|
|
100
|
+
* actor.attemptsTo(
|
|
101
|
+
* ExecuteScript.async(function getText(header, callback) {
|
|
102
|
+
* callback(header.innerText)
|
|
103
|
+
* }).withArguments(Target.the('header').located(by.css('h1')))
|
|
104
|
+
* );
|
|
105
|
+
*
|
|
106
|
+
* @param {string | Function} script
|
|
107
|
+
* The script to be executed
|
|
108
|
+
*
|
|
109
|
+
* @returns {ExecuteScriptWithArguments}
|
|
110
|
+
*
|
|
111
|
+
* @see {@link LastScriptExecution.result}
|
|
112
|
+
*/
|
|
113
|
+
static async(script: string | Function): ExecuteScriptWithArguments { // eslint-disable-line @typescript-eslint/ban-types
|
|
114
|
+
return new ExecuteAsynchronousScript(script);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @desc
|
|
119
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
120
|
+
* execute a synchronous script in the context of the currently selected frame or window.
|
|
121
|
+
*
|
|
122
|
+
* If the script returns a value, it will be made available via {@link LastScriptExecution.result}.
|
|
123
|
+
*
|
|
124
|
+
* @example <caption>Executing a sync script as string and reading the result</caption>
|
|
125
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
126
|
+
* import { BrowseTheWeb, ExecuteScript, LastScriptExecution } from '@serenity-js/webdriverio';
|
|
127
|
+
* import { Ensure, includes } from '@serenity-js/assertions';
|
|
128
|
+
*
|
|
129
|
+
* actorCalled('Joseph')
|
|
130
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
131
|
+
* .attemptsTo(
|
|
132
|
+
* ExecuteScript.sync('return navigator.userAgent'),
|
|
133
|
+
* Ensure.that(LastScriptExecution.result<string>(), includes('Chrome')),
|
|
134
|
+
* );
|
|
135
|
+
*
|
|
136
|
+
* @example <caption>Executing a sync script as function and reading the result</caption>
|
|
137
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
138
|
+
* import { by, BrowseTheWeb, Enter, ExecuteScript, LastScriptExecution, Target } from '@serenity-js/webdriverio';
|
|
139
|
+
*
|
|
140
|
+
* const someOfferField = Target.the('offer code').located(by.id('offer-code'));
|
|
141
|
+
* const applyOfferCodeField = Target.the('apply offer field').located(by.id('apply-offer-code'));
|
|
142
|
+
*
|
|
143
|
+
* actorCalled('Joseph')
|
|
144
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
145
|
+
* .attemptsTo(
|
|
146
|
+
* // inject JavaScript to read some property of an element
|
|
147
|
+
* ExecuteScript.sync(function getValue(element) {
|
|
148
|
+
* return element.value;
|
|
149
|
+
* }).withArguments(someOfferField),
|
|
150
|
+
*
|
|
151
|
+
* // use LastScriptExecution.result() to read the value
|
|
152
|
+
* // returned from the injected script
|
|
153
|
+
* // and pass it to another interaction
|
|
154
|
+
* Enter.theValue(LastScriptExecution.result<string>()).into(applyOfferCodeField),
|
|
155
|
+
* );
|
|
156
|
+
*
|
|
157
|
+
* @param {string | Function} script
|
|
158
|
+
* The script to be executed
|
|
159
|
+
*
|
|
160
|
+
* @returns {ExecuteScriptWithArguments}
|
|
161
|
+
*
|
|
162
|
+
* @see {@link LastScriptExecution.result}
|
|
163
|
+
*/
|
|
164
|
+
static sync(script: string | Function): ExecuteScriptWithArguments { // eslint-disable-line @typescript-eslint/ban-types
|
|
165
|
+
return new ExecuteSynchronousScript(script);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @desc
|
|
171
|
+
* Allows for a script to be executed to be parametrised.
|
|
172
|
+
*
|
|
173
|
+
* **Please note** that the arguments can be both synchronous and asynchronous {@link @serenity-js/core/lib/screenplay~Question}s
|
|
174
|
+
* as well as regular static values.
|
|
175
|
+
*
|
|
176
|
+
* @abstract
|
|
177
|
+
*
|
|
178
|
+
* @see {@link ExecuteScript}
|
|
179
|
+
*
|
|
180
|
+
* @extends {@serenity-js/core/lib/screenplay~Interaction}
|
|
181
|
+
*/
|
|
182
|
+
export abstract class ExecuteScriptWithArguments extends Interaction {
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {string | Function} script
|
|
186
|
+
* The script to be executed
|
|
187
|
+
*
|
|
188
|
+
* @param {Array<Answerable<any>>} args
|
|
189
|
+
* Arguments to parametrise the script with
|
|
190
|
+
*/
|
|
191
|
+
constructor(
|
|
192
|
+
protected readonly script: string | Function, // eslint-disable-line @typescript-eslint/ban-types
|
|
193
|
+
protected readonly args: Array<Answerable<any>> = [],
|
|
194
|
+
) {
|
|
195
|
+
super();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @desc
|
|
200
|
+
* Instantiates an {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
201
|
+
* to {@link Enter}.
|
|
202
|
+
*
|
|
203
|
+
* @param {...Array<Answerable<any>>} args
|
|
204
|
+
* Arguments to parametrise the script with
|
|
205
|
+
*
|
|
206
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
207
|
+
*/
|
|
208
|
+
public abstract withArguments(...args: Array<Answerable<any>>): Interaction;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @desc
|
|
212
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
213
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
214
|
+
*
|
|
215
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
216
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
217
|
+
*
|
|
218
|
+
* @returns {PromiseLike<void>}
|
|
219
|
+
*
|
|
220
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
221
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
222
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
223
|
+
*/
|
|
224
|
+
performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): PromiseLike<void> {
|
|
225
|
+
// todo: interaction should store the result on the ability; the ability should not have a side-effect (?)
|
|
226
|
+
return Promise.all(this.args.map(arg => actor.answer(arg)))
|
|
227
|
+
.then(args => this.executeAs(actor, args))
|
|
228
|
+
.then(() => actor.collect(
|
|
229
|
+
TextData.fromJSON({
|
|
230
|
+
contentType: 'text/javascript;charset=UTF-8',
|
|
231
|
+
data: this.script.toString(),
|
|
232
|
+
}),
|
|
233
|
+
new Name('Script source'),
|
|
234
|
+
));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
protected abstract executeAs(actor: UsesAbilities & AnswersQuestions, args: any[]): Promise<any>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @package
|
|
242
|
+
*/
|
|
243
|
+
class ExecuteAsynchronousScript extends ExecuteScriptWithArguments {
|
|
244
|
+
withArguments(...args: Array<Answerable<any>>): Interaction {
|
|
245
|
+
return new ExecuteAsynchronousScript(this.script, args);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
protected executeAs(actor: UsesAbilities & AnswersQuestions, args: any[]): Promise<any> {
|
|
249
|
+
return BrowseTheWeb.as(actor).executeAsyncScript(this.script as unknown as any, ...args); // todo: fix types
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
toString(): string {
|
|
253
|
+
return this.args.length > 0
|
|
254
|
+
? formatted `#actor executes an asynchronous script with arguments: ${ this.args }`
|
|
255
|
+
: `#actor executes an asynchronous script`;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @package
|
|
261
|
+
*
|
|
262
|
+
* https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html
|
|
263
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
|
264
|
+
*/
|
|
265
|
+
class ExecuteScriptFromUrl extends Interaction {
|
|
266
|
+
constructor(private readonly sourceUrl: string) {
|
|
267
|
+
super();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @desc
|
|
272
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
273
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
274
|
+
*
|
|
275
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
276
|
+
* @returns {Promise<void>}
|
|
277
|
+
*
|
|
278
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
279
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
280
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
281
|
+
*/
|
|
282
|
+
performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<any> {
|
|
283
|
+
return BrowseTheWeb.as(actor)
|
|
284
|
+
.executeAsyncScript(
|
|
285
|
+
/* istanbul ignore next */
|
|
286
|
+
function executeScriptFromUrl(sourceUrl: string, callback: (message?: string) => void) {
|
|
287
|
+
const alreadyLoadedScripts = Array.prototype.slice
|
|
288
|
+
.call(document.querySelectorAll('script'))
|
|
289
|
+
.map(script => script.src);
|
|
290
|
+
|
|
291
|
+
if (~ alreadyLoadedScripts.indexOf(sourceUrl)) {
|
|
292
|
+
return callback('Script from ' + sourceUrl + ' has already been loaded');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const script = document.createElement('script');
|
|
296
|
+
script.addEventListener('load', function() {
|
|
297
|
+
callback();
|
|
298
|
+
});
|
|
299
|
+
script.addEventListener('error', function () {
|
|
300
|
+
return callback('Couldn\'t load script from ' + sourceUrl);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
script.src = sourceUrl;
|
|
304
|
+
script.async = true;
|
|
305
|
+
document.head.append(script);
|
|
306
|
+
},
|
|
307
|
+
this.sourceUrl
|
|
308
|
+
)
|
|
309
|
+
.then(errorMessage => {
|
|
310
|
+
if (errorMessage) {
|
|
311
|
+
throw new LogicError(errorMessage);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @desc
|
|
318
|
+
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
319
|
+
*
|
|
320
|
+
* @returns {string}
|
|
321
|
+
*/
|
|
322
|
+
toString(): string {
|
|
323
|
+
return `#actor executes a script from ${ this.sourceUrl }`;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @package
|
|
329
|
+
*/
|
|
330
|
+
class ExecuteSynchronousScript extends ExecuteScriptWithArguments {
|
|
331
|
+
|
|
332
|
+
withArguments(...args: Array<Answerable<any>>): Interaction {
|
|
333
|
+
return new ExecuteSynchronousScript(this.script, args);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
protected executeAs(actor: UsesAbilities & AnswersQuestions, args: any[]): Promise<any> {
|
|
337
|
+
return BrowseTheWeb.as(actor).executeScript(this.script as unknown as any, ...args); // todo fix type
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
toString(): string {
|
|
341
|
+
return this.args.length > 0
|
|
342
|
+
? formatted `#actor executes a synchronous script with arguments: ${ this.args }`
|
|
343
|
+
: `#actor executes a synchronous script`;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, Interaction, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
|
|
4
|
+
import { PageElement } from '../models';
|
|
5
|
+
import { PageElementInteraction } from './PageElementInteraction';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @desc
|
|
9
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
10
|
+
* hover the mouse pointer over a given Web element.
|
|
11
|
+
*
|
|
12
|
+
* @example <caption>Example widget</caption>
|
|
13
|
+
* <a data-test="example-link"
|
|
14
|
+
* class="off"
|
|
15
|
+
* onmouseover="this.className='on';"
|
|
16
|
+
* onmouseout="this.className='off';"
|
|
17
|
+
* href="/">hover over me</a>
|
|
18
|
+
*
|
|
19
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
20
|
+
* import { by, Target } from '@serenity-js/webdriverio';
|
|
21
|
+
*
|
|
22
|
+
* class Example {
|
|
23
|
+
* static link = Target.the('example link')
|
|
24
|
+
* .located(by.css('[data-test="example-link"]'));
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @example <caption>Hovering over an element</caption>
|
|
28
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
29
|
+
* import { BrowseTheWeb, Hover, CssClasses } from '@serenity-js/webdriverio';
|
|
30
|
+
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
31
|
+
*
|
|
32
|
+
* actorCalled('Hank')
|
|
33
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
34
|
+
* .attemptsTo(
|
|
35
|
+
* Ensure.that(CssClasses.of(Example.link), equals([ 'off' ])),
|
|
36
|
+
*
|
|
37
|
+
* Hover.over(Example.link),
|
|
38
|
+
* Ensure.that(CssClasses.of(Example.link), equals([ 'on' ])),
|
|
39
|
+
* );
|
|
40
|
+
*
|
|
41
|
+
* @see {@link BrowseTheWeb}
|
|
42
|
+
* @see {@link Target}
|
|
43
|
+
* @see {@link CssClasses}
|
|
44
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
45
|
+
* @see {@link @serenity-js/assertions/lib/expectations~equals}
|
|
46
|
+
*
|
|
47
|
+
* @extends {ElementInteraction}
|
|
48
|
+
*/
|
|
49
|
+
export class Hover extends PageElementInteraction {
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @desc
|
|
53
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
54
|
+
*
|
|
55
|
+
* @param {Answerable<PageElement>} target
|
|
56
|
+
* The element to be hovered over
|
|
57
|
+
*
|
|
58
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
59
|
+
*/
|
|
60
|
+
static over(target: Answerable<PageElement>): Interaction {
|
|
61
|
+
return new Hover(target);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Answerable<PageElement>} target
|
|
66
|
+
* The element to be hovered over
|
|
67
|
+
*/
|
|
68
|
+
constructor(private readonly target: Answerable<PageElement>) {
|
|
69
|
+
super(formatted `#actor hovers the mouse over ${ target }`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @desc
|
|
74
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
75
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
76
|
+
*
|
|
77
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
78
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
79
|
+
*
|
|
80
|
+
* @returns {PromiseLike<void>}
|
|
81
|
+
*
|
|
82
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
83
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
84
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
85
|
+
*/
|
|
86
|
+
async performAs(actor: UsesAbilities & AnswersQuestions): Promise<void> {
|
|
87
|
+
const element = await this.resolve(actor, this.target);
|
|
88
|
+
return element.hoverOver();
|
|
89
|
+
}
|
|
90
|
+
}
|