@serenity-js/protractor 3.0.0-rc.9 → 3.0.1

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.
Files changed (169) hide show
  1. package/CHANGELOG.md +144 -2236
  2. package/README.md +39 -26
  3. package/lib/adapter/Config.d.ts +11 -9
  4. package/lib/adapter/Config.d.ts.map +1 -0
  5. package/lib/adapter/ProtractorFrameworkAdapter.d.ts +2 -3
  6. package/lib/adapter/ProtractorFrameworkAdapter.d.ts.map +1 -0
  7. package/lib/adapter/ProtractorFrameworkAdapter.js +11 -10
  8. package/lib/adapter/ProtractorFrameworkAdapter.js.map +1 -1
  9. package/lib/adapter/browser-detector/BrowserDetector.d.ts +1 -0
  10. package/lib/adapter/browser-detector/BrowserDetector.d.ts.map +1 -0
  11. package/lib/adapter/browser-detector/BrowserDetector.js +5 -5
  12. package/lib/adapter/browser-detector/BrowserDetector.js.map +1 -1
  13. package/lib/adapter/browser-detector/StandardisedCapabilities.d.ts +5 -4
  14. package/lib/adapter/browser-detector/StandardisedCapabilities.d.ts.map +1 -0
  15. package/lib/adapter/browser-detector/StandardisedCapabilities.js +17 -17
  16. package/lib/adapter/browser-detector/StandardisedCapabilities.js.map +1 -1
  17. package/lib/adapter/browser-detector/index.d.ts +1 -0
  18. package/lib/adapter/browser-detector/index.d.ts.map +1 -0
  19. package/lib/adapter/browser-detector/index.js +5 -1
  20. package/lib/adapter/browser-detector/index.js.map +1 -1
  21. package/lib/adapter/index.d.ts +2 -0
  22. package/lib/adapter/index.d.ts.map +1 -0
  23. package/lib/adapter/index.js +6 -1
  24. package/lib/adapter/index.js.map +1 -1
  25. package/lib/adapter/reporter/ProtractorReport.d.ts +5 -6
  26. package/lib/adapter/reporter/ProtractorReport.d.ts.map +1 -0
  27. package/lib/adapter/reporter/ProtractorReporter.d.ts +1 -0
  28. package/lib/adapter/reporter/ProtractorReporter.d.ts.map +1 -0
  29. package/lib/adapter/reporter/ProtractorReporter.js +10 -5
  30. package/lib/adapter/reporter/ProtractorReporter.js.map +1 -1
  31. package/lib/adapter/reporter/index.d.ts +1 -0
  32. package/lib/adapter/reporter/index.d.ts.map +1 -0
  33. package/lib/adapter/reporter/index.js +5 -1
  34. package/lib/adapter/reporter/index.js.map +1 -1
  35. package/lib/adapter/run.d.ts +7 -4
  36. package/lib/adapter/run.d.ts.map +1 -0
  37. package/lib/adapter/run.js +6 -4
  38. package/lib/adapter/run.js.map +1 -1
  39. package/lib/adapter/runner/CucumberAdapterConfig.d.ts +5 -10
  40. package/lib/adapter/runner/CucumberAdapterConfig.d.ts.map +1 -0
  41. package/lib/adapter/runner/TestRunnerDetector.d.ts +5 -12
  42. package/lib/adapter/runner/TestRunnerDetector.d.ts.map +1 -0
  43. package/lib/adapter/runner/TestRunnerDetector.js +7 -15
  44. package/lib/adapter/runner/TestRunnerDetector.js.map +1 -1
  45. package/lib/adapter/runner/TestRunnerLoader.d.ts +20 -17
  46. package/lib/adapter/runner/TestRunnerLoader.d.ts.map +1 -0
  47. package/lib/adapter/runner/TestRunnerLoader.js +18 -18
  48. package/lib/adapter/runner/TestRunnerLoader.js.map +1 -1
  49. package/lib/adapter/runner/index.d.ts +1 -0
  50. package/lib/adapter/runner/index.d.ts.map +1 -0
  51. package/lib/adapter/runner/index.js +5 -1
  52. package/lib/adapter/runner/index.js.map +1 -1
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.d.ts.map +1 -0
  55. package/lib/index.js +5 -1
  56. package/lib/index.js.map +1 -1
  57. package/lib/screenplay/abilities/BrowseTheWebWithProtractor.d.ts +62 -300
  58. package/lib/screenplay/abilities/BrowseTheWebWithProtractor.d.ts.map +1 -0
  59. package/lib/screenplay/abilities/BrowseTheWebWithProtractor.js +62 -422
  60. package/lib/screenplay/abilities/BrowseTheWebWithProtractor.js.map +1 -1
  61. package/lib/screenplay/abilities/index.d.ts +1 -0
  62. package/lib/screenplay/abilities/index.d.ts.map +1 -0
  63. package/lib/screenplay/abilities/index.js +5 -1
  64. package/lib/screenplay/abilities/index.js.map +1 -1
  65. package/lib/screenplay/index.d.ts +1 -0
  66. package/lib/screenplay/index.d.ts.map +1 -0
  67. package/lib/screenplay/index.js +5 -1
  68. package/lib/screenplay/index.js.map +1 -1
  69. package/lib/screenplay/interactions/UseAngular.d.ts +53 -48
  70. package/lib/screenplay/interactions/UseAngular.d.ts.map +1 -0
  71. package/lib/screenplay/interactions/UseAngular.js +52 -42
  72. package/lib/screenplay/interactions/UseAngular.js.map +1 -1
  73. package/lib/screenplay/interactions/index.d.ts +1 -0
  74. package/lib/screenplay/interactions/index.d.ts.map +1 -0
  75. package/lib/screenplay/interactions/index.js +5 -1
  76. package/lib/screenplay/interactions/index.js.map +1 -1
  77. package/lib/screenplay/models/ProtractorBrowsingSession.d.ts +22 -0
  78. package/lib/screenplay/models/ProtractorBrowsingSession.d.ts.map +1 -0
  79. package/lib/screenplay/models/ProtractorBrowsingSession.js +99 -0
  80. package/lib/screenplay/models/ProtractorBrowsingSession.js.map +1 -0
  81. package/lib/screenplay/models/ProtractorCookie.d.ts +6 -0
  82. package/lib/screenplay/models/ProtractorCookie.d.ts.map +1 -0
  83. package/lib/screenplay/models/ProtractorCookie.js +8 -3
  84. package/lib/screenplay/models/ProtractorCookie.js.map +1 -1
  85. package/lib/screenplay/models/ProtractorErrorHandler.d.ts +8 -0
  86. package/lib/screenplay/models/ProtractorErrorHandler.d.ts.map +1 -0
  87. package/lib/screenplay/models/ProtractorErrorHandler.js +23 -0
  88. package/lib/screenplay/models/ProtractorErrorHandler.js.map +1 -0
  89. package/lib/screenplay/models/ProtractorModalDialogHandler.d.ts +25 -0
  90. package/lib/screenplay/models/ProtractorModalDialogHandler.d.ts.map +1 -0
  91. package/lib/screenplay/models/ProtractorModalDialogHandler.js +74 -0
  92. package/lib/screenplay/models/ProtractorModalDialogHandler.js.map +1 -0
  93. package/lib/screenplay/models/ProtractorPage.d.ts +58 -6
  94. package/lib/screenplay/models/ProtractorPage.d.ts.map +1 -0
  95. package/lib/screenplay/models/ProtractorPage.js +221 -44
  96. package/lib/screenplay/models/ProtractorPage.js.map +1 -1
  97. package/lib/screenplay/models/ProtractorPageElement.d.ts +10 -1
  98. package/lib/screenplay/models/ProtractorPageElement.d.ts.map +1 -0
  99. package/lib/screenplay/models/ProtractorPageElement.js +141 -147
  100. package/lib/screenplay/models/ProtractorPageElement.js.map +1 -1
  101. package/lib/screenplay/models/index.d.ts +2 -1
  102. package/lib/screenplay/models/index.d.ts.map +1 -0
  103. package/lib/screenplay/models/index.js +6 -2
  104. package/lib/screenplay/models/index.js.map +1 -1
  105. package/lib/screenplay/models/locators/ProtractorLocator.d.ts +21 -8
  106. package/lib/screenplay/models/locators/ProtractorLocator.d.ts.map +1 -0
  107. package/lib/screenplay/models/locators/ProtractorLocator.js +107 -10
  108. package/lib/screenplay/models/locators/ProtractorLocator.js.map +1 -1
  109. package/lib/screenplay/models/locators/ProtractorRootLocator.d.ts +17 -0
  110. package/lib/screenplay/models/locators/ProtractorRootLocator.d.ts.map +1 -0
  111. package/lib/screenplay/models/locators/ProtractorRootLocator.js +38 -0
  112. package/lib/screenplay/models/locators/ProtractorRootLocator.js.map +1 -0
  113. package/lib/screenplay/models/locators/index.d.ts +2 -1
  114. package/lib/screenplay/models/locators/index.d.ts.map +1 -0
  115. package/lib/screenplay/models/locators/index.js +6 -2
  116. package/lib/screenplay/models/locators/index.js.map +1 -1
  117. package/lib/screenplay/promised.d.ts +3 -3
  118. package/lib/screenplay/promised.d.ts.map +1 -0
  119. package/lib/screenplay/promised.js +2 -3
  120. package/lib/screenplay/promised.js.map +1 -1
  121. package/lib/screenplay/questions/ProtractorParam.d.ts +64 -51
  122. package/lib/screenplay/questions/ProtractorParam.d.ts.map +1 -0
  123. package/lib/screenplay/questions/ProtractorParam.js +59 -47
  124. package/lib/screenplay/questions/ProtractorParam.js.map +1 -1
  125. package/lib/screenplay/questions/index.d.ts +1 -0
  126. package/lib/screenplay/questions/index.d.ts.map +1 -0
  127. package/lib/screenplay/questions/index.js +5 -1
  128. package/lib/screenplay/questions/index.js.map +1 -1
  129. package/lib/screenplay/unpromisedWebElement.d.ts +6 -4
  130. package/lib/screenplay/unpromisedWebElement.d.ts.map +1 -0
  131. package/lib/screenplay/unpromisedWebElement.js +5 -4
  132. package/lib/screenplay/unpromisedWebElement.js.map +1 -1
  133. package/package.json +36 -60
  134. package/src/adapter/Config.ts +10 -9
  135. package/src/adapter/ProtractorFrameworkAdapter.ts +16 -10
  136. package/src/adapter/browser-detector/BrowserDetector.ts +3 -3
  137. package/src/adapter/browser-detector/StandardisedCapabilities.ts +24 -24
  138. package/src/adapter/index.ts +1 -0
  139. package/src/adapter/reporter/ProtractorReport.ts +4 -6
  140. package/src/adapter/reporter/ProtractorReporter.ts +16 -16
  141. package/src/adapter/run.ts +6 -4
  142. package/src/adapter/runner/CucumberAdapterConfig.ts +5 -10
  143. package/src/adapter/runner/TestRunnerDetector.ts +5 -13
  144. package/src/adapter/runner/TestRunnerLoader.ts +21 -19
  145. package/src/screenplay/abilities/BrowseTheWebWithProtractor.ts +63 -480
  146. package/src/screenplay/interactions/UseAngular.ts +55 -44
  147. package/src/screenplay/models/ProtractorBrowsingSession.ts +133 -0
  148. package/src/screenplay/models/ProtractorCookie.ts +8 -3
  149. package/src/screenplay/models/ProtractorErrorHandler.ts +23 -0
  150. package/src/screenplay/models/ProtractorModalDialogHandler.ts +97 -0
  151. package/src/screenplay/models/ProtractorPage.ts +282 -54
  152. package/src/screenplay/models/ProtractorPageElement.ts +160 -165
  153. package/src/screenplay/models/index.ts +1 -1
  154. package/src/screenplay/models/locators/ProtractorLocator.ts +121 -31
  155. package/src/screenplay/models/locators/ProtractorRootLocator.ts +41 -0
  156. package/src/screenplay/models/locators/index.ts +1 -1
  157. package/src/screenplay/promised.ts +2 -3
  158. package/src/screenplay/questions/ProtractorParam.ts +62 -49
  159. package/src/screenplay/unpromisedWebElement.ts +5 -4
  160. package/tsconfig.build.json +14 -0
  161. package/lib/screenplay/models/ProtractorModalDialog.d.ts +0 -11
  162. package/lib/screenplay/models/ProtractorModalDialog.js +0 -43
  163. package/lib/screenplay/models/ProtractorModalDialog.js.map +0 -1
  164. package/lib/screenplay/models/locators/ProtractorNativeElementRoot.d.ts +0 -5
  165. package/lib/screenplay/models/locators/ProtractorNativeElementRoot.js +0 -3
  166. package/lib/screenplay/models/locators/ProtractorNativeElementRoot.js.map +0 -1
  167. package/src/screenplay/models/ProtractorModalDialog.ts +0 -49
  168. package/src/screenplay/models/locators/ProtractorNativeElementRoot.ts +0 -6
  169. package/tsconfig.eslint.json +0 -10
@@ -1,77 +1,65 @@
1
- import { ConfigurationError, Duration, LogicError } from '@serenity-js/core';
2
- import { BrowserCapabilities, BrowseTheWeb, ByCss, ByCssContainingText, ById, ByTagName, ByXPath, Cookie, CookieData, Key, ModalDialog, Page, PageElement } from '@serenity-js/web';
3
- import { by, ElementFinder, ProtractorBrowser, WebElementPromise } from 'protractor';
4
- import { Capabilities } from 'selenium-webdriver';
1
+ import { ConfigurationError } from '@serenity-js/core';
2
+ import { BrowserCapabilities, BrowseTheWeb } from '@serenity-js/web';
3
+ import * as protractor from 'protractor';
5
4
 
6
- import { ProtractorCookie, ProtractorModalDialog, ProtractorPage, ProtractorPageElement } from '../models';
7
- import { ProtractorLocator, ProtractorNativeElementRoot } from '../models/locators';
5
+ import { ProtractorBrowsingSession } from '../models';
8
6
  import { promised } from '../promised';
9
7
 
10
8
  /**
11
- * @desc
12
- * An {@link @serenity-js/core/lib/screenplay~Ability} that enables the {@link Actor} to interact with web front-ends using {@link protractor}.
9
+ * This implementation of the {@apilink Ability|ability} to {@apilink BrowseTheWeb}
10
+ * enables the {@apilink Actor} to interact with web front-ends using [Protractor](http://www.protractortest.org/#/).
13
11
  *
14
- * @example <caption>Using the protractor.browser</caption>
15
- * import { Actor } from '@serenity-js/core';
16
- * import { BrowseTheWeb, Navigate, Target } from '@serenity-js/protractor'
17
- * import { Ensure, equals } from '@serenity-js/assertions';
18
- * import { by, protractor } from 'protractor';
12
+ * ## Using Protractor to `BrowseTheWeb`
19
13
  *
20
- * const actor = Actor.named('Wendy').whoCan(
21
- * BrowseTheWeb.using(protractor.browser),
22
- * );
14
+ * ```ts
15
+ * import { actorCalled } from '@serenity-js/core'
16
+ * import { BrowseTheWebWithProtractor } from '@serenity-js/protractor
17
+ * import { By, Navigate, PageElement, Text } from '@serenity-js/web'
18
+ * import { Ensure, equals } from '@serenity-js/assertions'
19
+ * import { protractor } from 'protractor'
23
20
  *
24
- * const HomePage = {
25
- * Title: Target.the('title').located(by.css('h1')),
26
- * };
21
+ * const HomePage = {
22
+ * title: () =>
23
+ * PageElement.located(By.css('h1')).describedAs('title')
24
+ * }
27
25
  *
28
- * actor.attemptsTo(
26
+ * await actorCalled('Wendy')
27
+ * .whoCan(BrowseTheWebWithProtractor.using(protractor.browser))
28
+ * .attemptsTo(
29
29
  * Navigate.to(`https://serenity-js.org`),
30
- * Ensure.that(Text.of(HomePage.Title), equals('Serenity/JS')),
31
- * );
30
+ * Ensure.that(Text.of(HomePage.title()), equals('Serenity/JS')),
31
+ * )
32
+ * ```
32
33
  *
33
- * @see https://www.protractortest.org/
34
+ * ## Learn more
35
+ * - [Protractor website](https://www.protractortest.org/)
36
+ * - {@apilink BrowseTheWeb}
37
+ * - {@apilink Ability}
38
+ * - {@apilink Actor}
34
39
  *
35
- * @public
36
- * @implements {@serenity-js/core/lib/screenplay~Ability}
37
- * @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
40
+ * @group Abilities
38
41
  */
39
- export class BrowseTheWebWithProtractor extends BrowseTheWeb<ElementFinder, ProtractorNativeElementRoot> {
42
+ export class BrowseTheWebWithProtractor extends BrowseTheWeb<protractor.ElementFinder> {
40
43
 
41
44
  /**
42
- * @desc
43
- * Ability to interact with web front-ends using a given protractor browser instance.
45
+ * Ability to interact with web front-ends using
46
+ * provided protractor browser instance.
44
47
  *
45
- * @param {ProtractorBrowser} browser
46
- * @returns {BrowseTheWebWithProtractor}
48
+ * @param {protractor~ProtractorBrowser} browser
49
+ *
50
+ * #### Learn more
51
+ * - [Protractor Browser API docs](http://www.protractortest.org/#/api?view=ProtractorBrowser)
47
52
  */
48
- static using(browser: ProtractorBrowser): BrowseTheWebWithProtractor {
53
+ static using(browser: protractor.ProtractorBrowser): BrowseTheWebWithProtractor {
49
54
  return new BrowseTheWebWithProtractor(browser);
50
55
  }
51
56
 
52
57
  /**
53
- * @private
54
- */
55
- private lastScriptExecutionSummary: LastScriptExecutionSummary;
56
-
57
- /**
58
- * @param {ProtractorBrowser} browser
58
+ * @param browser
59
59
  * An instance of a protractor browser
60
60
  */
61
- constructor(protected browser: ProtractorBrowser) {
62
- super(new Map()
63
- .set(ByCss, (selector: ByCss) =>
64
- // todo: this is a temporary experiment; target state is for all CSS selectors to support Shadow DOM by default
65
- ProtractorLocator.createRootLocator(this.browser, selector,
66
- selector.value.startsWith('>>>') && !! by.shadowDomCss
67
- ? by.shadowDomCss(selector.value.replace('>>>', ''))
68
- : by.css(selector.value))
69
- )
70
- .set(ByCssContainingText, (selector: ByCssContainingText) => ProtractorLocator.createRootLocator(this.browser, selector, by.cssContainingText(selector.value, selector.text)))
71
- .set(ById, (selector: ById) => ProtractorLocator.createRootLocator(this.browser, selector, by.id(selector.value)))
72
- .set(ByTagName, (selector: ByTagName) => ProtractorLocator.createRootLocator(this.browser, selector, by.tagName(selector.value)))
73
- .set(ByXPath, (selector: ByXPath) => ProtractorLocator.createRootLocator(this.browser, selector, by.xpath(selector.value)))
74
- );
61
+ constructor(protected browser: protractor.ProtractorBrowser) {
62
+ super(new ProtractorBrowsingSession(browser));
75
63
  }
76
64
 
77
65
  async browserCapabilities(): Promise<BrowserCapabilities> {
@@ -84,437 +72,39 @@ export class BrowseTheWebWithProtractor extends BrowseTheWeb<ElementFinder, Prot
84
72
  };
85
73
  }
86
74
 
87
- async cookie(name: string): Promise<Cookie> {
88
- return new ProtractorCookie(this.browser, name);
89
- }
90
-
91
- async setCookie(cookieData: CookieData): Promise<void> {
92
- return promised(this.browser.manage().addCookie({
93
- name: cookieData.name,
94
- value: cookieData.value,
95
- path: cookieData.path,
96
- domain: cookieData.domain,
97
- secure: cookieData.secure,
98
- httpOnly: cookieData.httpOnly,
99
- expiry: cookieData.expiry
100
- ? cookieData.expiry.toSeconds()
101
- : undefined,
102
- }));
103
- }
104
-
105
- deleteAllCookies(): Promise<void> {
106
- return promised(this.browser.manage().deleteAllCookies());
107
- }
108
-
109
- navigateTo(destination: string): Promise<void> {
110
- return promised(this.browser.get(destination));
111
- }
112
-
113
- navigateBack(): Promise<void> {
114
- return promised(this.browser.navigate().back());
115
- }
116
-
117
- navigateForward(): Promise<void> {
118
- return promised(this.browser.navigate().forward());
119
- }
120
-
121
- reloadPage(): Promise<void> {
122
- return promised(this.browser.navigate().refresh());
123
- }
124
-
125
- waitFor(duration: Duration): Promise<void> {
126
- return promised(this.browser.sleep(duration.inMilliseconds()));
127
- }
128
-
129
- waitUntil(condition: () => boolean | Promise<boolean>, timeout: Duration): Promise<void> {
130
- return promised(this.browser.wait(condition, timeout.inMilliseconds())) as unknown as Promise<void>;
131
- }
132
-
133
- async sendKeys(keys: (string | Key)[]): Promise<void> {
134
- function isModifier(maybeKey: string | Key): boolean {
135
- return Key.isKey(maybeKey) && maybeKey.isModifier;
136
- }
137
-
138
- function asCodePoint(maybeKey: string | Key): string {
139
- if (! Key.isKey(maybeKey)) {
140
- return maybeKey;
141
- }
142
-
143
- return maybeKey.utf16codePoint;
144
- }
145
-
146
- // keyDown for any modifier keys and sendKeys otherwise
147
- const keyDownActions = keys.reduce((actions, key) => {
148
- return isModifier(key)
149
- ? actions.keyDown(asCodePoint(key))
150
- : actions.sendKeys(asCodePoint(key))
151
- }, this.browser.actions());
152
-
153
- // keyUp for any modifier keys, ignore for regular keys
154
- const keyUpActions = keys.reduce((actions, key) => {
155
- return isModifier(key)
156
- ? actions.keyUp(asCodePoint(key))
157
- : actions;
158
- }, keyDownActions);
159
-
160
- return promised(keyUpActions.perform());
161
- }
162
-
163
- async modalDialog(): Promise<ModalDialog> {
164
- return new ProtractorModalDialog(this.browser);
165
- }
166
-
167
75
  /**
168
- * @desc
169
- * Navigate to the given destination and loads mock modules before Angular.
170
- * Assumes that the page being loaded uses Angular.
76
+ * Returns Protractor configuration parameter at `path`.
171
77
  *
172
- * @param {string} destination
173
- * @param {number?} timeoutInMillis
78
+ * #### Configuring a custom parameter
174
79
  *
175
- * @returns {Promise<void>}
176
- */
177
- get(destination: string, timeoutInMillis?: number): Promise<void> {
178
- return promised(this.browser.get(destination, timeoutInMillis));
179
- }
180
-
181
- /**
182
- * @desc
183
- * Switches the focus to a [`frame`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame) or
184
- * [`iframe`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) identified by `elementOrIndexOrName`,
185
- * which can be specified either as {@link selenium-webdriver~WebElement}, the name of the frame, or its index.
186
- *
187
- * @param {number | string | WebElement} elementOrIndexOrName
188
- *
189
- * @returns {Promise<void>}
190
- */
191
- async switchToFrame(elementOrIndexOrName: number | string | PageElement): Promise<void> {
192
- if (elementOrIndexOrName instanceof ProtractorPageElement) {
193
- const nativeElement = await elementOrIndexOrName.nativeElement();
194
- const webElement = await nativeElement.getWebElement() as unknown as WebElementPromise // https://github.com/angular/protractor/issues/1846#issuecomment-82634739;
195
-
196
- return this.browser.switchTo().frame(webElement);
197
- }
198
-
199
- // incorrect type definition in selenium-webdriver prevents us from providing a string argument
200
- return this.browser.switchTo().frame(elementOrIndexOrName as any);
201
- }
202
-
203
- /**
204
- * @desc
205
- * Switches the focus from any [`frame`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame) or
206
- * [`iframe`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) back to its parent iframe.
207
- *
208
- * @returns {Promise<void>}
209
- */
210
- switchToParentFrame(): Promise<void> {
211
- return promised(this.browser.driver.switchToParentFrame());
212
- }
213
-
214
- /**
215
- * @desc
216
- * Switches the focus from any [`frame`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame)
217
- * or [`iframe`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) back to default content,
218
- * a.k.a. "the main window".
219
- *
220
- * @returns {Promise<void>}
221
- */
222
- switchToDefaultContent(): Promise<void> {
223
- return promised(this.browser.switchTo().defaultContent());
224
- }
225
-
226
- /**
227
- * @desc
228
- * Returns a {@link Page} representing the currently active top-level browsing context.
229
- *
230
- * @returns {Promise<Page>}
231
- */
232
- async currentPage(): Promise<Page> {
233
-
234
- const windowHandle = await this.browser.getWindowHandle();
235
-
236
- return new ProtractorPage(this.browser, windowHandle);
237
- }
238
-
239
- /**
240
- * @desc
241
- * Returns an array of {@link Page} objects representing all the available
242
- * top-level browsing context, e.g. all the open browser tabs.
243
- *
244
- * @returns {Promise<Array<Page>>}
245
- */
246
- async allPages(): Promise<Array<Page>> {
247
- const windowHandles = await this.browser.getAllWindowHandles();
248
-
249
- return windowHandles.map(windowHandle => new ProtractorPage(this.browser, windowHandle));
250
- }
251
-
252
- /**
253
- * @desc
254
- * If set to false, Protractor will not wait for Angular $http and $timeout
255
- * tasks to complete before interacting with the browser.
256
- *
257
- * This can be useful when:
258
- * - you need to switch to a non-Angular app during your tests (i.e. SSO login gateway)
259
- * - your app continuously polls an API with $timeout
260
- *
261
- * If you're not testing an Angular app, it's better to disable Angular synchronisation completely
262
- * in protractor configuration:
263
- *
264
- * @example <caption>protractor.conf.js</caption>
80
+ * ```js
81
+ * // protractor.conf.js
265
82
  * exports.config = {
266
- * onPrepare: function () {
267
- * return browser.waitForAngularEnabled(false);
268
- * },
269
- *
270
- * // ... other config
271
- * };
272
- *
273
- * @param {boolean} enable
274
- *
275
- * @returns {Promise<boolean>}
276
- */
277
- enableAngularSynchronisation(enable: boolean): Promise<boolean> {
278
- return promised(this.browser.waitForAngularEnabled(enable));
279
- }
280
-
281
- /**
282
- * @desc
283
- * Schedules a command to execute JavaScript in the context of the currently selected frame or window.
284
- * The script fragment will be executed as the body of an anonymous function.
285
- * If the script is provided as a function object, that function will be converted to a string for injection
286
- * into the target window.
287
- *
288
- * Any arguments provided in addition to the script will be included as script arguments and may be referenced
289
- * using the `arguments` object. Arguments may be a `boolean`, `number`, `string` or `WebElement`.
290
- * Arrays and objects may also be used as script arguments as long as each item adheres
291
- * to the types previously mentioned.
292
- *
293
- * The script may refer to any variables accessible from the current window.
294
- * Furthermore, the script will execute in the window's context, thus `document` may be used to refer
295
- * to the current document. Any local variables will not be available once the script has finished executing,
296
- * though global variables will persist.
297
- *
298
- * If the script has a return value (i.e. if the script contains a `return` statement),
299
- * then the following steps will be taken for resolving this functions return value:
300
- *
301
- * For a HTML element, the value will resolve to a WebElement
302
- * - Null and undefined return values will resolve to null
303
- * - Booleans, numbers, and strings will resolve as is
304
- * - Functions will resolve to their string representation
305
- * - For arrays and objects, each member item will be converted according to the rules above
306
- *
307
- * @example <caption>Perform a sleep in the browser under test</caption>
308
- * BrowseTheWeb.as(actor).executeAsyncScript(`
309
- * return arguments[0].tagName;
310
- * `, Target.the('header').located(by.css(h1))
311
- *
312
- * @see https://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.executeScript
313
- * @see https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html#executeScript-java.lang.String-java.lang.Object...-
314
- *
315
- * @param {string | Function} script
316
- * @param {any[]} args
317
- *
318
- * @returns {Promise<any>}
319
- *
320
- * @see {@link BrowseTheWeb#getLastScriptExecutionResult}
321
- */
322
- async executeScript<Result, InnerArguments extends any[]>(
323
- script: string | ((...parameters: InnerArguments) => Result),
324
- ...args: InnerArguments
325
- ): Promise<Result> {
326
- const nativeArguments = await Promise.all(args.map(arg => arg instanceof ProtractorPageElement ? arg.nativeElement() : arg)) as InnerArguments;
327
-
328
- return promised(this.browser.executeScript(script, ...nativeArguments))
329
- .then(result => {
330
- this.lastScriptExecutionSummary = new LastScriptExecutionSummary(
331
- result,
332
- );
333
- return result;
334
- }) as Promise<Result>;
335
- }
336
-
337
- /**
338
- * @desc
339
- * A simplified version of {@link BrowseTheWebWithProtractor#executeScript} that doesn't affect {@link LastScriptExecution.result()}.
340
- *
341
- * @param {Function} fn
342
- * @param {Parameters<fn>} args
343
- *
344
- * @returns {Promise<ReturnType<fn>>}
345
- */
346
- async executeFunction<F extends (...args: any[]) => any>(fn: F, ...args: Parameters<F>): Promise<ReturnType<F>> {
347
- const nativeArguments = await Promise.all(args.map(arg => arg instanceof ProtractorPageElement ? arg.nativeElement() : arg)) as Parameters<F>;
348
-
349
- return promised(this.browser.executeScriptWithDescription(fn, fn.name, ...nativeArguments));
350
- }
351
-
352
- /**
353
- * @desc
354
- * Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window.
355
- * The script fragment will be executed as the body of an anonymous function.
356
- * If the script is provided as a function object, that function will be converted to a string for injection
357
- * into the target window.
358
- *
359
- * Any arguments provided in addition to the script will be included as script arguments and may be referenced
360
- * using the `arguments` object. Arguments may be a `boolean`, `number`, `string` or `WebElement`
361
- * Arrays and objects may also be used as script arguments as long as each item adheres
362
- * to the types previously mentioned.
363
- *
364
- * Unlike executing synchronous JavaScript with {@link BrowseTheWebWithProtractor#executeScript},
365
- * scripts executed with this function must explicitly signal they are finished by invoking the provided callback.
366
- *
367
- * This callback will always be injected into the executed function as the last argument,
368
- * and thus may be referenced with `arguments[arguments.length - 1]`.
369
- *
370
- * The following steps will be taken for resolving this functions return value against
371
- * the first argument to the script's callback function:
372
- *
373
- * - For a HTML element, the value will resolve to a WebElement
374
- * - Null and undefined return values will resolve to null
375
- * - Booleans, numbers, and strings will resolve as is
376
- * - Functions will resolve to their string representation
377
- * - For arrays and objects, each member item will be converted according to the rules above
378
- *
379
- * @example <caption>Perform a sleep in the browser under test</caption>
380
- * BrowseTheWeb.as(actor).executeAsyncScript(`
381
- * var delay = arguments[0];
382
- * var callback = arguments[arguments.length - 1];
383
- *
384
- * window.setTimeout(callback, delay);
385
- * `, 500)
386
- *
387
- * @example <caption>Return a value asynchronously</caption>
388
- * BrowseTheWeb.as(actor).executeAsyncScript(`
389
- * var callback = arguments[arguments.length - 1];
390
- *
391
- * callback('some return value')
392
- * `).then(value => doSomethingWithThe(value))
393
- *
394
- * @see https://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.executeAsyncScript
395
- * @see https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html#executeAsyncScript-java.lang.String-java.lang.Object...-
396
- *
397
- * @param {string|Function} script
398
- * @param {any[]} args
399
- *
400
- * @returns {Promise<any>}
401
- *
402
- * @see {@link BrowseTheWeb#getLastScriptExecutionResult}
403
- */
404
- async executeAsyncScript<Result, Parameters extends any[]>(
405
- script: string | ((...args: [...parameters: Parameters, callback: (result: Result) => void]) => void),
406
- ...args: Parameters
407
- ): Promise<Result> {
408
- const nativeArguments = await Promise.all(args.map(arg => arg instanceof ProtractorPageElement ? arg.nativeElement() : arg)) as Parameters;
409
-
410
- return promised(this.browser.executeAsyncScript(script, ...nativeArguments))
411
- .then(result => {
412
- this.lastScriptExecutionSummary = new LastScriptExecutionSummary(
413
- result,
414
- );
415
- return result;
416
- }) as Promise<Result>;
417
- }
418
-
419
- /**
420
- * @desc
421
- * Schedule a command to take a screenshot. The driver makes a best effort to
422
- * return a base64-encoded screenshot of the following, in order of preference:
423
- *
424
- * 1. Entire page
425
- * 2. Current window
426
- * 3. Visible portion of the current frame
427
- * 4. The entire display containing the browser
428
- *
429
- * @return {Promise<string>} A promise that will be resolved to a base64-encoded screenshot PNG
430
- */
431
- takeScreenshot(): Promise<string> {
432
- return promised(this.browser.takeScreenshot());
433
- }
434
-
435
- /**
436
- * @desc
437
- * Returns the capabilities of the browser used in the current session.
438
- *
439
- * By default, the session `capabilities` specified in the `protractor.conf.js`
440
- * indicate the _desired_ properties of the remote browser. However, if the remote cannot satisfy
441
- * all the requirements, it will still create a session.
442
- *
443
- * @returns {Promise<Capabilities>} The actual capabilities of this browser.
444
- */
445
- capabilities(): Promise<Capabilities> {
446
- return promised(this.browser.getCapabilities());
447
- }
448
-
449
- /**
450
- * @desc
451
- * Pause the actor flow for a specified number of milliseconds.
452
- *
453
- * @param {number} millis
454
- * @returns {Promise<void>}
455
- */
456
- sleep(millis: number): Promise<void> {
457
- return promised(this.browser.sleep(millis));
458
- }
459
-
460
- /**
461
- * @desc
462
- * Pause the actor flow until the condition is met or the timeout expires.
463
- *
464
- * @param {function(): Promise<boolean>} condition
465
- * @param {number} timeoutInMillis
466
- * @returns {Promise<boolean>}
467
- */
468
- wait(condition: () => Promise<boolean>, timeoutInMillis: number): Promise<boolean> {
469
- return promised(this.browser.wait(condition, timeoutInMillis));
470
- }
471
-
472
- /**
473
- * @desc
474
- * Returns the last result of calling {@link BrowseTheWebWithProtractor#executeAsyncScript}
475
- * or {@link BrowseTheWebWithProtractor#executeScript}
476
- *
477
- * @returns {any}
478
- */
479
- lastScriptExecutionResult(): any {
480
- if (! this.lastScriptExecutionSummary) {
481
- throw new LogicError(`Make sure to execute a script before checking on the result`);
482
- }
483
-
484
- // Selenium 3 returns `null` when the script it executed returns `undefined`
485
- // so we're mapping the result back.
486
- return this.lastScriptExecutionSummary.result !== null
487
- ? this.lastScriptExecutionSummary.result
488
- : undefined;
489
- }
490
-
491
- /**
492
- * @desc
493
- * Returns Protractor configuration parameter at `path`.
494
- *
495
- * @example <caption>protractor.conf.js</caption>
496
- * exports.config = {
497
- * params: {
498
- * login: {
499
- * username: 'jane@example.org'
500
- * password: process.env.PASSWORD
501
- * }
502
- * }
503
- * // ...
83
+ * params: {
84
+ * login: {
85
+ * username: 'jane@example.org'
86
+ * password: process.env.PASSWORD
87
+ * }
88
+ * }
89
+ * // ...
504
90
  * }
91
+ * ```
505
92
  *
506
- * @example <caption>Retrieving config param by name</caption>
507
- * BrowseTheWeb.as(actor).param('login') // returns object with username and password
93
+ * #### Retrieving config param by name
94
+ * ```js
95
+ * BrowseTheWebWithProtractor.as(actor).param('login')
96
+ * // returns object with username and password
97
+ * ```
508
98
  *
509
- * @example <caption>Retrieving config param by path</caption>
510
- * BrowseTheWeb.as(actor).param('login.username') // returns string 'jane@example.org'
99
+ * #### Retrieving config param by path
100
+ * ```js
101
+ * BrowseTheWeb.as(actor).param('login.username')
102
+ * // returns string 'jane@example.org'
511
103
  *
512
- * @param {string} path
104
+ * @param path
513
105
  * Either a name or a dot-delimited path to the param.
514
106
  *
515
- * @returns {T}
516
- *
517
- * @throws {@serenity-js/core/lib/errors~ConfigurationError}
107
+ * @throws {@apilink ConfigurationError}
518
108
  * Throws a `ConfigurationError` if the parameter is `undefined`
519
109
  */
520
110
  param<T = any>(path: string): T {
@@ -528,10 +118,3 @@ export class BrowseTheWebWithProtractor extends BrowseTheWeb<ElementFinder, Prot
528
118
  }, this.browser.params);
529
119
  }
530
120
  }
531
-
532
- /**
533
- * @package
534
- */
535
- class LastScriptExecutionSummary {
536
- constructor(public readonly result: any) {}
537
- }