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