@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,209 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, Interaction, TestCompromisedError, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
|
|
4
|
+
import { BrowseTheWeb } from '../abilities';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @desc
|
|
8
|
+
* Allows the {@link @serenity-js/core/lib/screenplay/actor~Actor} to navigate
|
|
9
|
+
* to a specific destination, as well as back and forth in the browser history,
|
|
10
|
+
* or reload the current page.
|
|
11
|
+
*/
|
|
12
|
+
export class Navigate {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @desc
|
|
16
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
17
|
+
* to navigate to a given URL.
|
|
18
|
+
*
|
|
19
|
+
* The URL can be:
|
|
20
|
+
* - absolute, i.e. `https://example.org/search`
|
|
21
|
+
* - relative, i.e. `/search`
|
|
22
|
+
*
|
|
23
|
+
* If the URL is relative, WebdriverIO will append it to `baseUrl` specified in
|
|
24
|
+
* the [configuration file](https://webdriver.io/docs/configurationfile/).
|
|
25
|
+
*
|
|
26
|
+
* @example <caption>wdio.conf.ts</caption>
|
|
27
|
+
* export const config = {
|
|
28
|
+
* baseUrl: 'https://example.org',
|
|
29
|
+
* // ...
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @example <caption>Navigate to path relative to baseUrl</caption>
|
|
33
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
34
|
+
* import { BrowseTheWeb, Navigate } from '@serenity-js/webdriverio';
|
|
35
|
+
*
|
|
36
|
+
* actorCalled('Hannu')
|
|
37
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
38
|
+
* .attemptsTo(
|
|
39
|
+
* Navigate.to('/search'),
|
|
40
|
+
* );
|
|
41
|
+
*
|
|
42
|
+
* @example <caption>Navigate to an absolute URL (overrides baseUrl)</caption>
|
|
43
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
44
|
+
* import { BrowseTheWeb, Navigate } from '@serenity-js/webdriverio';
|
|
45
|
+
*
|
|
46
|
+
* actorCalled('Hannu')
|
|
47
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
48
|
+
* .attemptsTo(
|
|
49
|
+
* Navigate.to('https://mycompany.org/login'),
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* @param {Answerable<string>} url
|
|
53
|
+
* An absolute URL or path an {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
54
|
+
* should navigate to
|
|
55
|
+
*
|
|
56
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
57
|
+
*
|
|
58
|
+
* @see {@link BrowseTheWeb}
|
|
59
|
+
*/
|
|
60
|
+
static to(url: Answerable<string>): Interaction {
|
|
61
|
+
return new NavigateToUrl(url);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @desc
|
|
66
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
67
|
+
* navigate back one page in the joint session history of the current top-level browsing context.
|
|
68
|
+
*
|
|
69
|
+
* @example <caption>Navigate to path relative to baseUrl</caption>
|
|
70
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
71
|
+
* import { Ensure, endsWith } from '@serenity-js/assertions';
|
|
72
|
+
* import { BrowseTheWeb, Navigate } from '@serenity-js/webdriverio';
|
|
73
|
+
*
|
|
74
|
+
* actorCalled('Hannu')
|
|
75
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
76
|
+
* .attemptsTo(
|
|
77
|
+
* Navigate.to('/first'),
|
|
78
|
+
* Navigate.to('/second'),
|
|
79
|
+
*
|
|
80
|
+
* Navigate.back(),
|
|
81
|
+
*
|
|
82
|
+
* Ensure.that(Website.url(), endsWith('/first')),
|
|
83
|
+
* );
|
|
84
|
+
*
|
|
85
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
86
|
+
*
|
|
87
|
+
* @see https://webdriver.io/docs/api/webdriver/#back
|
|
88
|
+
* @see {@link BrowseTheWeb}
|
|
89
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
90
|
+
* @see {@link @serenity-js/assertions/lib/expectations~endsWith}
|
|
91
|
+
*/
|
|
92
|
+
static back(): Interaction {
|
|
93
|
+
return Interaction.where(`#actor navigates back in the browser history`, actor =>
|
|
94
|
+
BrowseTheWeb.as(actor).navigateBack(),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @desc
|
|
100
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
101
|
+
* navigate forward one page in the session history.
|
|
102
|
+
*
|
|
103
|
+
* @example <caption>Navigate to path relative to baseUrl</caption>
|
|
104
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
105
|
+
* import { Ensure, endsWith } from '@serenity-js/assertions';
|
|
106
|
+
* import { BrowseTheWeb, Navigate } from '@serenity-js/webdriverio';
|
|
107
|
+
*
|
|
108
|
+
* actorCalled('Hannu')
|
|
109
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
110
|
+
* .attemptsTo(
|
|
111
|
+
* Navigate.to('/first'),
|
|
112
|
+
* Navigate.to('/second'),
|
|
113
|
+
*
|
|
114
|
+
* Navigate.back(),
|
|
115
|
+
* Navigate.forward(),
|
|
116
|
+
*
|
|
117
|
+
* Ensure.that(Website.url(), endsWith('/second')),
|
|
118
|
+
* );
|
|
119
|
+
*
|
|
120
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
121
|
+
*
|
|
122
|
+
* @see {@link BrowseTheWeb}
|
|
123
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
124
|
+
* @see {@link @serenity-js/assertions/lib/expectations~endsWith}
|
|
125
|
+
* @see https://webdriver.io/docs/api/webdriver/#forward
|
|
126
|
+
*/
|
|
127
|
+
static forward(): Interaction {
|
|
128
|
+
return Interaction.where(`#actor navigates forward in the browser history`, actor =>
|
|
129
|
+
BrowseTheWeb.as(actor).navigateForward(),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @desc
|
|
135
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
136
|
+
* reload the current page.
|
|
137
|
+
*
|
|
138
|
+
* @example <caption>Navigate to path relative to baseUrl</caption>
|
|
139
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
140
|
+
* import { Ensure, endsWith } from '@serenity-js/assertions';
|
|
141
|
+
* import { Navigate, Cookie } from '@serenity-js/web';
|
|
142
|
+
* import { BrowseTheWebWithWebdriverIO } from '@serenity-js/webdriverio';
|
|
143
|
+
*
|
|
144
|
+
* actorCalled('Hannu')
|
|
145
|
+
* .whoCan(BrowseTheWebWithWebdriverIO.using(browser))
|
|
146
|
+
* .attemptsTo(
|
|
147
|
+
* Navigate.to('/login'),
|
|
148
|
+
* Cookie.called('session_id').delete(),
|
|
149
|
+
* Navigate.reloadPage(),
|
|
150
|
+
* );
|
|
151
|
+
*
|
|
152
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
153
|
+
*
|
|
154
|
+
* @see {@link BrowseTheWeb}
|
|
155
|
+
* @see {@link Cookie}
|
|
156
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
157
|
+
* @see {@link @serenity-js/assertions/lib/expectations~endsWith}
|
|
158
|
+
*/
|
|
159
|
+
static reloadPage(): Interaction {
|
|
160
|
+
return Interaction.where(`#actor reloads the page`, actor =>
|
|
161
|
+
BrowseTheWeb.as(actor).reloadPage(),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @package
|
|
168
|
+
*/
|
|
169
|
+
class NavigateToUrl extends Interaction {
|
|
170
|
+
constructor(private readonly url: Answerable<string>) {
|
|
171
|
+
super();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @desc
|
|
176
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
177
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
178
|
+
*
|
|
179
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
180
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
181
|
+
* to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
182
|
+
*
|
|
183
|
+
* @returns {PromiseLike<void>}
|
|
184
|
+
*
|
|
185
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
186
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
187
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
188
|
+
*/
|
|
189
|
+
performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void> {
|
|
190
|
+
return actor.answer(this.url)
|
|
191
|
+
.then(url =>
|
|
192
|
+
BrowseTheWeb.as(actor)
|
|
193
|
+
.navigateTo(url)
|
|
194
|
+
.catch(error => {
|
|
195
|
+
throw new TestCompromisedError(`Couldn't navigate to ${ url }`, error);
|
|
196
|
+
})
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @desc
|
|
202
|
+
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
203
|
+
*
|
|
204
|
+
* @returns {string}
|
|
205
|
+
*/
|
|
206
|
+
toString(): string {
|
|
207
|
+
return formatted `#actor navigates to ${ this.url }`;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, Interaction, LogicError } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
|
|
4
|
+
import { PageElement } from '../models';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @desc
|
|
8
|
+
* A base class for interactions with {@link PageElement}s.
|
|
9
|
+
*
|
|
10
|
+
* @extends {@serenity-js/core/lib/screenplay~Interaction}
|
|
11
|
+
*/
|
|
12
|
+
export abstract class PageElementInteraction extends Interaction {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} description
|
|
16
|
+
* A human-readable description to be used when reporting
|
|
17
|
+
* this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
18
|
+
*
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
protected constructor(private readonly description: string) {
|
|
22
|
+
super();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @desc
|
|
27
|
+
* Returns the resolved {@link PageElement}, or throws a {@link @serenity-js/core/lib/errors~LogicError}
|
|
28
|
+
* if the element is `undefined`.
|
|
29
|
+
*
|
|
30
|
+
* @param {@serenity-js/core/lib/screenplay/actor~AnswersQuestions} actor
|
|
31
|
+
* @param {@serenity-js/core/lib/screenplay~Answerable<Element<'async'>>} element
|
|
32
|
+
*
|
|
33
|
+
* @returns {Promise<PageElement>}
|
|
34
|
+
*
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
protected async resolve(
|
|
38
|
+
actor: AnswersQuestions,
|
|
39
|
+
element: Answerable<PageElement>,
|
|
40
|
+
): Promise<PageElement> {
|
|
41
|
+
const resolved = await actor.answer(element);
|
|
42
|
+
|
|
43
|
+
if (! resolved) {
|
|
44
|
+
throw new LogicError(formatted `Couldn't find ${ element }`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return resolved;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @desc
|
|
52
|
+
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
53
|
+
*
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
toString(): string {
|
|
57
|
+
return this.description;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Activity, Answerable, AnswersQuestions, Interaction, Question, UsesAbilities } from '@serenity-js/core';
|
|
2
|
+
import { formatted } from '@serenity-js/core/lib/io';
|
|
3
|
+
|
|
4
|
+
import { Key } from '../../input';
|
|
5
|
+
import { BrowseTheWeb } from '../abilities';
|
|
6
|
+
import { PageElement } from '../models';
|
|
7
|
+
import { PageElementInteraction } from './PageElementInteraction';
|
|
8
|
+
import { PressBuilder } from './PressBuilder';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @desc
|
|
12
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
13
|
+
* send a key press or a sequence of keys to a Web element.
|
|
14
|
+
*
|
|
15
|
+
* *Please note*: On macOS, some keyboard shortcuts might not work with the [`devtools` protocol](https://webdriver.io/docs/automationProtocols/#devtools-protocol).
|
|
16
|
+
*
|
|
17
|
+
* For example:
|
|
18
|
+
* - to *copy*, instead of `Meta+C`, use `Control+Insert`
|
|
19
|
+
* - to *cut*, instead of `Meta+X`, use `Control+Delete`
|
|
20
|
+
* - to *paste*, instead of `Meta+V`, use `Shift+Insert`
|
|
21
|
+
*
|
|
22
|
+
* @example <caption>Example widget</caption>
|
|
23
|
+
* <form>
|
|
24
|
+
* <input type="text" name="example" id="example" />
|
|
25
|
+
* </form>
|
|
26
|
+
*
|
|
27
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
28
|
+
* import { by, Target } from '@serenity-js/webdriverio';
|
|
29
|
+
*
|
|
30
|
+
* class Form {
|
|
31
|
+
* static exampleInput = Target.the('example input')
|
|
32
|
+
* .located(by.id('example'));
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* @example <caption>Pressing keys</caption>
|
|
36
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
37
|
+
* import { BrowseTheWeb, Key, Press, Value } from '@serenity-js/webdriverio';
|
|
38
|
+
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
39
|
+
*
|
|
40
|
+
* actorCalled('Priyanka')
|
|
41
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
42
|
+
* .attemptsTo(
|
|
43
|
+
* Press.the('H', 'i', '!', Key.ENTER).in(Form.exampleInput),
|
|
44
|
+
* Ensure.that(Value.of(Form.exampleInput), equals('Hi!')),
|
|
45
|
+
* );
|
|
46
|
+
*
|
|
47
|
+
* @see {@link Key}
|
|
48
|
+
* @see {@link BrowseTheWeb}
|
|
49
|
+
* @see {@link Target}
|
|
50
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
51
|
+
* @see {@link @serenity-js/assertions/lib/expectations~equals}
|
|
52
|
+
*
|
|
53
|
+
* @extends {ElementInteraction}
|
|
54
|
+
*/
|
|
55
|
+
export class Press extends PageElementInteraction {
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @desc
|
|
59
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
60
|
+
*
|
|
61
|
+
* @param {...keys: Array<Answerable<Key | string | Key[] | string[]>>} keys
|
|
62
|
+
* A sequence of one or more keys to press
|
|
63
|
+
*
|
|
64
|
+
* @returns {PressBuilder}
|
|
65
|
+
*/
|
|
66
|
+
static the(...keys: Array<Answerable<Key | string | Key[] | string[]>>): Activity & PressBuilder {
|
|
67
|
+
return new Press(KeySequence.of(keys));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
in(field: Answerable<PageElement> /* | Question<AlertPromise> | AlertPromise */): Interaction {
|
|
71
|
+
return new PressKeyInField(this.keys, field)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {Answerable<Array<Key | string>>} keys
|
|
76
|
+
* A sequence of one or more keys to press
|
|
77
|
+
*/
|
|
78
|
+
constructor(
|
|
79
|
+
private readonly keys: Answerable<Array<Key | string>>
|
|
80
|
+
) {
|
|
81
|
+
super(formatted `#actor presses ${ keys }`);
|
|
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 keys = await actor.answer(this.keys);
|
|
100
|
+
return BrowseTheWeb.as(actor).sendKeys(keys);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class PressKeyInField extends PageElementInteraction {
|
|
105
|
+
/**
|
|
106
|
+
* @param {Answerable<Array<Key | string>>} keys
|
|
107
|
+
* A sequence of one or more keys to press
|
|
108
|
+
*
|
|
109
|
+
* @param {Answerable<PageElement>} field
|
|
110
|
+
* Web element to send the keys to
|
|
111
|
+
*/
|
|
112
|
+
constructor(
|
|
113
|
+
private readonly keys: Answerable<Array<Key | string>>,
|
|
114
|
+
private readonly field: Answerable<PageElement> /* todo | Question<AlertPromise> | AlertPromise */,
|
|
115
|
+
) {
|
|
116
|
+
super(formatted `#actor presses ${ keys } in ${ field }`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async performAs(actor: UsesAbilities & AnswersQuestions): Promise<void> {
|
|
120
|
+
const field = await this.resolve(actor, this.field);
|
|
121
|
+
const keys = await actor.answer(this.keys);
|
|
122
|
+
|
|
123
|
+
// fix for protractor
|
|
124
|
+
// todo: should this wait on focus to occur?
|
|
125
|
+
await BrowseTheWeb.as(actor).executeScript(
|
|
126
|
+
/* istanbul ignore next */
|
|
127
|
+
function focus(element: any) {
|
|
128
|
+
element.focus();
|
|
129
|
+
},
|
|
130
|
+
await field.nativeElement(),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return BrowseTheWeb.as(actor).sendKeys(keys);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @package
|
|
139
|
+
*/
|
|
140
|
+
class KeySequence extends Question<Promise<Array<Key | string>>> {
|
|
141
|
+
private subject: string;
|
|
142
|
+
|
|
143
|
+
static of(keys: Array<Answerable<Key | string | Key[] | string[]>>) {
|
|
144
|
+
return new KeySequence(keys);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
constructor(private readonly keys: Array<Answerable<Key | string | Key[] | string[]>>) {
|
|
148
|
+
super();
|
|
149
|
+
this.subject = KeySequence.describe(keys);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<Array<string | Key>> {
|
|
153
|
+
return Promise.all(
|
|
154
|
+
this.keys.map(part => actor.answer(part))
|
|
155
|
+
).then(keys => {
|
|
156
|
+
return keys.flat().filter(key => !! key)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @desc
|
|
162
|
+
* Changes the description of this question's subject.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} subject
|
|
165
|
+
* @returns {Question<T>}
|
|
166
|
+
*/
|
|
167
|
+
describedAs(subject: string): this {
|
|
168
|
+
this.subject = subject;
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
toString(): string {
|
|
173
|
+
return this.subject;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private static describe(keys: Array<Answerable<Key | string | Key[] | string[]>>): string {
|
|
177
|
+
const prefix = keys.length === 1 ? 'key' : 'keys';
|
|
178
|
+
|
|
179
|
+
const description = keys.reduce((acc, key, index) => {
|
|
180
|
+
const separator = Key.isKey(key) && key.isModifier
|
|
181
|
+
? '-'
|
|
182
|
+
: acc.separator;
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
description: index === 0
|
|
186
|
+
? `${ key }`
|
|
187
|
+
: `${ acc.description }${acc.separator}${ key }`,
|
|
188
|
+
separator,
|
|
189
|
+
}
|
|
190
|
+
}, { description: '', separator: ', ' }).description;
|
|
191
|
+
|
|
192
|
+
return `${ prefix } ${ description }`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Answerable } from '@serenity-js/core';
|
|
2
|
+
import { Interaction } from '@serenity-js/core/lib/screenplay';
|
|
3
|
+
|
|
4
|
+
import { PageElement } from '../models';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @desc
|
|
8
|
+
* Fluent interface to make the instantiation of
|
|
9
|
+
* the {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
10
|
+
* to {@link Press} more readable.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link Press}
|
|
13
|
+
*
|
|
14
|
+
* @interface
|
|
15
|
+
*/
|
|
16
|
+
export interface PressBuilder {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @desc
|
|
20
|
+
* Instantiates an {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
21
|
+
* to {@link Press}.
|
|
22
|
+
*
|
|
23
|
+
* @param {Answerable<PageElement>} field
|
|
24
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
25
|
+
*
|
|
26
|
+
* @see {@link Target}
|
|
27
|
+
*/
|
|
28
|
+
in: (field: Answerable<PageElement> /* | Question<AlertPromise> | AlertPromise */) => Interaction;
|
|
29
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
* perfom a right click on a given Web element.
|
|
11
|
+
*
|
|
12
|
+
* This is typically used to open a [custom context menu](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event)
|
|
13
|
+
* on a given Web element, since it's not possible to interact with the standard context menu offered by your browser
|
|
14
|
+
*
|
|
15
|
+
* @example <caption>Example widget</caption>
|
|
16
|
+
* <form>
|
|
17
|
+
* <input type="text" id="field"
|
|
18
|
+
* oncontextmenu="showMenu(); return false;" />
|
|
19
|
+
*
|
|
20
|
+
* <div id="context-menu" style="display:none">
|
|
21
|
+
* Custom context menu
|
|
22
|
+
* </div>
|
|
23
|
+
* </form>
|
|
24
|
+
*
|
|
25
|
+
* <script>
|
|
26
|
+
* function showMenu() {
|
|
27
|
+
* document.getElementById("context-menu").style.display = 'block';
|
|
28
|
+
* }
|
|
29
|
+
* </script>
|
|
30
|
+
*
|
|
31
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
32
|
+
* import { by, Target } from '@serenity-js/webdriverio';
|
|
33
|
+
*
|
|
34
|
+
* class Form {
|
|
35
|
+
* static exampleInput = Target.the('example input')
|
|
36
|
+
* .located(by.id('example'));
|
|
37
|
+
* static exampleContextMenu = Target.the('example context menu')
|
|
38
|
+
* .located(by.id('context-menu'));
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* @example <caption>Right-click on an element</caption>
|
|
42
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
43
|
+
* import { BrowseTheWeb, RightClick, isVisible } from '@serenity-js/webdriverio';
|
|
44
|
+
* import { Ensure } from '@serenity-js/assertions';
|
|
45
|
+
*
|
|
46
|
+
* actorCalled('Chloé')
|
|
47
|
+
* .whoCan(BrowseTheWeb.using(browser))
|
|
48
|
+
* .attemptsTo(
|
|
49
|
+
* RightClick.on(Form.exampleInput),
|
|
50
|
+
* Ensure.that(Form.exampleContextMenu, isVisible()),
|
|
51
|
+
* );
|
|
52
|
+
*
|
|
53
|
+
* @see {@link BrowseTheWeb}
|
|
54
|
+
* @see {@link Target}
|
|
55
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
56
|
+
* @see {@link isVisible}
|
|
57
|
+
*
|
|
58
|
+
* @extends {ElementInteraction}
|
|
59
|
+
*/
|
|
60
|
+
export class RightClick extends PageElementInteraction {
|
|
61
|
+
/**
|
|
62
|
+
* @desc
|
|
63
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
64
|
+
*
|
|
65
|
+
* @param {Answerable<PageElement>} target
|
|
66
|
+
* The element to be right-clicked on
|
|
67
|
+
*
|
|
68
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
69
|
+
*/
|
|
70
|
+
static on(target: Answerable<PageElement>): Interaction {
|
|
71
|
+
return new RightClick(target);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {Answerable<PageElement>} target
|
|
76
|
+
* The element to be right-clicked on
|
|
77
|
+
*/
|
|
78
|
+
constructor(private readonly target: Answerable<PageElement>) {
|
|
79
|
+
super(formatted `#actor right-clicks on ${ target }`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @desc
|
|
84
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
85
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
86
|
+
*
|
|
87
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
88
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
89
|
+
*
|
|
90
|
+
* @returns {PromiseLike<void>}
|
|
91
|
+
*
|
|
92
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
93
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
94
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
95
|
+
*/
|
|
96
|
+
async performAs(actor: UsesAbilities & AnswersQuestions): Promise<void> {
|
|
97
|
+
const element = await this.resolve(actor, this.target);
|
|
98
|
+
return element.rightClick();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @desc
|
|
8
|
+
* Instructs the {@link @serenity-js/core/lib/screenplay/actor~Actor} to
|
|
9
|
+
* scroll until a given Web element comes into view.
|
|
10
|
+
*
|
|
11
|
+
* @example <caption>Example widget</caption>
|
|
12
|
+
* <!--
|
|
13
|
+
* an element somewhere at the bottom of the page,
|
|
14
|
+
* outside of the visible area
|
|
15
|
+
* -->
|
|
16
|
+
* <input type="submit" id="submit" />
|
|
17
|
+
*
|
|
18
|
+
* @example <caption>Lean Page Object describing the widget</caption>
|
|
19
|
+
* import { Target } from '@serenity-js/protractor';
|
|
20
|
+
* import { by } from 'protractor';
|
|
21
|
+
*
|
|
22
|
+
* class Form {
|
|
23
|
+
* static submitButton = Target.the('submit button')
|
|
24
|
+
* .located(by.id('submit'));
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @example <caption>Scrolling to element</caption>
|
|
28
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
29
|
+
* import { Ensure } from '@serenity-js/assertions';
|
|
30
|
+
* import { BrowseTheWeb, Scroll, isVisible } from '@serenity-js/protractor';
|
|
31
|
+
* import { protractor } from 'protractor';
|
|
32
|
+
*
|
|
33
|
+
* actorCalled('Sara')
|
|
34
|
+
* .whoCan(BrowseTheWeb.using(protractor.browser))
|
|
35
|
+
* .attemptsTo(
|
|
36
|
+
* Scroll.to(Form.submitButton),
|
|
37
|
+
* Ensure.that(Form.submitButton, isVisible()),
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* @see {@link BrowseTheWeb}
|
|
41
|
+
* @see {@link Target}
|
|
42
|
+
* @see {@link isVisible}
|
|
43
|
+
* @see {@link @serenity-js/assertions~Ensure}
|
|
44
|
+
*
|
|
45
|
+
* @extends {@serenity-js/core/lib/screenplay~Interaction}
|
|
46
|
+
*/
|
|
47
|
+
export class Scroll extends Interaction {
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @desc
|
|
51
|
+
* Instantiates this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
52
|
+
*
|
|
53
|
+
* @param {Answerable<PageElement>} target
|
|
54
|
+
* The element to be scroll to
|
|
55
|
+
*
|
|
56
|
+
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
57
|
+
*/
|
|
58
|
+
static to(target: Answerable<PageElement>): Scroll {
|
|
59
|
+
return new Scroll(target);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {Answerable<PageElement>} target
|
|
64
|
+
* The element to be scroll to
|
|
65
|
+
*/
|
|
66
|
+
constructor(private readonly target: Answerable<PageElement>) {
|
|
67
|
+
super();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @desc
|
|
72
|
+
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
73
|
+
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
74
|
+
*
|
|
75
|
+
* @param {UsesAbilities & AnswersQuestions} actor
|
|
76
|
+
* An {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
77
|
+
*
|
|
78
|
+
* @returns {PromiseLike<void>}
|
|
79
|
+
*
|
|
80
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
81
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
82
|
+
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
83
|
+
*/
|
|
84
|
+
async performAs(actor: UsesAbilities & AnswersQuestions): Promise<void> {
|
|
85
|
+
const target = await actor.answer(this.target);
|
|
86
|
+
|
|
87
|
+
return target.scrollIntoView();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @desc
|
|
92
|
+
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
93
|
+
*
|
|
94
|
+
* @returns {string}
|
|
95
|
+
*/
|
|
96
|
+
toString(): string {
|
|
97
|
+
return formatted `#actor scrolls to ${ this.target }`;
|
|
98
|
+
}
|
|
99
|
+
}
|