@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,206 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, CollectsArtifacts, Interaction, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
/**
|
|
3
|
+
* @desc
|
|
4
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
5
|
+
* execute a script within the context of the current browser window.
|
|
6
|
+
*
|
|
7
|
+
* Please see the tests below for usage examples.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link LastScriptExecution.result}
|
|
10
|
+
*/
|
|
11
|
+
export declare class ExecuteScript {
|
|
12
|
+
/**
|
|
13
|
+
* @desc
|
|
14
|
+
* Instantiates a version of this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
15
|
+
* configured to load a script from `sourceUrl`.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} sourceUrl
|
|
18
|
+
* The URL to load the script from
|
|
19
|
+
*
|
|
20
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
21
|
+
*/
|
|
22
|
+
static from(sourceUrl: string): Interaction;
|
|
23
|
+
/**
|
|
24
|
+
* @desc
|
|
25
|
+
* Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window.
|
|
26
|
+
* The script fragment will be executed as the body of an anonymous function.
|
|
27
|
+
* If the script is provided as a function object, that function will be converted to a string for injection
|
|
28
|
+
* into the target window.
|
|
29
|
+
*
|
|
30
|
+
* Any arguments provided in addition to the script will be included as script arguments and may be referenced
|
|
31
|
+
* using the `arguments` object. Arguments may be a `boolean`, `number`, `string`
|
|
32
|
+
* or {@link Target} (`Answerable<Element>`).
|
|
33
|
+
* Arrays and objects may also be used as script arguments as long as each item adheres
|
|
34
|
+
* to the types previously mentioned.
|
|
35
|
+
*
|
|
36
|
+
* Unlike executing synchronous JavaScript with {@link ExecuteScript#sync},
|
|
37
|
+
* scripts executed with this function must explicitly signal they are finished by invoking the provided callback.
|
|
38
|
+
*
|
|
39
|
+
* This callback will always be injected into the executed function as the last argument,
|
|
40
|
+
* and thus may be referenced with `arguments[arguments.length - 1]`.
|
|
41
|
+
*
|
|
42
|
+
* If the script invokes the `callback` with a return value, this will be made available
|
|
43
|
+
* via the {@link LastScriptExecution.result}.
|
|
44
|
+
*
|
|
45
|
+
* **Please note** that in order to signal an error in the `script` you need to throw an {@link Error}
|
|
46
|
+
* instead of passing it to the callback function.
|
|
47
|
+
*
|
|
48
|
+
* @example <caption>Executing an async script</caption>
|
|
49
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
50
|
+
*
|
|
51
|
+
* actor.attemptsTo(
|
|
52
|
+
* ExecuteScript.async(`
|
|
53
|
+
* var callback = arguments[arguments.length - 1];
|
|
54
|
+
*
|
|
55
|
+
* // do stuff
|
|
56
|
+
*
|
|
57
|
+
* callback(result)
|
|
58
|
+
* `)
|
|
59
|
+
* );
|
|
60
|
+
*
|
|
61
|
+
* @example <caption>Passing arguments to an async script</caption>
|
|
62
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
63
|
+
*
|
|
64
|
+
* actor.attemptsTo(
|
|
65
|
+
* ExecuteScript.async(`
|
|
66
|
+
* var name = arguments[0];
|
|
67
|
+
* var age = arguments[1];
|
|
68
|
+
* var callback = arguments[arguments.length - 1];
|
|
69
|
+
*
|
|
70
|
+
* // do stuff
|
|
71
|
+
*
|
|
72
|
+
* callback(result)
|
|
73
|
+
* `).withArguments('Bob', 24)
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* @example <caption>Passing Target arguments to an async script</caption>
|
|
77
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
78
|
+
*
|
|
79
|
+
* actor.attemptsTo(
|
|
80
|
+
* ExecuteScript.async(`
|
|
81
|
+
* var header = arguments[0]; // Target gets converted to a WebElement
|
|
82
|
+
* var callback = arguments[arguments.length - 1];
|
|
83
|
+
*
|
|
84
|
+
* callback(header.innerText)
|
|
85
|
+
* `).withArguments(Target.the('header').located(by.css('h1')))
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* @example <caption>Executing async script as function</caption>
|
|
89
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
90
|
+
*
|
|
91
|
+
* actor.attemptsTo(
|
|
92
|
+
* ExecuteScript.async(function getText(header, callback) {
|
|
93
|
+
* callback(header.innerText)
|
|
94
|
+
* }).withArguments(Target.the('header').located(by.css('h1')))
|
|
95
|
+
* );
|
|
96
|
+
*
|
|
97
|
+
* @param {string | Function} script
|
|
98
|
+
* The script to be executed
|
|
99
|
+
*
|
|
100
|
+
* @returns {ExecuteScriptWithArguments}
|
|
101
|
+
*
|
|
102
|
+
* @see {@link LastScriptExecution.result}
|
|
103
|
+
*/
|
|
104
|
+
static async(script: string | Function): ExecuteScriptWithArguments;
|
|
105
|
+
/**
|
|
106
|
+
* @desc
|
|
107
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
108
|
+
* execute a synchronous script in the context of the currently selected frame or window.
|
|
109
|
+
*
|
|
110
|
+
* If the script returns a value, it will be made available via {@link LastScriptExecution.result}.
|
|
111
|
+
*
|
|
112
|
+
* @example <caption>Executing a sync script as string and reading the result</caption>
|
|
113
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
114
|
+
* import { BrowseTheWeb, ExecuteScript, LastScriptExecution } from '@serenity-js/webdriverio';
|
|
115
|
+
* import { Ensure, includes } from '@serenity-js/assertions';
|
|
116
|
+
*
|
|
117
|
+
* actorCalled('Joseph')
|
|
118
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
119
|
+
* .attemptsTo(
|
|
120
|
+
* ExecuteScript.sync('return navigator.userAgent'),
|
|
121
|
+
* Ensure.that(LastScriptExecution.result<string>(), includes('Chrome')),
|
|
122
|
+
* );
|
|
123
|
+
*
|
|
124
|
+
* @example <caption>Executing a sync script as function and reading the result</caption>
|
|
125
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
126
|
+
* import { by, BrowseTheWeb, Enter, ExecuteScript, LastScriptExecution, Target } from '@serenity-js/webdriverio';
|
|
127
|
+
*
|
|
128
|
+
* const someOfferField = Target.the('offer code').located(by.id('offer-code'));
|
|
129
|
+
* const applyOfferCodeField = Target.the('apply offer field').located(by.id('apply-offer-code'));
|
|
130
|
+
*
|
|
131
|
+
* actorCalled('Joseph')
|
|
132
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
133
|
+
* .attemptsTo(
|
|
134
|
+
* // inject JavaScript to read some property of an element
|
|
135
|
+
* ExecuteScript.sync(function getValue(element) {
|
|
136
|
+
* return element.value;
|
|
137
|
+
* }).withArguments(someOfferField),
|
|
138
|
+
*
|
|
139
|
+
* // use LastScriptExecution.result() to read the value
|
|
140
|
+
* // returned from the injected script
|
|
141
|
+
* // and pass it to another interaction
|
|
142
|
+
* Enter.theValue(LastScriptExecution.result<string>()).into(applyOfferCodeField),
|
|
143
|
+
* );
|
|
144
|
+
*
|
|
145
|
+
* @param {string | Function} script
|
|
146
|
+
* The script to be executed
|
|
147
|
+
*
|
|
148
|
+
* @returns {ExecuteScriptWithArguments}
|
|
149
|
+
*
|
|
150
|
+
* @see {@link LastScriptExecution.result}
|
|
151
|
+
*/
|
|
152
|
+
static sync(script: string | Function): ExecuteScriptWithArguments;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @desc
|
|
156
|
+
* Allows for a script to be executed to be parametrised.
|
|
157
|
+
*
|
|
158
|
+
* **Please note** that the arguments can be both synchronous and asynchronous {@link @serenity-js/core/lib/screenplay~Question}s
|
|
159
|
+
* as well as regular static values.
|
|
160
|
+
*
|
|
161
|
+
* @abstract
|
|
162
|
+
*
|
|
163
|
+
* @see {@link ExecuteScript}
|
|
164
|
+
*
|
|
165
|
+
* @extends {@serenity-js/core/lib/screenplay~Interaction}
|
|
166
|
+
*/
|
|
167
|
+
export declare abstract class ExecuteScriptWithArguments extends Interaction {
|
|
168
|
+
protected readonly script: string | Function;
|
|
169
|
+
protected readonly args: Array<Answerable<any>>;
|
|
170
|
+
/**
|
|
171
|
+
* @param {string | Function} script
|
|
172
|
+
* The script to be executed
|
|
173
|
+
*
|
|
174
|
+
* @param {Array<Answerable<any>>} args
|
|
175
|
+
* Arguments to parametrise the script with
|
|
176
|
+
*/
|
|
177
|
+
constructor(script: string | Function, // eslint-disable-line @typescript-eslint/ban-types
|
|
178
|
+
args?: Array<Answerable<any>>);
|
|
179
|
+
/**
|
|
180
|
+
* @desc
|
|
181
|
+
* Instantiates an {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
182
|
+
* to {@link Enter}.
|
|
183
|
+
*
|
|
184
|
+
* @param {...Array<Answerable<any>>} args
|
|
185
|
+
* Arguments to parametrise the script with
|
|
186
|
+
*
|
|
187
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
188
|
+
*/
|
|
189
|
+
abstract withArguments(...args: Array<Answerable<any>>): Interaction;
|
|
190
|
+
/**
|
|
191
|
+
* @desc
|
|
192
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
193
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
194
|
+
*
|
|
195
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
196
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
197
|
+
*
|
|
198
|
+
* @returns {PromiseLike<void>}
|
|
199
|
+
*
|
|
200
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
201
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
202
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
203
|
+
*/
|
|
204
|
+
performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): PromiseLike<void>;
|
|
205
|
+
protected abstract executeAs(actor: UsesAbilities & AnswersQuestions, args: any[]): Promise<any>;
|
|
206
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecuteScriptWithArguments = exports.ExecuteScript = void 0;
|
|
4
|
+
const core_1 = require("@serenity-js/core");
|
|
5
|
+
const io_1 = require("@serenity-js/core/lib/io");
|
|
6
|
+
const model_1 = require("@serenity-js/core/lib/model");
|
|
7
|
+
const abilities_1 = require("../abilities");
|
|
8
|
+
/**
|
|
9
|
+
* @desc
|
|
10
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
11
|
+
* execute a script within the context of the current browser window.
|
|
12
|
+
*
|
|
13
|
+
* Please see the tests below for usage examples.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link LastScriptExecution.result}
|
|
16
|
+
*/
|
|
17
|
+
class ExecuteScript {
|
|
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) {
|
|
29
|
+
return new ExecuteScriptFromUrl(sourceUrl);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @desc
|
|
33
|
+
* Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window.
|
|
34
|
+
* The script fragment will be executed as the body of an anonymous function.
|
|
35
|
+
* If the script is provided as a function object, that function will be converted to a string for injection
|
|
36
|
+
* into the target window.
|
|
37
|
+
*
|
|
38
|
+
* Any arguments provided in addition to the script will be included as script arguments and may be referenced
|
|
39
|
+
* using the `arguments` object. Arguments may be a `boolean`, `number`, `string`
|
|
40
|
+
* or {@link Target} (`Answerable<Element>`).
|
|
41
|
+
* Arrays and objects may also be used as script arguments as long as each item adheres
|
|
42
|
+
* to the types previously mentioned.
|
|
43
|
+
*
|
|
44
|
+
* Unlike executing synchronous JavaScript with {@link ExecuteScript#sync},
|
|
45
|
+
* scripts executed with this function must explicitly signal they are finished by invoking the provided callback.
|
|
46
|
+
*
|
|
47
|
+
* This callback will always be injected into the executed function as the last argument,
|
|
48
|
+
* and thus may be referenced with `arguments[arguments.length - 1]`.
|
|
49
|
+
*
|
|
50
|
+
* If the script invokes the `callback` with a return value, this will be made available
|
|
51
|
+
* via the {@link LastScriptExecution.result}.
|
|
52
|
+
*
|
|
53
|
+
* **Please note** that in order to signal an error in the `script` you need to throw an {@link Error}
|
|
54
|
+
* instead of passing it to the callback function.
|
|
55
|
+
*
|
|
56
|
+
* @example <caption>Executing an async script</caption>
|
|
57
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
58
|
+
*
|
|
59
|
+
* actor.attemptsTo(
|
|
60
|
+
* ExecuteScript.async(`
|
|
61
|
+
* var callback = arguments[arguments.length - 1];
|
|
62
|
+
*
|
|
63
|
+
* // do stuff
|
|
64
|
+
*
|
|
65
|
+
* callback(result)
|
|
66
|
+
* `)
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* @example <caption>Passing arguments to an async script</caption>
|
|
70
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
71
|
+
*
|
|
72
|
+
* actor.attemptsTo(
|
|
73
|
+
* ExecuteScript.async(`
|
|
74
|
+
* var name = arguments[0];
|
|
75
|
+
* var age = arguments[1];
|
|
76
|
+
* var callback = arguments[arguments.length - 1];
|
|
77
|
+
*
|
|
78
|
+
* // do stuff
|
|
79
|
+
*
|
|
80
|
+
* callback(result)
|
|
81
|
+
* `).withArguments('Bob', 24)
|
|
82
|
+
* );
|
|
83
|
+
*
|
|
84
|
+
* @example <caption>Passing Target arguments to an async script</caption>
|
|
85
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
86
|
+
*
|
|
87
|
+
* actor.attemptsTo(
|
|
88
|
+
* ExecuteScript.async(`
|
|
89
|
+
* var header = arguments[0]; // Target gets converted to a WebElement
|
|
90
|
+
* var callback = arguments[arguments.length - 1];
|
|
91
|
+
*
|
|
92
|
+
* callback(header.innerText)
|
|
93
|
+
* `).withArguments(Target.the('header').located(by.css('h1')))
|
|
94
|
+
* );
|
|
95
|
+
*
|
|
96
|
+
* @example <caption>Executing async script as function</caption>
|
|
97
|
+
* import { ExecuteScript } from '@serenity-js/webdriverio';
|
|
98
|
+
*
|
|
99
|
+
* actor.attemptsTo(
|
|
100
|
+
* ExecuteScript.async(function getText(header, callback) {
|
|
101
|
+
* callback(header.innerText)
|
|
102
|
+
* }).withArguments(Target.the('header').located(by.css('h1')))
|
|
103
|
+
* );
|
|
104
|
+
*
|
|
105
|
+
* @param {string | Function} script
|
|
106
|
+
* The script to be executed
|
|
107
|
+
*
|
|
108
|
+
* @returns {ExecuteScriptWithArguments}
|
|
109
|
+
*
|
|
110
|
+
* @see {@link LastScriptExecution.result}
|
|
111
|
+
*/
|
|
112
|
+
static async(script) {
|
|
113
|
+
return new ExecuteAsynchronousScript(script);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @desc
|
|
117
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
118
|
+
* execute a synchronous script in the context of the currently selected frame or window.
|
|
119
|
+
*
|
|
120
|
+
* If the script returns a value, it will be made available via {@link LastScriptExecution.result}.
|
|
121
|
+
*
|
|
122
|
+
* @example <caption>Executing a sync script as string and reading the result</caption>
|
|
123
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
124
|
+
* import { BrowseTheWeb, ExecuteScript, LastScriptExecution } from '@serenity-js/webdriverio';
|
|
125
|
+
* import { Ensure, includes } from '@serenity-js/assertions';
|
|
126
|
+
*
|
|
127
|
+
* actorCalled('Joseph')
|
|
128
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
129
|
+
* .attemptsTo(
|
|
130
|
+
* ExecuteScript.sync('return navigator.userAgent'),
|
|
131
|
+
* Ensure.that(LastScriptExecution.result<string>(), includes('Chrome')),
|
|
132
|
+
* );
|
|
133
|
+
*
|
|
134
|
+
* @example <caption>Executing a sync script as function and reading the result</caption>
|
|
135
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
136
|
+
* import { by, BrowseTheWeb, Enter, ExecuteScript, LastScriptExecution, Target } from '@serenity-js/webdriverio';
|
|
137
|
+
*
|
|
138
|
+
* const someOfferField = Target.the('offer code').located(by.id('offer-code'));
|
|
139
|
+
* const applyOfferCodeField = Target.the('apply offer field').located(by.id('apply-offer-code'));
|
|
140
|
+
*
|
|
141
|
+
* actorCalled('Joseph')
|
|
142
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
143
|
+
* .attemptsTo(
|
|
144
|
+
* // inject JavaScript to read some property of an element
|
|
145
|
+
* ExecuteScript.sync(function getValue(element) {
|
|
146
|
+
* return element.value;
|
|
147
|
+
* }).withArguments(someOfferField),
|
|
148
|
+
*
|
|
149
|
+
* // use LastScriptExecution.result() to read the value
|
|
150
|
+
* // returned from the injected script
|
|
151
|
+
* // and pass it to another interaction
|
|
152
|
+
* Enter.theValue(LastScriptExecution.result<string>()).into(applyOfferCodeField),
|
|
153
|
+
* );
|
|
154
|
+
*
|
|
155
|
+
* @param {string | Function} script
|
|
156
|
+
* The script to be executed
|
|
157
|
+
*
|
|
158
|
+
* @returns {ExecuteScriptWithArguments}
|
|
159
|
+
*
|
|
160
|
+
* @see {@link LastScriptExecution.result}
|
|
161
|
+
*/
|
|
162
|
+
static sync(script) {
|
|
163
|
+
return new ExecuteSynchronousScript(script);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ExecuteScript = ExecuteScript;
|
|
167
|
+
/**
|
|
168
|
+
* @desc
|
|
169
|
+
* Allows for a script to be executed to be parametrised.
|
|
170
|
+
*
|
|
171
|
+
* **Please note** that the arguments can be both synchronous and asynchronous {@link @serenity-js/core/lib/screenplay~Question}s
|
|
172
|
+
* as well as regular static values.
|
|
173
|
+
*
|
|
174
|
+
* @abstract
|
|
175
|
+
*
|
|
176
|
+
* @see {@link ExecuteScript}
|
|
177
|
+
*
|
|
178
|
+
* @extends {@serenity-js/core/lib/screenplay~Interaction}
|
|
179
|
+
*/
|
|
180
|
+
class ExecuteScriptWithArguments extends core_1.Interaction {
|
|
181
|
+
/**
|
|
182
|
+
* @param {string | Function} script
|
|
183
|
+
* The script to be executed
|
|
184
|
+
*
|
|
185
|
+
* @param {Array<Answerable<any>>} args
|
|
186
|
+
* Arguments to parametrise the script with
|
|
187
|
+
*/
|
|
188
|
+
constructor(script, // eslint-disable-line @typescript-eslint/ban-types
|
|
189
|
+
args = []) {
|
|
190
|
+
super();
|
|
191
|
+
this.script = script;
|
|
192
|
+
this.args = args;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @desc
|
|
196
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
197
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
198
|
+
*
|
|
199
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
200
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
201
|
+
*
|
|
202
|
+
* @returns {PromiseLike<void>}
|
|
203
|
+
*
|
|
204
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
205
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
206
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
207
|
+
*/
|
|
208
|
+
performAs(actor) {
|
|
209
|
+
// todo: interaction should store the result on the ability; the ability should not have a side-effect (?)
|
|
210
|
+
return Promise.all(this.args.map(arg => actor.answer(arg)))
|
|
211
|
+
.then(args => this.executeAs(actor, args))
|
|
212
|
+
.then(() => actor.collect(model_1.TextData.fromJSON({
|
|
213
|
+
contentType: 'text/javascript;charset=UTF-8',
|
|
214
|
+
data: this.script.toString(),
|
|
215
|
+
}), new model_1.Name('Script source')));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.ExecuteScriptWithArguments = ExecuteScriptWithArguments;
|
|
219
|
+
/**
|
|
220
|
+
* @package
|
|
221
|
+
*/
|
|
222
|
+
class ExecuteAsynchronousScript extends ExecuteScriptWithArguments {
|
|
223
|
+
withArguments(...args) {
|
|
224
|
+
return new ExecuteAsynchronousScript(this.script, args);
|
|
225
|
+
}
|
|
226
|
+
executeAs(actor, args) {
|
|
227
|
+
return abilities_1.BrowseTheWeb.as(actor).executeAsyncScript(this.script, ...args); // todo: fix types
|
|
228
|
+
}
|
|
229
|
+
toString() {
|
|
230
|
+
return this.args.length > 0
|
|
231
|
+
? (0, io_1.formatted) `#actor executes an asynchronous script with arguments: ${this.args}`
|
|
232
|
+
: `#actor executes an asynchronous script`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* @package
|
|
237
|
+
*
|
|
238
|
+
* https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html
|
|
239
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
|
240
|
+
*/
|
|
241
|
+
class ExecuteScriptFromUrl extends core_1.Interaction {
|
|
242
|
+
constructor(sourceUrl) {
|
|
243
|
+
super();
|
|
244
|
+
this.sourceUrl = sourceUrl;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* @desc
|
|
248
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
249
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
250
|
+
*
|
|
251
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
252
|
+
* @returns {Promise<void>}
|
|
253
|
+
*
|
|
254
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
255
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
256
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
257
|
+
*/
|
|
258
|
+
performAs(actor) {
|
|
259
|
+
return abilities_1.BrowseTheWeb.as(actor)
|
|
260
|
+
.executeAsyncScript(
|
|
261
|
+
/* istanbul ignore next */
|
|
262
|
+
function executeScriptFromUrl(sourceUrl, callback) {
|
|
263
|
+
const alreadyLoadedScripts = Array.prototype.slice
|
|
264
|
+
.call(document.querySelectorAll('script'))
|
|
265
|
+
.map(script => script.src);
|
|
266
|
+
if (~alreadyLoadedScripts.indexOf(sourceUrl)) {
|
|
267
|
+
return callback('Script from ' + sourceUrl + ' has already been loaded');
|
|
268
|
+
}
|
|
269
|
+
const script = document.createElement('script');
|
|
270
|
+
script.addEventListener('load', function () {
|
|
271
|
+
callback();
|
|
272
|
+
});
|
|
273
|
+
script.addEventListener('error', function () {
|
|
274
|
+
return callback('Couldn\'t load script from ' + sourceUrl);
|
|
275
|
+
});
|
|
276
|
+
script.src = sourceUrl;
|
|
277
|
+
script.async = true;
|
|
278
|
+
document.head.append(script);
|
|
279
|
+
}, this.sourceUrl)
|
|
280
|
+
.then(errorMessage => {
|
|
281
|
+
if (errorMessage) {
|
|
282
|
+
throw new core_1.LogicError(errorMessage);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @desc
|
|
288
|
+
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
289
|
+
*
|
|
290
|
+
* @returns {string}
|
|
291
|
+
*/
|
|
292
|
+
toString() {
|
|
293
|
+
return `#actor executes a script from ${this.sourceUrl}`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* @package
|
|
298
|
+
*/
|
|
299
|
+
class ExecuteSynchronousScript extends ExecuteScriptWithArguments {
|
|
300
|
+
withArguments(...args) {
|
|
301
|
+
return new ExecuteSynchronousScript(this.script, args);
|
|
302
|
+
}
|
|
303
|
+
executeAs(actor, args) {
|
|
304
|
+
return abilities_1.BrowseTheWeb.as(actor).executeScript(this.script, ...args); // todo fix type
|
|
305
|
+
}
|
|
306
|
+
toString() {
|
|
307
|
+
return this.args.length > 0
|
|
308
|
+
? (0, io_1.formatted) `#actor executes a synchronous script with arguments: ${this.args}`
|
|
309
|
+
: `#actor executes a synchronous script`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=ExecuteScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecuteScript.js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,IAAI,CAAC,CAAC,CAAI,gBAAgB;IAC5G,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;YACvB,CAAC,CAAC,IAAA,cAAS,EAAC,wDAAyD,IAAI,CAAC,IAAK,EAAE;YACjF,CAAC,CAAC,sCAAsC,CAAC;IACjD,CAAC;CACJ"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, Interaction, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { PageElement } from '../models';
|
|
3
|
+
import { PageElementInteraction } from './PageElementInteraction';
|
|
4
|
+
/**
|
|
5
|
+
* @desc
|
|
6
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
7
|
+
* hover the mouse pointer over a given Web element.
|
|
8
|
+
*
|
|
9
|
+
* @example <caption>Example widget</caption>
|
|
10
|
+
* <a data-test="example-link"
|
|
11
|
+
* class="off"
|
|
12
|
+
* onmouseover="this.className='on';"
|
|
13
|
+
* onmouseout="this.className='off';"
|
|
14
|
+
* href="/">hover over me</a>
|
|
15
|
+
*
|
|
16
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
17
|
+
* import { by, Target } from '@serenity-js/webdriverio';
|
|
18
|
+
*
|
|
19
|
+
* class Example {
|
|
20
|
+
* static link = Target.the('example link')
|
|
21
|
+
* .located(by.css('[data-test="example-link"]'));
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example <caption>Hovering over an element</caption>
|
|
25
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
26
|
+
* import { BrowseTheWeb, Hover, CssClasses } from '@serenity-js/webdriverio';
|
|
27
|
+
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
28
|
+
*
|
|
29
|
+
* actorCalled('Hank')
|
|
30
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
31
|
+
* .attemptsTo(
|
|
32
|
+
* Ensure.that(CssClasses.of(Example.link), equals([ 'off' ])),
|
|
33
|
+
*
|
|
34
|
+
* Hover.over(Example.link),
|
|
35
|
+
* Ensure.that(CssClasses.of(Example.link), equals([ 'on' ])),
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* @see {@link BrowseTheWeb}
|
|
39
|
+
* @see {@link Target}
|
|
40
|
+
* @see {@link CssClasses}
|
|
41
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
42
|
+
* @see {@link @serenity-js/assertions/lib/expectations~equals}
|
|
43
|
+
*
|
|
44
|
+
* @extends {ElementInteraction}
|
|
45
|
+
*/
|
|
46
|
+
export declare class Hover extends PageElementInteraction {
|
|
47
|
+
private readonly target;
|
|
48
|
+
/**
|
|
49
|
+
* @desc
|
|
50
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
51
|
+
*
|
|
52
|
+
* @param {Answerable<PageElement>} target
|
|
53
|
+
* The element to be hovered over
|
|
54
|
+
*
|
|
55
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
56
|
+
*/
|
|
57
|
+
static over(target: Answerable<PageElement>): Interaction;
|
|
58
|
+
/**
|
|
59
|
+
* @param {Answerable<PageElement>} target
|
|
60
|
+
* The element to be hovered over
|
|
61
|
+
*/
|
|
62
|
+
constructor(target: Answerable<PageElement>);
|
|
63
|
+
/**
|
|
64
|
+
* @desc
|
|
65
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
66
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
67
|
+
*
|
|
68
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
69
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
70
|
+
*
|
|
71
|
+
* @returns {PromiseLike<void>}
|
|
72
|
+
*
|
|
73
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
74
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
75
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
76
|
+
*/
|
|
77
|
+
performAs(actor: UsesAbilities & AnswersQuestions): Promise<void>;
|
|
78
|
+
}
|