codeceptjs 3.5.10 → 3.5.12-beta.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 (225) hide show
  1. package/README.md +3 -3
  2. package/lib/command/run-multiple.js +3 -1
  3. package/lib/command/run-workers.js +32 -1
  4. package/lib/command/workers/runTests.js +18 -2
  5. package/lib/helper/Expect.js +33 -33
  6. package/lib/helper/Playwright.js +49 -26
  7. package/lib/helper/Puppeteer.js +41 -19
  8. package/lib/helper/WebDriver.js +155 -48
  9. package/lib/helper/extras/PlaywrightReactVueLocator.js +38 -0
  10. package/lib/locator.js +17 -4
  11. package/lib/plugin/retryFailedStep.js +6 -2
  12. package/lib/plugin/retryTo.js +2 -2
  13. package/lib/plugin/tryTo.js +5 -4
  14. package/package.json +25 -22
  15. package/typings/index.d.ts +8 -5
  16. package/typings/promiseBasedTypes.d.ts +203 -75
  17. package/typings/types.d.ts +213 -145
  18. package/docs/advanced.md +0 -351
  19. package/docs/ai.md +0 -248
  20. package/docs/api.md +0 -323
  21. package/docs/basics.md +0 -979
  22. package/docs/bdd.md +0 -539
  23. package/docs/best.md +0 -237
  24. package/docs/books.md +0 -37
  25. package/docs/bootstrap.md +0 -135
  26. package/docs/build/ApiDataFactory.js +0 -410
  27. package/docs/build/Appium.js +0 -2027
  28. package/docs/build/Expect.js +0 -422
  29. package/docs/build/FileSystem.js +0 -228
  30. package/docs/build/GraphQL.js +0 -229
  31. package/docs/build/GraphQLDataFactory.js +0 -309
  32. package/docs/build/JSONResponse.js +0 -338
  33. package/docs/build/Mochawesome.js +0 -71
  34. package/docs/build/Nightmare.js +0 -2152
  35. package/docs/build/OpenAI.js +0 -126
  36. package/docs/build/Playwright.js +0 -5078
  37. package/docs/build/Protractor.js +0 -2706
  38. package/docs/build/Puppeteer.js +0 -3874
  39. package/docs/build/REST.js +0 -344
  40. package/docs/build/TestCafe.js +0 -2125
  41. package/docs/build/WebDriver.js +0 -4124
  42. package/docs/changelog.md +0 -2572
  43. package/docs/commands.md +0 -266
  44. package/docs/community-helpers.md +0 -58
  45. package/docs/configuration.md +0 -157
  46. package/docs/continuous-integration.md +0 -22
  47. package/docs/custom-helpers.md +0 -306
  48. package/docs/data.md +0 -379
  49. package/docs/detox.md +0 -235
  50. package/docs/docker.md +0 -136
  51. package/docs/email.md +0 -183
  52. package/docs/examples.md +0 -149
  53. package/docs/helpers/ApiDataFactory.md +0 -266
  54. package/docs/helpers/Appium.md +0 -1374
  55. package/docs/helpers/Detox.md +0 -586
  56. package/docs/helpers/Expect.md +0 -275
  57. package/docs/helpers/FileSystem.md +0 -152
  58. package/docs/helpers/GraphQL.md +0 -151
  59. package/docs/helpers/GraphQLDataFactory.md +0 -226
  60. package/docs/helpers/JSONResponse.md +0 -254
  61. package/docs/helpers/Mochawesome.md +0 -8
  62. package/docs/helpers/MockRequest.md +0 -377
  63. package/docs/helpers/Nightmare.md +0 -1305
  64. package/docs/helpers/OpenAI.md +0 -70
  65. package/docs/helpers/Playwright.md +0 -2706
  66. package/docs/helpers/Polly.md +0 -44
  67. package/docs/helpers/Protractor.md +0 -1769
  68. package/docs/helpers/Puppeteer-firefox.md +0 -86
  69. package/docs/helpers/Puppeteer.md +0 -2291
  70. package/docs/helpers/REST.md +0 -218
  71. package/docs/helpers/TestCafe.md +0 -1321
  72. package/docs/helpers/WebDriver.md +0 -2460
  73. package/docs/hooks.md +0 -340
  74. package/docs/index.md +0 -111
  75. package/docs/installation.md +0 -75
  76. package/docs/internal-api.md +0 -266
  77. package/docs/locators.md +0 -331
  78. package/docs/mobile-react-native-locators.md +0 -67
  79. package/docs/mobile.md +0 -338
  80. package/docs/pageobjects.md +0 -291
  81. package/docs/parallel.md +0 -400
  82. package/docs/playwright.md +0 -632
  83. package/docs/plugins.md +0 -1259
  84. package/docs/puppeteer.md +0 -316
  85. package/docs/quickstart.md +0 -162
  86. package/docs/react.md +0 -69
  87. package/docs/reports.md +0 -392
  88. package/docs/secrets.md +0 -36
  89. package/docs/shadow.md +0 -68
  90. package/docs/shared/keys.mustache +0 -31
  91. package/docs/shared/react.mustache +0 -1
  92. package/docs/testcafe.md +0 -174
  93. package/docs/translation.md +0 -247
  94. package/docs/tutorial.md +0 -271
  95. package/docs/typescript.md +0 -180
  96. package/docs/ui.md +0 -59
  97. package/docs/videos.md +0 -28
  98. package/docs/visual.md +0 -202
  99. package/docs/vue.md +0 -121
  100. package/docs/webapi/amOnPage.mustache +0 -11
  101. package/docs/webapi/appendField.mustache +0 -11
  102. package/docs/webapi/attachFile.mustache +0 -12
  103. package/docs/webapi/blur.mustache +0 -18
  104. package/docs/webapi/checkOption.mustache +0 -13
  105. package/docs/webapi/clearCookie.mustache +0 -9
  106. package/docs/webapi/clearField.mustache +0 -9
  107. package/docs/webapi/click.mustache +0 -25
  108. package/docs/webapi/clickLink.mustache +0 -8
  109. package/docs/webapi/closeCurrentTab.mustache +0 -7
  110. package/docs/webapi/closeOtherTabs.mustache +0 -8
  111. package/docs/webapi/dontSee.mustache +0 -11
  112. package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
  113. package/docs/webapi/dontSeeCookie.mustache +0 -8
  114. package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
  115. package/docs/webapi/dontSeeElement.mustache +0 -8
  116. package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
  117. package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
  118. package/docs/webapi/dontSeeInField.mustache +0 -11
  119. package/docs/webapi/dontSeeInSource.mustache +0 -8
  120. package/docs/webapi/dontSeeInTitle.mustache +0 -8
  121. package/docs/webapi/doubleClick.mustache +0 -13
  122. package/docs/webapi/downloadFile.mustache +0 -12
  123. package/docs/webapi/dragAndDrop.mustache +0 -9
  124. package/docs/webapi/dragSlider.mustache +0 -11
  125. package/docs/webapi/executeAsyncScript.mustache +0 -24
  126. package/docs/webapi/executeScript.mustache +0 -26
  127. package/docs/webapi/fillField.mustache +0 -16
  128. package/docs/webapi/focus.mustache +0 -13
  129. package/docs/webapi/forceClick.mustache +0 -28
  130. package/docs/webapi/forceRightClick.mustache +0 -18
  131. package/docs/webapi/grabAllWindowHandles.mustache +0 -7
  132. package/docs/webapi/grabAttributeFrom.mustache +0 -10
  133. package/docs/webapi/grabAttributeFromAll.mustache +0 -9
  134. package/docs/webapi/grabBrowserLogs.mustache +0 -9
  135. package/docs/webapi/grabCookie.mustache +0 -11
  136. package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
  137. package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
  138. package/docs/webapi/grabCurrentUrl.mustache +0 -9
  139. package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
  140. package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
  141. package/docs/webapi/grabElementBoundingRect.mustache +0 -20
  142. package/docs/webapi/grabGeoLocation.mustache +0 -8
  143. package/docs/webapi/grabHTMLFrom.mustache +0 -10
  144. package/docs/webapi/grabHTMLFromAll.mustache +0 -9
  145. package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
  146. package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
  147. package/docs/webapi/grabPageScrollPosition.mustache +0 -8
  148. package/docs/webapi/grabPopupText.mustache +0 -5
  149. package/docs/webapi/grabSource.mustache +0 -8
  150. package/docs/webapi/grabTextFrom.mustache +0 -10
  151. package/docs/webapi/grabTextFromAll.mustache +0 -9
  152. package/docs/webapi/grabTitle.mustache +0 -8
  153. package/docs/webapi/grabValueFrom.mustache +0 -9
  154. package/docs/webapi/grabValueFromAll.mustache +0 -8
  155. package/docs/webapi/grabWebElement.mustache +0 -9
  156. package/docs/webapi/grabWebElements.mustache +0 -9
  157. package/docs/webapi/moveCursorTo.mustache +0 -12
  158. package/docs/webapi/openNewTab.mustache +0 -7
  159. package/docs/webapi/pressKey.mustache +0 -12
  160. package/docs/webapi/pressKeyDown.mustache +0 -12
  161. package/docs/webapi/pressKeyUp.mustache +0 -12
  162. package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
  163. package/docs/webapi/refreshPage.mustache +0 -6
  164. package/docs/webapi/resizeWindow.mustache +0 -6
  165. package/docs/webapi/rightClick.mustache +0 -14
  166. package/docs/webapi/saveElementScreenshot.mustache +0 -10
  167. package/docs/webapi/saveScreenshot.mustache +0 -12
  168. package/docs/webapi/say.mustache +0 -10
  169. package/docs/webapi/scrollIntoView.mustache +0 -11
  170. package/docs/webapi/scrollPageToBottom.mustache +0 -6
  171. package/docs/webapi/scrollPageToTop.mustache +0 -6
  172. package/docs/webapi/scrollTo.mustache +0 -12
  173. package/docs/webapi/see.mustache +0 -11
  174. package/docs/webapi/seeAttributesOnElements.mustache +0 -9
  175. package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
  176. package/docs/webapi/seeCookie.mustache +0 -8
  177. package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
  178. package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
  179. package/docs/webapi/seeElement.mustache +0 -8
  180. package/docs/webapi/seeElementInDOM.mustache +0 -8
  181. package/docs/webapi/seeInCurrentUrl.mustache +0 -8
  182. package/docs/webapi/seeInField.mustache +0 -12
  183. package/docs/webapi/seeInPopup.mustache +0 -8
  184. package/docs/webapi/seeInSource.mustache +0 -7
  185. package/docs/webapi/seeInTitle.mustache +0 -8
  186. package/docs/webapi/seeNumberOfElements.mustache +0 -11
  187. package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
  188. package/docs/webapi/seeTextEquals.mustache +0 -9
  189. package/docs/webapi/seeTitleEquals.mustache +0 -8
  190. package/docs/webapi/selectOption.mustache +0 -21
  191. package/docs/webapi/setCookie.mustache +0 -16
  192. package/docs/webapi/setGeoLocation.mustache +0 -12
  193. package/docs/webapi/switchTo.mustache +0 -9
  194. package/docs/webapi/switchToNextTab.mustache +0 -10
  195. package/docs/webapi/switchToPreviousTab.mustache +0 -10
  196. package/docs/webapi/type.mustache +0 -21
  197. package/docs/webapi/uncheckOption.mustache +0 -13
  198. package/docs/webapi/wait.mustache +0 -8
  199. package/docs/webapi/waitForClickable.mustache +0 -11
  200. package/docs/webapi/waitForDetached.mustache +0 -10
  201. package/docs/webapi/waitForElement.mustache +0 -11
  202. package/docs/webapi/waitForEnabled.mustache +0 -6
  203. package/docs/webapi/waitForFunction.mustache +0 -17
  204. package/docs/webapi/waitForInvisible.mustache +0 -10
  205. package/docs/webapi/waitForText.mustache +0 -13
  206. package/docs/webapi/waitForValue.mustache +0 -10
  207. package/docs/webapi/waitForVisible.mustache +0 -10
  208. package/docs/webapi/waitInUrl.mustache +0 -9
  209. package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
  210. package/docs/webapi/waitToHide.mustache +0 -10
  211. package/docs/webapi/waitUrlEquals.mustache +0 -10
  212. package/docs/webdriver.md +0 -655
  213. package/docs/wiki/Books-&-Posts.md +0 -27
  214. package/docs/wiki/Community-Helpers-&-Plugins.md +0 -53
  215. package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -61
  216. package/docs/wiki/Examples.md +0 -145
  217. package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
  218. package/docs/wiki/Home.md +0 -16
  219. package/docs/wiki/Migration-to-Appium-v2---CodeceptJS.md +0 -83
  220. package/docs/wiki/Release-Process.md +0 -24
  221. package/docs/wiki/Roadmap.md +0 -23
  222. package/docs/wiki/Tests.md +0 -1393
  223. package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
  224. package/docs/wiki/Videos.md +0 -19
  225. package/lib/helper/extras/PlaywrightReact.js +0 -9
@@ -1,2291 +0,0 @@
1
- ---
2
- permalink: /helpers/Puppeteer
3
- editLink: false
4
- sidebar: auto
5
- title: Puppeteer
6
- ---
7
-
8
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9
-
10
- ## Puppeteer
11
-
12
- **Extends Helper**
13
-
14
- Uses [Google Chrome's Puppeteer][1] library to run tests inside headless Chrome.
15
- Browser control is executed via DevTools Protocol (instead of Selenium).
16
- This helper works with a browser out of the box with no additional tools required to install.
17
-
18
- Requires `puppeteer` or `puppeteer-core` package to be installed.
19
-
20
- npm i puppeteer --save
21
-
22
- or
23
-
24
- npm i puppeteer-core --save
25
-
26
- Using `puppeteer-core` package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
27
-
28
- > Experimental Firefox support [can be activated][2].
29
-
30
-
31
-
32
- ## Configuration
33
-
34
- This helper should be configured in codecept.conf.js
35
-
36
- Type: [object][4]
37
-
38
- ### Properties
39
-
40
- - `url` **[string][6]** base url of website to be tested
41
- - `basicAuth` **[object][4]?** (optional) the basic authentication to pass to base url. Example: {username: 'username', password: 'password'}
42
- - `show` **[boolean][20]?** show Google Chrome window for debug.
43
- - `restart` **[boolean][20]?** restart browser between tests.
44
- - `disableScreenshots` **[boolean][20]?** don't save screenshot on failure.
45
- - `fullPageScreenshots` **[boolean][20]?** make full page screenshots on failure.
46
- - `uniqueScreenshotNames` **[boolean][20]?** option to prevent screenshot override if you have scenarios with the same name in different suites.
47
- - `trace` **[boolean][20]?** record [tracing information][25] with screenshots.
48
- - `keepTraceForPassedTests` **[boolean][20]?** save trace for passed tests.
49
- - `keepBrowserState` **[boolean][20]?** keep browser state between tests when `restart` is set to false.
50
- - `keepCookies` **[boolean][20]?** keep cookies between tests when `restart` is set to false.
51
- - `waitForAction` **[number][10]?** how long to wait after click, doubleClick or PressKey actions in ms. Default: 100.
52
- - `waitForNavigation` **[string][6]?** when to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. See [Puppeteer API][23]. Array values are accepted as well.
53
- - `pressKeyDelay` **[number][10]?** delay between key presses in ms. Used when calling Puppeteers page.type(...) in fillField/appendField
54
- - `getPageTimeout` **[number][10]?** config option to set maximum navigation time in milliseconds. If the timeout is set to 0, then timeout will be disabled.
55
- - `waitForTimeout` **[number][10]?** default wait* timeout in ms.
56
- - `windowSize` **[string][6]?** default window size. Set a dimension in format WIDTHxHEIGHT like `640x480`.
57
- - `userAgent` **[string][6]?** user-agent string.
58
- - `manualStart` **[boolean][20]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
59
- - `browser` **[string][6]?** can be changed to `firefox` when using [puppeteer-firefox][2].
60
- - `chrome` **[object][4]?** pass additional [Puppeteer run options][26].
61
- - `highlightElement` **[boolean][20]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
62
-
63
-
64
-
65
- #### Trace Recording Customization
66
-
67
- Trace recording provides complete information on test execution and includes screenshots, and network requests logged during run.
68
- Traces will be saved to `output/trace`
69
-
70
- - `trace`: enables trace recording for failed tests; trace are saved into `output/trace` folder
71
- - `keepTraceForPassedTests`: - save trace for passed tests
72
-
73
- #### Example #1: Wait for 0 network connections.
74
-
75
- ```js
76
- {
77
- helpers: {
78
- Puppeteer : {
79
- url: "http://localhost",
80
- restart: false,
81
- waitForNavigation: "networkidle0",
82
- waitForAction: 500
83
- }
84
- }
85
- }
86
- ```
87
-
88
- #### Example #2: Wait for DOMContentLoaded event and 0 network connections
89
-
90
- ```js
91
- {
92
- helpers: {
93
- Puppeteer : {
94
- url: "http://localhost",
95
- restart: false,
96
- waitForNavigation: [ "domcontentloaded", "networkidle0" ],
97
- waitForAction: 500
98
- }
99
- }
100
- }
101
- ```
102
-
103
- #### Example #3: Debug in window mode
104
-
105
- ```js
106
- {
107
- helpers: {
108
- Puppeteer : {
109
- url: "http://localhost",
110
- show: true
111
- }
112
- }
113
- }
114
- ```
115
-
116
- #### Example #4: Connect to remote browser by specifying [websocket endpoint][3]
117
-
118
- ```js
119
- {
120
- helpers: {
121
- Puppeteer: {
122
- url: "http://localhost",
123
- chrome: {
124
- browserWSEndpoint: "ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a"
125
- }
126
- }
127
- }
128
- }
129
- ```
130
-
131
- > Note: When connecting to remote browser `show` and specific `chrome` options (e.g. `headless` or `devtools`) are ignored.
132
-
133
- #### Example #5: Target URL with provided basic authentication
134
-
135
- ```js
136
- {
137
- helpers: {
138
- Puppeteer : {
139
- url: 'http://localhost',
140
- basicAuth: {username: 'username', password: 'password'},
141
- show: true
142
- }
143
- }
144
- }
145
- ```
146
-
147
- #### Troubleshooting
148
-
149
- Error Message: `No usable sandbox!`
150
-
151
- When running Puppeteer on CI try to disable sandbox if you see that message
152
-
153
- helpers: {
154
- Puppeteer: {
155
- url: 'http://localhost',
156
- show: false,
157
- chrome: {
158
- args: ['--no-sandbox', '--disable-setuid-sandbox']
159
- }
160
- },
161
- }
162
-
163
- ## Access From Helpers
164
-
165
- Receive Puppeteer client from a custom helper by accessing `browser` for the Browser object or `page` for the current Page object:
166
-
167
- ```js
168
- const { browser } = this.helpers.Puppeteer;
169
- await browser.pages(); // List of pages in the browser
170
-
171
- const { page } = this.helpers.Puppeteer;
172
- await page.url(); // Get the url of the current page
173
- ```
174
-
175
- ## Methods
176
-
177
- ### Parameters
178
-
179
- - `config`
180
-
181
- ### _addPopupListener
182
-
183
- Add the 'dialog' event listener to a page
184
-
185
- #### Parameters
186
-
187
- - `page`
188
-
189
- ### _getPageUrl
190
-
191
- Gets page URL including hash.
192
-
193
- ### _locate
194
-
195
- Get elements by different locator types, including strict locator
196
- Should be used in custom helpers:
197
-
198
- ```js
199
- const elements = await this.helpers['Puppeteer']._locate({name: 'password'});
200
- ```
201
-
202
-
203
-
204
-
205
- This action supports [React locators](https://codecept.io/react#locators)
206
-
207
-
208
- #### Parameters
209
-
210
- - `locator`
211
-
212
- ### _locateCheckable
213
-
214
- Find a checkbox by providing human readable text:
215
- NOTE: Assumes the checkable element exists
216
-
217
- ```js
218
- this.helpers['Puppeteer']._locateCheckable('I agree with terms and conditions').then // ...
219
- ```
220
-
221
- #### Parameters
222
-
223
- - `locator`
224
- - `providedContext`
225
-
226
- ### _locateClickable
227
-
228
- Find a clickable element by providing human readable text:
229
-
230
- ```js
231
- this.helpers['Puppeteer']._locateClickable('Next page').then // ...
232
- ```
233
-
234
- #### Parameters
235
-
236
- - `locator`
237
-
238
- ### _locateFields
239
-
240
- Find field elements by providing human readable text:
241
-
242
- ```js
243
- this.helpers['Puppeteer']._locateFields('Your email').then // ...
244
- ```
245
-
246
- #### Parameters
247
-
248
- - `locator`
249
-
250
- ### _setPage
251
-
252
- Set current page
253
-
254
- #### Parameters
255
-
256
- - `page` **[object][4]** page to set
257
-
258
- ### acceptPopup
259
-
260
- Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt.
261
- Don't confuse popups with modal windows, as created by [various
262
- libraries][5].
263
-
264
- ### amAcceptingPopups
265
-
266
- Set the automatic popup response to Accept.
267
- This must be set before a popup is triggered.
268
-
269
- ```js
270
- I.amAcceptingPopups();
271
- I.click('#triggerPopup');
272
- I.acceptPopup();
273
- ```
274
-
275
- ### amCancellingPopups
276
-
277
- Set the automatic popup response to Cancel/Dismiss.
278
- This must be set before a popup is triggered.
279
-
280
- ```js
281
- I.amCancellingPopups();
282
- I.click('#triggerPopup');
283
- I.cancelPopup();
284
- ```
285
-
286
- ### amOnPage
287
-
288
- Opens a web page in a browser. Requires relative or absolute url.
289
- If url starts with `/`, opens a web page of a site defined in `url` config parameter.
290
-
291
- ```js
292
- I.amOnPage('/'); // opens main page of website
293
- I.amOnPage('https://github.com'); // opens github
294
- I.amOnPage('/login'); // opens a login page
295
- ```
296
-
297
- #### Parameters
298
-
299
- - `url` **[string][6]** url path or global url.
300
-
301
- Returns **void** automatically synchronized promise through #recorder
302
-
303
- ### appendField
304
-
305
- Appends text to a input field or textarea.
306
- Field is located by name, label, CSS or XPath
307
-
308
- ```js
309
- I.appendField('#myTextField', 'appended');
310
- // typing secret
311
- I.appendField('password', secret('123456'));
312
- ```
313
-
314
- #### Parameters
315
-
316
- - `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator
317
- - `value` **[string][6]** text value to append.
318
-
319
- Returns **void** automatically synchronized promise through #recorder
320
-
321
-
322
- This action supports [React locators](https://codecept.io/react#locators)
323
-
324
-
325
- ### attachFile
326
-
327
- Attaches a file to element located by label, name, CSS or XPath
328
- Path to file is relative current codecept directory (where codecept.conf.ts or codecept.conf.js is located).
329
- File will be uploaded to remote system (if tests are running remotely).
330
-
331
- ```js
332
- I.attachFile('Avatar', 'data/avatar.jpg');
333
- I.attachFile('form input[name=avatar]', 'data/avatar.jpg');
334
- ```
335
-
336
- #### Parameters
337
-
338
- - `locator` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
339
- - `pathToFile` **[string][6]** local file path relative to codecept.conf.ts or codecept.conf.js config file.
340
-
341
- Returns **void** automatically synchronized promise through #recorder> ⚠ There is an [issue with file upload in Puppeteer 2.1.0 & 2.1.1][7], downgrade to 2.0.0 if you face it.
342
-
343
- ### blur
344
-
345
- Remove focus from a text input, button, etc.
346
- Calls [blur][8] on the element.
347
-
348
- Examples:
349
-
350
- ```js
351
- I.blur('.text-area')
352
- ```
353
-
354
- ```js
355
- //element `#product-tile` is focused
356
- I.see('#add-to-cart-btn');
357
- I.blur('#product-tile')
358
- I.dontSee('#add-to-cart-btn');
359
- ```
360
-
361
- #### Parameters
362
-
363
- - `locator` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
364
- - `options` **any?** Playwright only: [Additional options][9] for available options object as 2nd argument.
365
-
366
- Returns **void** automatically synchronized promise through #recorder
367
-
368
- ### cancelPopup
369
-
370
- Dismisses the active JavaScript popup, as created by window.alert|window.confirm|window.prompt.
371
-
372
- ### checkOption
373
-
374
- Selects a checkbox or radio button.
375
- Element is located by label or name or CSS or XPath.
376
-
377
- The second parameter is a context (CSS or XPath locator) to narrow the search.
378
-
379
- ```js
380
- I.checkOption('#agree');
381
- I.checkOption('I Agree to Terms and Conditions');
382
- I.checkOption('agree', '//form');
383
- ```
384
-
385
- #### Parameters
386
-
387
- - `field` **([string][6] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator.
388
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator.
389
-
390
- Returns **void** automatically synchronized promise through #recorder
391
-
392
- ### clearCookie
393
-
394
- Clears a cookie by name,
395
- if none provided clears all cookies.
396
-
397
- ```js
398
- I.clearCookie();
399
- I.clearCookie('test'); // Playwright currently doesn't support clear a particular cookie name
400
- ```
401
-
402
- #### Parameters
403
-
404
- - `name`
405
- - `cookie` **[string][6]?** (optional, `null` by default) cookie name
406
-
407
- ### clearField
408
-
409
- Clears a `<textarea>` or text `<input>` element's value.
410
-
411
- ```js
412
- I.clearField('Email');
413
- I.clearField('user[email]');
414
- I.clearField('#email');
415
- ```
416
-
417
- #### Parameters
418
-
419
- - `field`
420
- - `editable` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
421
-
422
- Returns **void** automatically synchronized promise through #recorder.
423
-
424
- ### click
425
-
426
- Perform a click on a link or a button, given by a locator.
427
- If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
428
- For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
429
- For images, the "alt" attribute and inner text of any parent links are searched.
430
-
431
- The second parameter is a context (CSS or XPath locator) to narrow the search.
432
-
433
- ```js
434
- // simple link
435
- I.click('Logout');
436
- // button of form
437
- I.click('Submit');
438
- // CSS button
439
- I.click('#form input[type=submit]');
440
- // XPath
441
- I.click('//form/*[@type=submit]');
442
- // link in context
443
- I.click('Logout', '#nav');
444
- // using strict locator
445
- I.click({css: 'nav a.login'});
446
- ```
447
-
448
- #### Parameters
449
-
450
- - `locator` **([string][6] | [object][4])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
451
- - `context` **([string][6]? | [object][4] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
452
-
453
- Returns **void** automatically synchronized promise through #recorder
454
-
455
-
456
- This action supports [React locators](https://codecept.io/react#locators)
457
-
458
-
459
- ### clickLink
460
-
461
- Performs a click on a link and waits for navigation before moving on.
462
-
463
- ```js
464
- I.clickLink('Logout', '#nav');
465
- ```
466
-
467
- #### Parameters
468
-
469
- - `locator` **([string][6] | [object][4])** clickable link or button located by text, or any element located by CSS|XPath|strict locator
470
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element to search in CSS|XPath|Strict locator
471
-
472
- Returns **void** automatically synchronized promise through #recorder
473
-
474
-
475
- This action supports [React locators](https://codecept.io/react#locators)
476
-
477
-
478
- ### closeCurrentTab
479
-
480
- Close current tab and switches to previous.
481
-
482
- ```js
483
- I.closeCurrentTab();
484
- ```
485
-
486
- ### closeOtherTabs
487
-
488
- Close all tabs except for the current one.
489
-
490
- ```js
491
- I.closeOtherTabs();
492
- ```
493
-
494
- ### dontSee
495
-
496
- Opposite to `see`. Checks that a text is not present on a page.
497
- Use context parameter to narrow down the search.
498
-
499
- ```js
500
- I.dontSee('Login'); // assume we are already logged in.
501
- I.dontSee('Login', '.nav'); // no login inside .nav element
502
- ```
503
-
504
- #### Parameters
505
-
506
- - `text` **[string][6]** which is not present.
507
- - `context` **([string][6] | [object][4])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search.
508
-
509
- Returns **void** automatically synchronized promise through #recorder
510
-
511
-
512
- This action supports [React locators](https://codecept.io/react#locators)
513
-
514
-
515
- ### dontSeeCheckboxIsChecked
516
-
517
- Verifies that the specified checkbox is not checked.
518
-
519
- ```js
520
- I.dontSeeCheckboxIsChecked('#agree'); // located by ID
521
- I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label
522
- I.dontSeeCheckboxIsChecked('agree'); // located by name
523
- ```
524
-
525
- #### Parameters
526
-
527
- - `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
528
-
529
- Returns **void** automatically synchronized promise through #recorder
530
-
531
- ### dontSeeCookie
532
-
533
- Checks that cookie with given name does not exist.
534
-
535
- ```js
536
- I.dontSeeCookie('auth'); // no auth cookie
537
- ```
538
-
539
- #### Parameters
540
-
541
- - `name` **[string][6]** cookie name.
542
-
543
- Returns **void** automatically synchronized promise through #recorder
544
-
545
- ### dontSeeCurrentUrlEquals
546
-
547
- Checks that current url is not equal to provided one.
548
- If a relative url provided, a configured url will be prepended to it.
549
-
550
- ```js
551
- I.dontSeeCurrentUrlEquals('/login'); // relative url are ok
552
- I.dontSeeCurrentUrlEquals('http://mysite.com/login'); // absolute urls are also ok
553
- ```
554
-
555
- #### Parameters
556
-
557
- - `url` **[string][6]** value to check.
558
-
559
- Returns **void** automatically synchronized promise through #recorder
560
-
561
- ### dontSeeElement
562
-
563
- Opposite to `seeElement`. Checks that element is not visible (or in DOM)
564
-
565
- ```js
566
- I.dontSeeElement('.modal'); // modal is not shown
567
- ```
568
-
569
- #### Parameters
570
-
571
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|Strict locator.
572
-
573
- Returns **void** automatically synchronized promise through #recorder
574
-
575
-
576
- This action supports [React locators](https://codecept.io/react#locators)
577
-
578
-
579
- ### dontSeeElementInDOM
580
-
581
- Opposite to `seeElementInDOM`. Checks that element is not on page.
582
-
583
- ```js
584
- I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not
585
- ```
586
-
587
- #### Parameters
588
-
589
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|Strict locator.
590
-
591
- Returns **void** automatically synchronized promise through #recorder
592
-
593
- ### dontSeeInCurrentUrl
594
-
595
- Checks that current url does not contain a provided fragment.
596
-
597
- #### Parameters
598
-
599
- - `url` **[string][6]** value to check.
600
-
601
- Returns **void** automatically synchronized promise through #recorder
602
-
603
- ### dontSeeInField
604
-
605
- Checks that value of input field or textarea doesn't equal to given value
606
- Opposite to `seeInField`.
607
-
608
- ```js
609
- I.dontSeeInField('email', 'user@user.com'); // field by name
610
- I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
611
- ```
612
-
613
- #### Parameters
614
-
615
- - `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
616
- - `value` **([string][6] | [object][4])** value to check.
617
-
618
- Returns **void** automatically synchronized promise through #recorder
619
-
620
- ### dontSeeInSource
621
-
622
- Checks that the current page does not contains the given string in its raw source code.
623
-
624
- ```js
625
- I.dontSeeInSource('<!--'); // no comments in source
626
- ```
627
-
628
- #### Parameters
629
-
630
- - `text`
631
- - `value` **[string][6]** to check.
632
-
633
- Returns **void** automatically synchronized promise through #recorder
634
-
635
- ### dontSeeInTitle
636
-
637
- Checks that title does not contain text.
638
-
639
- ```js
640
- I.dontSeeInTitle('Error');
641
- ```
642
-
643
- #### Parameters
644
-
645
- - `text` **[string][6]** value to check.
646
-
647
- Returns **void** automatically synchronized promise through #recorder
648
-
649
- ### doubleClick
650
-
651
- Performs a double-click on an element matched by link|button|label|CSS or XPath.
652
- Context can be specified as second parameter to narrow search.
653
-
654
- ```js
655
- I.doubleClick('Edit');
656
- I.doubleClick('Edit', '.actions');
657
- I.doubleClick({css: 'button.accept'});
658
- I.doubleClick('.btn.edit');
659
- ```
660
-
661
- #### Parameters
662
-
663
- - `locator` **([string][6] | [object][4])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
664
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
665
-
666
- Returns **void** automatically synchronized promise through #recorder
667
-
668
-
669
- This action supports [React locators](https://codecept.io/react#locators)
670
-
671
-
672
- ### downloadFile
673
-
674
- This method is **deprecated**.
675
-
676
- Please use `handleDownloads()` instead.
677
-
678
- #### Parameters
679
-
680
- - `locator`
681
- - `customName`
682
-
683
- ### dragAndDrop
684
-
685
- Drag an item to a destination element.
686
-
687
- ```js
688
- I.dragAndDrop('#dragHandle', '#container');
689
- ```
690
-
691
- #### Parameters
692
-
693
- - `srcElement` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
694
- - `destElement` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
695
-
696
- Returns **void** automatically synchronized promise through #recorder
697
-
698
- ### dragSlider
699
-
700
- Drag the scrubber of a slider to a given position
701
- For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
702
-
703
- ```js
704
- I.dragSlider('#slider', 30);
705
- I.dragSlider('#slider', -70);
706
- ```
707
-
708
- #### Parameters
709
-
710
- - `locator` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
711
- - `offsetX` **[number][10]** position to drag.
712
-
713
- Returns **void** automatically synchronized promise through #recorder
714
-
715
-
716
- This action supports [React locators](https://codecept.io/react#locators)
717
-
718
-
719
- ### executeAsyncScript
720
-
721
- Executes async script on page.
722
- Provided function should execute a passed callback (as first argument) to signal it is finished.
723
-
724
- Example: In Vue.js to make components completely rendered we are waiting for [nextTick][11].
725
-
726
- ```js
727
- I.executeAsyncScript(function(done) {
728
- Vue.nextTick(done); // waiting for next tick
729
- });
730
- ```
731
-
732
- By passing value to `done()` function you can return values.
733
- Additional arguments can be passed as well, while `done` function is always last parameter in arguments list.
734
-
735
- ```js
736
- let val = await I.executeAsyncScript(function(url, done) {
737
- // in browser context
738
- $.ajax(url, { success: (data) => done(data); }
739
- }, 'http://ajax.callback.url/');
740
- ```
741
-
742
- #### Parameters
743
-
744
- - `args` **...any** to be passed to function.
745
- - `fn` **([string][6] | [function][12])** function to be executed in browser context.
746
-
747
- Returns **[Promise][13]&lt;any>** script return valueAsynchronous scripts can also be executed with `executeScript` if a function returns a Promise.
748
-
749
- ### executeScript
750
-
751
- Executes sync script on a page.
752
- Pass arguments to function as additional parameters.
753
- Will return execution result to a test.
754
- In this case you should use async function and await to receive results.
755
-
756
- Example with jQuery DatePicker:
757
-
758
- ```js
759
- // change date of jQuery DatePicker
760
- I.executeScript(function() {
761
- // now we are inside browser context
762
- $('date').datetimepicker('setDate', new Date());
763
- });
764
- ```
765
-
766
- Can return values. Don't forget to use `await` to get them.
767
-
768
- ```js
769
- let date = await I.executeScript(function(el) {
770
- // only basic types can be returned
771
- return $(el).datetimepicker('getDate').toString();
772
- }, '#date'); // passing jquery selector
773
- ```
774
-
775
- #### Parameters
776
-
777
- - `args` **...any** to be passed to function.
778
- - `fn` **([string][6] | [function][12])** function to be executed in browser context.
779
-
780
- Returns **[Promise][13]&lt;any>** script return valueIf a function returns a Promise It will wait for it resolution.
781
-
782
- ### fillField
783
-
784
- Fills a text field or textarea, after clearing its value, with the given string.
785
- Field is located by name, label, CSS, or XPath.
786
-
787
- ```js
788
- // by label
789
- I.fillField('Email', 'hello@world.com');
790
- // by name
791
- I.fillField('password', secret('123456'));
792
- // by CSS
793
- I.fillField('form#login input[name=username]', 'John');
794
- // or by strict locator
795
- I.fillField({css: 'form#login input[name=username]'}, 'John');
796
- ```
797
-
798
- #### Parameters
799
-
800
- - `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
801
- - `value` **([string][6] | [object][4])** text value to fill.
802
-
803
- Returns **void** automatically synchronized promise through #recorder
804
-
805
-
806
- This action supports [React locators](https://codecept.io/react#locators)
807
-
808
-
809
- ### focus
810
-
811
- Calls [focus][8] on the matching element.
812
-
813
- Examples:
814
-
815
- ```js
816
- I.dontSee('#add-to-cart-btn');
817
- I.focus('#product-tile')
818
- I.see('#add-to-cart-bnt');
819
- ```
820
-
821
- #### Parameters
822
-
823
- - `locator` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
824
- - `options` **any?** Playwright only: [Additional options][14] for available options object as 2nd argument.
825
-
826
- Returns **void** automatically synchronized promise through #recorder
827
-
828
- ### forceClick
829
-
830
- Perform an emulated click on a link or a button, given by a locator.
831
- Unlike normal click instead of sending native event, emulates a click with JavaScript.
832
- This works on hidden, animated or inactive elements as well.
833
-
834
- If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
835
- For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
836
- For images, the "alt" attribute and inner text of any parent links are searched.
837
-
838
- The second parameter is a context (CSS or XPath locator) to narrow the search.
839
-
840
- ```js
841
- // simple link
842
- I.forceClick('Logout');
843
- // button of form
844
- I.forceClick('Submit');
845
- // CSS button
846
- I.forceClick('#form input[type=submit]');
847
- // XPath
848
- I.forceClick('//form/*[@type=submit]');
849
- // link in context
850
- I.forceClick('Logout', '#nav');
851
- // using strict locator
852
- I.forceClick({css: 'nav a.login'});
853
- ```
854
-
855
- #### Parameters
856
-
857
- - `locator` **([string][6] | [object][4])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
858
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
859
-
860
- Returns **void** automatically synchronized promise through #recorder
861
-
862
-
863
- This action supports [React locators](https://codecept.io/react#locators)
864
-
865
-
866
- ### grabAttributeFrom
867
-
868
- Retrieves an attribute from an element located by CSS or XPath and returns it to test.
869
- Resumes test execution, so **should be used inside async with `await`** operator.
870
- If more than one element is found - attribute of first element is returned.
871
-
872
- ```js
873
- let hint = await I.grabAttributeFrom('#tooltip', 'title');
874
- ```
875
-
876
- #### Parameters
877
-
878
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
879
- - `attr` **[string][6]** attribute name.
880
-
881
- Returns **[Promise][13]&lt;[string][6]>** attribute value
882
-
883
-
884
- This action supports [React locators](https://codecept.io/react#locators)
885
-
886
-
887
- ### grabAttributeFromAll
888
-
889
- Retrieves an array of attributes from elements located by CSS or XPath and returns it to test.
890
- Resumes test execution, so **should be used inside async with `await`** operator.
891
-
892
- ```js
893
- let hints = await I.grabAttributeFromAll('.tooltip', 'title');
894
- ```
895
-
896
- #### Parameters
897
-
898
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
899
- - `attr` **[string][6]** attribute name.
900
-
901
- Returns **[Promise][13]&lt;[Array][15]&lt;[string][6]>>** attribute value
902
-
903
-
904
- This action supports [React locators](https://codecept.io/react#locators)
905
-
906
-
907
- ### grabBrowserLogs
908
-
909
- Get JS log from browser.
910
-
911
- ```js
912
- let logs = await I.grabBrowserLogs();
913
- console.log(JSON.stringify(logs))
914
- ```
915
-
916
- Returns **[Promise][13]&lt;[Array][15]&lt;any>>**
917
-
918
- ### grabCookie
919
-
920
- Gets a cookie object by name.
921
- If none provided gets all cookies.
922
- Resumes test execution, so **should be used inside async function with `await`** operator.
923
-
924
- ```js
925
- let cookie = await I.grabCookie('auth');
926
- assert(cookie.value, '123456');
927
- ```
928
-
929
- #### Parameters
930
-
931
- - `name` **[string][6]?** cookie name.
932
-
933
- Returns **any** attribute valueReturns cookie in JSON format. If name not passed returns all cookies for this domain.
934
-
935
- ### grabCssPropertyFrom
936
-
937
- Grab CSS property for given locator
938
- Resumes test execution, so **should be used inside an async function with `await`** operator.
939
- If more than one element is found - value of first element is returned.
940
-
941
- ```js
942
- const value = await I.grabCssPropertyFrom('h3', 'font-weight');
943
- ```
944
-
945
- #### Parameters
946
-
947
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
948
- - `cssProperty` **[string][6]** CSS property name.
949
-
950
- Returns **[Promise][13]&lt;[string][6]>** CSS value
951
-
952
-
953
- This action supports [React locators](https://codecept.io/react#locators)
954
-
955
-
956
- ### grabCssPropertyFromAll
957
-
958
- Grab array of CSS properties for given locator
959
- Resumes test execution, so **should be used inside an async function with `await`** operator.
960
-
961
- ```js
962
- const values = await I.grabCssPropertyFromAll('h3', 'font-weight');
963
- ```
964
-
965
- #### Parameters
966
-
967
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
968
- - `cssProperty` **[string][6]** CSS property name.
969
-
970
- Returns **[Promise][13]&lt;[Array][15]&lt;[string][6]>>** CSS value
971
-
972
-
973
- This action supports [React locators](https://codecept.io/react#locators)
974
-
975
-
976
- ### grabCurrentUrl
977
-
978
- Get current URL from browser.
979
- Resumes test execution, so should be used inside an async function.
980
-
981
- ```js
982
- let url = await I.grabCurrentUrl();
983
- console.log(`Current URL is [${url}]`);
984
- ```
985
-
986
- Returns **[Promise][13]&lt;[string][6]>** current URL
987
-
988
- ### grabDataFromPerformanceTiming
989
-
990
- Grab the data from performance timing using Navigation Timing API.
991
- The returned data will contain following things in ms:
992
-
993
- - responseEnd,
994
- - domInteractive,
995
- - domContentLoadedEventEnd,
996
- - loadEventEnd
997
- Resumes test execution, so **should be used inside an async function with `await`** operator.
998
-
999
- ```js
1000
- await I.amOnPage('https://example.com');
1001
- let data = await I.grabDataFromPerformanceTiming();
1002
- //Returned data
1003
- { // all results are in [ms]
1004
- responseEnd: 23,
1005
- domInteractive: 44,
1006
- domContentLoadedEventEnd: 196,
1007
- loadEventEnd: 241
1008
- }
1009
- ```
1010
-
1011
- Returns **void** automatically synchronized promise through #recorder
1012
-
1013
- ### grabElementBoundingRect
1014
-
1015
- Grab the width, height, location of given locator.
1016
- Provide `width` or `height`as second param to get your desired prop.
1017
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1018
-
1019
- Returns an object with `x`, `y`, `width`, `height` keys.
1020
-
1021
- ```js
1022
- const value = await I.grabElementBoundingRect('h3');
1023
- // value is like { x: 226.5, y: 89, width: 527, height: 220 }
1024
- ```
1025
-
1026
- To get only one metric use second parameter:
1027
-
1028
- ```js
1029
- const width = await I.grabElementBoundingRect('h3', 'width');
1030
- // width == 527
1031
- ```
1032
-
1033
- #### Parameters
1034
-
1035
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1036
- - `prop`
1037
- - `elementSize` **[string][6]?** x, y, width or height of the given element.
1038
-
1039
- Returns **([Promise][13]&lt;DOMRect> | [Promise][13]&lt;[number][10]>)** Element bounding rectangle
1040
-
1041
- ### grabHTMLFrom
1042
-
1043
- Retrieves the innerHTML from an element located by CSS or XPath and returns it to test.
1044
- Resumes test execution, so **should be used inside async function with `await`** operator.
1045
- If more than one element is found - HTML of first element is returned.
1046
-
1047
- ```js
1048
- let postHTML = await I.grabHTMLFrom('#post');
1049
- ```
1050
-
1051
- #### Parameters
1052
-
1053
- - `locator`
1054
- - `element` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1055
-
1056
- Returns **[Promise][13]&lt;[string][6]>** HTML code for an element
1057
-
1058
- ### grabHTMLFromAll
1059
-
1060
- Retrieves all the innerHTML from elements located by CSS or XPath and returns it to test.
1061
- Resumes test execution, so **should be used inside async function with `await`** operator.
1062
-
1063
- ```js
1064
- let postHTMLs = await I.grabHTMLFromAll('.post');
1065
- ```
1066
-
1067
- #### Parameters
1068
-
1069
- - `locator`
1070
- - `element` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1071
-
1072
- Returns **[Promise][13]&lt;[Array][15]&lt;[string][6]>>** HTML code for an element
1073
-
1074
- ### grabNumberOfOpenTabs
1075
-
1076
- Grab number of open tabs.
1077
- Resumes test execution, so **should be used inside async function with `await`** operator.
1078
-
1079
- ```js
1080
- let tabs = await I.grabNumberOfOpenTabs();
1081
- ```
1082
-
1083
- Returns **[Promise][13]&lt;[number][10]>** number of open tabs
1084
-
1085
- ### grabNumberOfVisibleElements
1086
-
1087
- Grab number of visible elements by locator.
1088
- Resumes test execution, so **should be used inside async function with `await`** operator.
1089
-
1090
- ```js
1091
- let numOfElements = await I.grabNumberOfVisibleElements('p');
1092
- ```
1093
-
1094
- #### Parameters
1095
-
1096
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1097
-
1098
- Returns **[Promise][13]&lt;[number][10]>** number of visible elements
1099
-
1100
-
1101
-
1102
- This action supports [React locators](https://codecept.io/react#locators)
1103
-
1104
-
1105
- ### grabPageScrollPosition
1106
-
1107
- Retrieves a page scroll position and returns it to test.
1108
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1109
-
1110
- ```js
1111
- let { x, y } = await I.grabPageScrollPosition();
1112
- ```
1113
-
1114
- Returns **[Promise][13]&lt;PageScrollPosition>** scroll position
1115
-
1116
- ### grabPopupText
1117
-
1118
- Grab the text within the popup. If no popup is visible then it will return null
1119
-
1120
- ```js
1121
- await I.grabPopupText();
1122
- ```
1123
-
1124
- Returns **[Promise][13]&lt;([string][6] | null)>**
1125
-
1126
- ### grabSource
1127
-
1128
- Retrieves page source and returns it to test.
1129
- Resumes test execution, so **should be used inside async function with `await`** operator.
1130
-
1131
- ```js
1132
- let pageSource = await I.grabSource();
1133
- ```
1134
-
1135
- Returns **[Promise][13]&lt;[string][6]>** source code
1136
-
1137
- ### grabTextFrom
1138
-
1139
- Retrieves a text from an element located by CSS or XPath and returns it to test.
1140
- Resumes test execution, so **should be used inside async with `await`** operator.
1141
-
1142
- ```js
1143
- let pin = await I.grabTextFrom('#pin');
1144
- ```
1145
-
1146
- If multiple elements found returns first element.
1147
-
1148
- #### Parameters
1149
-
1150
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1151
-
1152
- Returns **[Promise][13]&lt;[string][6]>** attribute value
1153
-
1154
-
1155
- This action supports [React locators](https://codecept.io/react#locators)
1156
-
1157
-
1158
- ### grabTextFromAll
1159
-
1160
- Retrieves all texts from an element located by CSS or XPath and returns it to test.
1161
- Resumes test execution, so **should be used inside async with `await`** operator.
1162
-
1163
- ```js
1164
- let pins = await I.grabTextFromAll('#pin li');
1165
- ```
1166
-
1167
- #### Parameters
1168
-
1169
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1170
-
1171
- Returns **[Promise][13]&lt;[Array][15]&lt;[string][6]>>** attribute value
1172
-
1173
-
1174
- This action supports [React locators](https://codecept.io/react#locators)
1175
-
1176
-
1177
- ### grabTitle
1178
-
1179
- Retrieves a page title and returns it to test.
1180
- Resumes test execution, so **should be used inside async with `await`** operator.
1181
-
1182
- ```js
1183
- let title = await I.grabTitle();
1184
- ```
1185
-
1186
- Returns **[Promise][13]&lt;[string][6]>** title
1187
-
1188
- ### grabValueFrom
1189
-
1190
- Retrieves a value from a form element located by CSS or XPath and returns it to test.
1191
- Resumes test execution, so **should be used inside async function with `await`** operator.
1192
- If more than one element is found - value of first element is returned.
1193
-
1194
- ```js
1195
- let email = await I.grabValueFrom('input[name=email]');
1196
- ```
1197
-
1198
- #### Parameters
1199
-
1200
- - `locator` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
1201
-
1202
- Returns **[Promise][13]&lt;[string][6]>** attribute value
1203
-
1204
- ### grabValueFromAll
1205
-
1206
- Retrieves an array of value from a form located by CSS or XPath and returns it to test.
1207
- Resumes test execution, so **should be used inside async function with `await`** operator.
1208
-
1209
- ```js
1210
- let inputs = await I.grabValueFromAll('//form/input');
1211
- ```
1212
-
1213
- #### Parameters
1214
-
1215
- - `locator` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
1216
-
1217
- Returns **[Promise][13]&lt;[Array][15]&lt;[string][6]>>** attribute value
1218
-
1219
- ### grabWebElements
1220
-
1221
- Grab WebElements for given locator
1222
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1223
-
1224
- ```js
1225
- const webElements = await I.grabWebElements('#button');
1226
- ```
1227
-
1228
- #### Parameters
1229
-
1230
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1231
-
1232
- Returns **[Promise][13]&lt;any>** WebElement of being used Web helper
1233
-
1234
- ### handleDownloads
1235
-
1236
- Sets a directory to where save files. Allows to test file downloads.
1237
- Should be used with [FileSystem helper][16] to check that file were downloaded correctly.
1238
-
1239
- By default files are saved to `output/downloads`.
1240
- This directory is cleaned on every `handleDownloads` call, to ensure no old files are kept.
1241
-
1242
- ```js
1243
- I.handleDownloads();
1244
- I.click('Download Avatar');
1245
- I.amInPath('output/downloads');
1246
- I.seeFile('avatar.jpg');
1247
- ```
1248
-
1249
- #### Parameters
1250
-
1251
- - `downloadPath` **[string][6]** change this parameter to set another directory for saving
1252
-
1253
- ### moveCursorTo
1254
-
1255
- Moves cursor to element matched by locator.
1256
- Extra shift can be set with offsetX and offsetY options.
1257
-
1258
- ```js
1259
- I.moveCursorTo('.tooltip');
1260
- I.moveCursorTo('#submit', 5,5);
1261
- ```
1262
-
1263
- #### Parameters
1264
-
1265
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1266
- - `offsetX` **[number][10]** (optional, `0` by default) X-axis offset.
1267
- - `offsetY` **[number][10]** (optional, `0` by default) Y-axis offset.
1268
-
1269
- Returns **void** automatically synchronized promise through #recorder
1270
-
1271
-
1272
- This action supports [React locators](https://codecept.io/react#locators)
1273
-
1274
-
1275
- ### openNewTab
1276
-
1277
- Open new tab and switch to it
1278
-
1279
- ```js
1280
- I.openNewTab();
1281
- ```
1282
-
1283
- ### pressKey
1284
-
1285
- Presses a key in the browser (on a focused element).
1286
-
1287
- _Hint:_ For populating text field or textarea, it is recommended to use [`fillField`][17].
1288
-
1289
- ```js
1290
- I.pressKey('Backspace');
1291
- ```
1292
-
1293
- To press a key in combination with modifier keys, pass the sequence as an array. All modifier keys (`'Alt'`, `'Control'`, `'Meta'`, `'Shift'`) will be released afterwards.
1294
-
1295
- ```js
1296
- I.pressKey(['Control', 'Z']);
1297
- ```
1298
-
1299
- For specifying operation modifier key based on operating system it is suggested to use `'CommandOrControl'`.
1300
- This will press `'Command'` (also known as `'Meta'`) on macOS machines and `'Control'` on non-macOS machines.
1301
-
1302
- ```js
1303
- I.pressKey(['CommandOrControl', 'Z']);
1304
- ```
1305
-
1306
- Some of the supported key names are:
1307
-
1308
- - `'AltLeft'` or `'Alt'`
1309
- - `'AltRight'`
1310
- - `'ArrowDown'`
1311
- - `'ArrowLeft'`
1312
- - `'ArrowRight'`
1313
- - `'ArrowUp'`
1314
- - `'Backspace'`
1315
- - `'Clear'`
1316
- - `'ControlLeft'` or `'Control'`
1317
- - `'ControlRight'`
1318
- - `'Command'`
1319
- - `'CommandOrControl'`
1320
- - `'Delete'`
1321
- - `'End'`
1322
- - `'Enter'`
1323
- - `'Escape'`
1324
- - `'F1'` to `'F12'`
1325
- - `'Home'`
1326
- - `'Insert'`
1327
- - `'MetaLeft'` or `'Meta'`
1328
- - `'MetaRight'`
1329
- - `'Numpad0'` to `'Numpad9'`
1330
- - `'NumpadAdd'`
1331
- - `'NumpadDecimal'`
1332
- - `'NumpadDivide'`
1333
- - `'NumpadMultiply'`
1334
- - `'NumpadSubtract'`
1335
- - `'PageDown'`
1336
- - `'PageUp'`
1337
- - `'Pause'`
1338
- - `'Return'`
1339
- - `'ShiftLeft'` or `'Shift'`
1340
- - `'ShiftRight'`
1341
- - `'Space'`
1342
- - `'Tab'`
1343
-
1344
- #### Parameters
1345
-
1346
- - `key` **([string][6] | [Array][15]&lt;[string][6]>)** key or array of keys to press.
1347
-
1348
- Returns **void** automatically synchronized promise through #recorder_Note:_ Shortcuts like `'Meta'` + `'A'` do not work on macOS ([GoogleChrome/puppeteer#1313][18]).
1349
-
1350
- ### pressKeyDown
1351
-
1352
- Presses a key in the browser and leaves it in a down state.
1353
-
1354
- To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][19]).
1355
-
1356
- ```js
1357
- I.pressKeyDown('Control');
1358
- I.click('#element');
1359
- I.pressKeyUp('Control');
1360
- ```
1361
-
1362
- #### Parameters
1363
-
1364
- - `key` **[string][6]** name of key to press down.
1365
-
1366
- Returns **void** automatically synchronized promise through #recorder
1367
-
1368
- ### pressKeyUp
1369
-
1370
- Releases a key in the browser which was previously set to a down state.
1371
-
1372
- To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][19]).
1373
-
1374
- ```js
1375
- I.pressKeyDown('Control');
1376
- I.click('#element');
1377
- I.pressKeyUp('Control');
1378
- ```
1379
-
1380
- #### Parameters
1381
-
1382
- - `key` **[string][6]** name of key to release.
1383
-
1384
- Returns **void** automatically synchronized promise through #recorder
1385
-
1386
- ### refreshPage
1387
-
1388
- Reload the current page.
1389
-
1390
- ```js
1391
- I.refreshPage();
1392
- ```
1393
-
1394
- Returns **void** automatically synchronized promise through #recorder
1395
-
1396
- ### resizeWindow
1397
-
1398
- Resize the current window to provided width and height.
1399
- First parameter can be set to `maximize`.
1400
-
1401
- #### Parameters
1402
-
1403
- - `width` **[number][10]** width in pixels or `maximize`.
1404
- - `height` **[number][10]** height in pixels.
1405
-
1406
- Returns **void** automatically synchronized promise through #recorderUnlike other drivers Puppeteer changes the size of a viewport, not the window!
1407
- Puppeteer does not control the window of a browser so it can't adjust its real size.
1408
- It also can't maximize a window.
1409
-
1410
- ### rightClick
1411
-
1412
- Performs right click on a clickable element matched by semantic locator, CSS or XPath.
1413
-
1414
- ```js
1415
- // right click element with id el
1416
- I.rightClick('#el');
1417
- // right click link or button with text "Click me"
1418
- I.rightClick('Click me');
1419
- // right click button with text "Click me" inside .context
1420
- I.rightClick('Click me', '.context');
1421
- ```
1422
-
1423
- #### Parameters
1424
-
1425
- - `locator` **([string][6] | [object][4])** clickable element located by CSS|XPath|strict locator.
1426
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element located by CSS|XPath|strict locator.
1427
-
1428
- Returns **void** automatically synchronized promise through #recorder
1429
-
1430
-
1431
- This action supports [React locators](https://codecept.io/react#locators)
1432
-
1433
-
1434
- ### saveElementScreenshot
1435
-
1436
- Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
1437
- Filename is relative to output folder.
1438
-
1439
- ```js
1440
- I.saveElementScreenshot(`#submit`,'debug.png');
1441
- ```
1442
-
1443
- #### Parameters
1444
-
1445
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1446
- - `fileName` **[string][6]** file name to save.
1447
-
1448
- Returns **void** automatically synchronized promise through #recorder
1449
-
1450
- ### saveScreenshot
1451
-
1452
- Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
1453
- Filename is relative to output folder.
1454
- Optionally resize the window to the full available page `scrollHeight` and `scrollWidth` to capture the entire page by passing `true` in as the second argument.
1455
-
1456
- ```js
1457
- I.saveScreenshot('debug.png');
1458
- I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1459
- ```
1460
-
1461
- #### Parameters
1462
-
1463
- - `fileName` **[string][6]** file name to save.
1464
- - `fullPage` **[boolean][20]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1465
-
1466
- Returns **void** automatically synchronized promise through #recorder
1467
-
1468
- ### scrollPageToBottom
1469
-
1470
- Scroll page to the bottom.
1471
-
1472
- ```js
1473
- I.scrollPageToBottom();
1474
- ```
1475
-
1476
- Returns **void** automatically synchronized promise through #recorder
1477
-
1478
- ### scrollPageToTop
1479
-
1480
- Scroll page to the top.
1481
-
1482
- ```js
1483
- I.scrollPageToTop();
1484
- ```
1485
-
1486
- Returns **void** automatically synchronized promise through #recorder
1487
-
1488
- ### scrollTo
1489
-
1490
- Scrolls to element matched by locator.
1491
- Extra shift can be set with offsetX and offsetY options.
1492
-
1493
- ```js
1494
- I.scrollTo('footer');
1495
- I.scrollTo('#submit', 5, 5);
1496
- ```
1497
-
1498
- #### Parameters
1499
-
1500
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1501
- - `offsetX` **[number][10]** (optional, `0` by default) X-axis offset.
1502
- - `offsetY` **[number][10]** (optional, `0` by default) Y-axis offset.
1503
-
1504
- Returns **void** automatically synchronized promise through #recorder
1505
-
1506
- ### see
1507
-
1508
- Checks that a page contains a visible text.
1509
- Use context parameter to narrow down the search.
1510
-
1511
- ```js
1512
- I.see('Welcome'); // text welcome on a page
1513
- I.see('Welcome', '.content'); // text inside .content div
1514
- I.see('Register', {css: 'form.register'}); // use strict locator
1515
- ```
1516
-
1517
- #### Parameters
1518
-
1519
- - `text` **[string][6]** expected on page.
1520
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text.
1521
-
1522
- Returns **void** automatically synchronized promise through #recorder
1523
-
1524
-
1525
- This action supports [React locators](https://codecept.io/react#locators)
1526
-
1527
-
1528
- ### seeAttributesOnElements
1529
-
1530
- Checks that all elements with given locator have given attributes.
1531
-
1532
- ```js
1533
- I.seeAttributesOnElements('//form', { method: "post"});
1534
- ```
1535
-
1536
- #### Parameters
1537
-
1538
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1539
- - `attributes` **[object][4]** attributes and their values to check.
1540
-
1541
- Returns **void** automatically synchronized promise through #recorder
1542
-
1543
-
1544
- This action supports [React locators](https://codecept.io/react#locators)
1545
-
1546
-
1547
- ### seeCheckboxIsChecked
1548
-
1549
- Verifies that the specified checkbox is checked.
1550
-
1551
- ```js
1552
- I.seeCheckboxIsChecked('Agree');
1553
- I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
1554
- I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'});
1555
- ```
1556
-
1557
- #### Parameters
1558
-
1559
- - `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
1560
-
1561
- Returns **void** automatically synchronized promise through #recorder
1562
-
1563
- ### seeCookie
1564
-
1565
- Checks that cookie with given name exists.
1566
-
1567
- ```js
1568
- I.seeCookie('Auth');
1569
- ```
1570
-
1571
- #### Parameters
1572
-
1573
- - `name` **[string][6]** cookie name.
1574
-
1575
- Returns **void** automatically synchronized promise through #recorder
1576
-
1577
- ### seeCssPropertiesOnElements
1578
-
1579
- Checks that all elements with given locator have given CSS properties.
1580
-
1581
- ```js
1582
- I.seeCssPropertiesOnElements('h3', { 'font-weight': "bold"});
1583
- ```
1584
-
1585
- #### Parameters
1586
-
1587
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1588
- - `cssProperties` **[object][4]** object with CSS properties and their values to check.
1589
-
1590
- Returns **void** automatically synchronized promise through #recorder
1591
-
1592
-
1593
- This action supports [React locators](https://codecept.io/react#locators)
1594
-
1595
-
1596
- ### seeCurrentUrlEquals
1597
-
1598
- Checks that current url is equal to provided one.
1599
- If a relative url provided, a configured url will be prepended to it.
1600
- So both examples will work:
1601
-
1602
- ```js
1603
- I.seeCurrentUrlEquals('/register');
1604
- I.seeCurrentUrlEquals('http://my.site.com/register');
1605
- ```
1606
-
1607
- #### Parameters
1608
-
1609
- - `url` **[string][6]** value to check.
1610
-
1611
- Returns **void** automatically synchronized promise through #recorder
1612
-
1613
- ### seeElement
1614
-
1615
- Checks that a given Element is visible
1616
- Element is located by CSS or XPath.
1617
-
1618
- ```js
1619
- I.seeElement('#modal');
1620
- ```
1621
-
1622
- #### Parameters
1623
-
1624
- - `locator` **([string][6] | [object][4])** located by CSS|XPath|strict locator.
1625
-
1626
- Returns **void** automatically synchronized promise through #recorder
1627
-
1628
-
1629
- This action supports [React locators](https://codecept.io/react#locators)
1630
-
1631
-
1632
- ### seeElementInDOM
1633
-
1634
- Checks that a given Element is present in the DOM
1635
- Element is located by CSS or XPath.
1636
-
1637
- ```js
1638
- I.seeElementInDOM('#modal');
1639
- ```
1640
-
1641
- #### Parameters
1642
-
1643
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1644
-
1645
- Returns **void** automatically synchronized promise through #recorder
1646
-
1647
- ### seeInCurrentUrl
1648
-
1649
- Checks that current url contains a provided fragment.
1650
-
1651
- ```js
1652
- I.seeInCurrentUrl('/register'); // we are on registration page
1653
- ```
1654
-
1655
- #### Parameters
1656
-
1657
- - `url` **[string][6]** a fragment to check
1658
-
1659
- Returns **void** automatically synchronized promise through #recorder
1660
-
1661
- ### seeInField
1662
-
1663
- Checks that the given input field or textarea equals to given value.
1664
- For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
1665
-
1666
- ```js
1667
- I.seeInField('Username', 'davert');
1668
- I.seeInField({css: 'form textarea'},'Type your comment here');
1669
- I.seeInField('form input[type=hidden]','hidden_value');
1670
- I.seeInField('#searchform input','Search');
1671
- ```
1672
-
1673
- #### Parameters
1674
-
1675
- - `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
1676
- - `value` **([string][6] | [object][4])** value to check.
1677
-
1678
- Returns **void** automatically synchronized promise through #recorder
1679
-
1680
- ### seeInPopup
1681
-
1682
- Checks that the active JavaScript popup, as created by `window.alert|window.confirm|window.prompt`, contains the
1683
- given string.
1684
-
1685
- ```js
1686
- I.seeInPopup('Popup text');
1687
- ```
1688
-
1689
- #### Parameters
1690
-
1691
- - `text` **[string][6]** value to check.
1692
-
1693
- Returns **void** automatically synchronized promise through #recorder
1694
-
1695
- ### seeInSource
1696
-
1697
- Checks that the current page contains the given string in its raw source code.
1698
-
1699
- ```js
1700
- I.seeInSource('<h1>Green eggs &amp; ham</h1>');
1701
- ```
1702
-
1703
- #### Parameters
1704
-
1705
- - `text` **[string][6]** value to check.
1706
-
1707
- Returns **void** automatically synchronized promise through #recorder
1708
-
1709
- ### seeInTitle
1710
-
1711
- Checks that title contains text.
1712
-
1713
- ```js
1714
- I.seeInTitle('Home Page');
1715
- ```
1716
-
1717
- #### Parameters
1718
-
1719
- - `text` **[string][6]** text value to check.
1720
-
1721
- Returns **void** automatically synchronized promise through #recorder
1722
-
1723
- ### seeNumberOfElements
1724
-
1725
- Asserts that an element appears a given number of times in the DOM.
1726
- Element is located by label or name or CSS or XPath.
1727
-
1728
- ```js
1729
- I.seeNumberOfElements('#submitBtn', 1);
1730
- ```
1731
-
1732
- #### Parameters
1733
-
1734
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1735
- - `num` **[number][10]** number of elements.
1736
-
1737
- Returns **void** automatically synchronized promise through #recorder
1738
-
1739
-
1740
- This action supports [React locators](https://codecept.io/react#locators)
1741
-
1742
-
1743
- ### seeNumberOfVisibleElements
1744
-
1745
- Asserts that an element is visible a given number of times.
1746
- Element is located by CSS or XPath.
1747
-
1748
- ```js
1749
- I.seeNumberOfVisibleElements('.buttons', 3);
1750
- ```
1751
-
1752
- #### Parameters
1753
-
1754
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1755
- - `num` **[number][10]** number of elements.
1756
-
1757
- Returns **void** automatically synchronized promise through #recorder
1758
-
1759
-
1760
- This action supports [React locators](https://codecept.io/react#locators)
1761
-
1762
-
1763
- ### seeTextEquals
1764
-
1765
- Checks that text is equal to provided one.
1766
-
1767
- ```js
1768
- I.seeTextEquals('text', 'h1');
1769
- ```
1770
-
1771
- #### Parameters
1772
-
1773
- - `text` **[string][6]** element value to check.
1774
- - `context` **([string][6] | [object][4])?** element located by CSS|XPath|strict locator.
1775
-
1776
- Returns **void** automatically synchronized promise through #recorder
1777
-
1778
- ### seeTitleEquals
1779
-
1780
- Checks that title is equal to provided one.
1781
-
1782
- ```js
1783
- I.seeTitleEquals('Test title.');
1784
- ```
1785
-
1786
- #### Parameters
1787
-
1788
- - `text` **[string][6]** value to check.
1789
-
1790
- Returns **void** automatically synchronized promise through #recorder
1791
-
1792
- ### selectOption
1793
-
1794
- Selects an option in a drop-down select.
1795
- Field is searched by label | name | CSS | XPath.
1796
- Option is selected by visible text or by value.
1797
-
1798
- ```js
1799
- I.selectOption('Choose Plan', 'Monthly'); // select by label
1800
- I.selectOption('subscription', 'Monthly'); // match option by text
1801
- I.selectOption('subscription', '0'); // or by value
1802
- I.selectOption('//form/select[@name=account]','Premium');
1803
- I.selectOption('form select[name=account]', 'Premium');
1804
- I.selectOption({css: 'form select[name=account]'}, 'Premium');
1805
- ```
1806
-
1807
- Provide an array for the second argument to select multiple options.
1808
-
1809
- ```js
1810
- I.selectOption('Which OS do you use?', ['Android', 'iOS']);
1811
- ```
1812
-
1813
- #### Parameters
1814
-
1815
- - `select` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator.
1816
- - `option` **([string][6] | [Array][15]&lt;any>)** visible text or value of option.
1817
-
1818
- Returns **void** automatically synchronized promise through #recorder
1819
-
1820
- ### setCookie
1821
-
1822
- Sets cookie(s).
1823
-
1824
- Can be a single cookie object or an array of cookies:
1825
-
1826
- ```js
1827
- I.setCookie({name: 'auth', value: true});
1828
-
1829
- // as array
1830
- I.setCookie([
1831
- {name: 'auth', value: true},
1832
- {name: 'agree', value: true}
1833
- ]);
1834
- ```
1835
-
1836
- #### Parameters
1837
-
1838
- - `cookie` **(Cookie | [Array][15]&lt;Cookie>)** a cookie object or array of cookie objects.
1839
-
1840
- Returns **void** automatically synchronized promise through #recorder
1841
-
1842
- ### setPuppeteerRequestHeaders
1843
-
1844
- Set headers for all next requests
1845
-
1846
- ```js
1847
- I.setPuppeteerRequestHeaders({
1848
- 'X-Sent-By': 'CodeceptJS',
1849
- });
1850
- ```
1851
-
1852
- #### Parameters
1853
-
1854
- - `customHeaders` **[object][4]** headers to set
1855
-
1856
- ### switchTo
1857
-
1858
- Switches frame or in case of null locator reverts to parent.
1859
-
1860
- ```js
1861
- I.switchTo('iframe'); // switch to first iframe
1862
- I.switchTo(); // switch back to main page
1863
- ```
1864
-
1865
- #### Parameters
1866
-
1867
- - `locator` **([string][6]? | [object][4])** (optional, `null` by default) element located by CSS|XPath|strict locator.
1868
-
1869
- Returns **void** automatically synchronized promise through #recorder
1870
-
1871
- ### switchToNextTab
1872
-
1873
- Switch focus to a particular tab by its number. It waits tabs loading and then switch tab
1874
-
1875
- ```js
1876
- I.switchToNextTab();
1877
- I.switchToNextTab(2);
1878
- ```
1879
-
1880
- #### Parameters
1881
-
1882
- - `num` **[number][10]**
1883
-
1884
- ### switchToPreviousTab
1885
-
1886
- Switch focus to a particular tab by its number. It waits tabs loading and then switch tab
1887
-
1888
- ```js
1889
- I.switchToPreviousTab();
1890
- I.switchToPreviousTab(2);
1891
- ```
1892
-
1893
- #### Parameters
1894
-
1895
- - `num` **[number][10]**
1896
-
1897
- ### type
1898
-
1899
- Types out the given text into an active field.
1900
- To slow down typing use a second parameter, to set interval between key presses.
1901
- _Note:_ Should be used when [`fillField`][17] is not an option.
1902
-
1903
- ```js
1904
- // passing in a string
1905
- I.type('Type this out.');
1906
-
1907
- // typing values with a 100ms interval
1908
- I.type('4141555311111111', 100);
1909
-
1910
- // passing in an array
1911
- I.type(['T', 'E', 'X', 'T']);
1912
-
1913
- // passing a secret
1914
- I.type(secret('123456'));
1915
- ```
1916
-
1917
- #### Parameters
1918
-
1919
- - `keys`
1920
- - `delay` **[number][10]?** (optional) delay in ms between key presses
1921
- - `key` **([string][6] | [Array][15]&lt;[string][6]>)** or array of keys to type.
1922
-
1923
- Returns **void** automatically synchronized promise through #recorder
1924
-
1925
- ### uncheckOption
1926
-
1927
- Unselects a checkbox or radio button.
1928
- Element is located by label or name or CSS or XPath.
1929
-
1930
- The second parameter is a context (CSS or XPath locator) to narrow the search.
1931
-
1932
- ```js
1933
- I.uncheckOption('#agree');
1934
- I.uncheckOption('I Agree to Terms and Conditions');
1935
- I.uncheckOption('agree', '//form');
1936
- ```
1937
-
1938
- #### Parameters
1939
-
1940
- - `field` **([string][6] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator.
1941
- - `context` **([string][6]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator.
1942
-
1943
- Returns **void** automatically synchronized promise through #recorder
1944
-
1945
- ### usePuppeteerTo
1946
-
1947
- Use Puppeteer API inside a test.
1948
-
1949
- First argument is a description of an action.
1950
- Second argument is async function that gets this helper as parameter.
1951
-
1952
- { [`page`][21], [`browser`][22] } from Puppeteer API are available.
1953
-
1954
- ```js
1955
- I.usePuppeteerTo('emulate offline mode', async ({ page }) {
1956
- await page.setOfflineMode(true);
1957
- });
1958
- ```
1959
-
1960
- #### Parameters
1961
-
1962
- - `description` **[string][6]** used to show in logs.
1963
- - `fn` **[function][12]** async function that is executed with Puppeteer as argument
1964
-
1965
- ### wait
1966
-
1967
- Pauses execution for a number of seconds.
1968
-
1969
- ```js
1970
- I.wait(2); // wait 2 secs
1971
- ```
1972
-
1973
- #### Parameters
1974
-
1975
- - `sec` **[number][10]** number of second to wait.
1976
-
1977
- Returns **void** automatically synchronized promise through #recorder
1978
-
1979
- ### waitForClickable
1980
-
1981
- Waits for element to be clickable (by default waits for 1sec).
1982
- Element can be located by CSS or XPath.
1983
-
1984
- ```js
1985
- I.waitForClickable('.btn.continue');
1986
- I.waitForClickable('.btn.continue', 5); // wait for 5 secs
1987
- ```
1988
-
1989
- #### Parameters
1990
-
1991
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
1992
- - `waitTimeout`
1993
- - `sec` **[number][10]?** (optional, `1` by default) time in seconds to wait
1994
-
1995
- Returns **void** automatically synchronized promise through #recorder
1996
-
1997
- ### waitForDetached
1998
-
1999
- Waits for an element to become not attached to the DOM on a page (by default waits for 1sec).
2000
- Element can be located by CSS or XPath.
2001
-
2002
- ```js
2003
- I.waitForDetached('#popup');
2004
- ```
2005
-
2006
- #### Parameters
2007
-
2008
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2009
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2010
-
2011
- Returns **void** automatically synchronized promise through #recorder
2012
-
2013
- ### waitForElement
2014
-
2015
- Waits for element to be present on page (by default waits for 1sec).
2016
- Element can be located by CSS or XPath.
2017
-
2018
- ```js
2019
- I.waitForElement('.btn.continue');
2020
- I.waitForElement('.btn.continue', 5); // wait for 5 secs
2021
- ```
2022
-
2023
- #### Parameters
2024
-
2025
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2026
- - `sec` **[number][10]?** (optional, `1` by default) time in seconds to wait
2027
-
2028
- Returns **void** automatically synchronized promise through #recorder
2029
-
2030
-
2031
- This action supports [React locators](https://codecept.io/react#locators)
2032
-
2033
-
2034
- ### waitForEnabled
2035
-
2036
- Waits for element to become enabled (by default waits for 1sec).
2037
- Element can be located by CSS or XPath.
2038
-
2039
- #### Parameters
2040
-
2041
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2042
- - `sec` **[number][10]** (optional) time in seconds to wait, 1 by default.
2043
-
2044
- Returns **void** automatically synchronized promise through #recorder
2045
-
2046
- ### waitForFunction
2047
-
2048
- Waits for a function to return true (waits for 1 sec by default).
2049
- Running in browser context.
2050
-
2051
- ```js
2052
- I.waitForFunction(fn[, [args[, timeout]])
2053
- ```
2054
-
2055
- ```js
2056
- I.waitForFunction(() => window.requests == 0);
2057
- I.waitForFunction(() => window.requests == 0, 5); // waits for 5 sec
2058
- I.waitForFunction((count) => window.requests == count, [3], 5) // pass args and wait for 5 sec
2059
- ```
2060
-
2061
- #### Parameters
2062
-
2063
- - `fn` **([string][6] | [function][12])** to be executed in browser context.
2064
- - `argsOrSec` **([Array][15]&lt;any> | [number][10])?** (optional, `1` by default) arguments for function or seconds.
2065
- - `sec` **[number][10]?** (optional, `1` by default) time in seconds to wait
2066
-
2067
- Returns **void** automatically synchronized promise through #recorder
2068
-
2069
- ### waitForInvisible
2070
-
2071
- Waits for an element to be removed or become invisible on a page (by default waits for 1sec).
2072
- Element can be located by CSS or XPath.
2073
-
2074
- ```js
2075
- I.waitForInvisible('#popup');
2076
- ```
2077
-
2078
- #### Parameters
2079
-
2080
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2081
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2082
-
2083
- Returns **void** automatically synchronized promise through #recorder
2084
-
2085
- ### waitForNavigation
2086
-
2087
- Waits for navigation to finish. By default takes configured `waitForNavigation` option.
2088
-
2089
- See [Pupeteer's reference][23]
2090
-
2091
- #### Parameters
2092
-
2093
- - `opts` **any**
2094
-
2095
- ### waitForRequest
2096
-
2097
- Waits for a network request.
2098
-
2099
- ```js
2100
- I.waitForRequest('http://example.com/resource');
2101
- I.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET');
2102
- ```
2103
-
2104
- #### Parameters
2105
-
2106
- - `urlOrPredicate` **([string][6] | [function][12])**
2107
- - `sec` **[number][10]?** seconds to wait
2108
-
2109
- ### waitForResponse
2110
-
2111
- Waits for a network response.
2112
-
2113
- ```js
2114
- I.waitForResponse('http://example.com/resource');
2115
- I.waitForResponse(response => response.url() === 'http://example.com' && response.request().method() === 'GET');
2116
- ```
2117
-
2118
- #### Parameters
2119
-
2120
- - `urlOrPredicate` **([string][6] | [function][12])**
2121
- - `sec` **[number][10]?** number of seconds to wait
2122
-
2123
- ### waitForText
2124
-
2125
- Waits for a text to appear (by default waits for 1sec).
2126
- Element can be located by CSS or XPath.
2127
- Narrow down search results by providing context.
2128
-
2129
- ```js
2130
- I.waitForText('Thank you, form has been submitted');
2131
- I.waitForText('Thank you, form has been submitted', 5, '#modal');
2132
- ```
2133
-
2134
- #### Parameters
2135
-
2136
- - `text` **[string][6]** to wait for.
2137
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2138
- - `context` **([string][6] | [object][4])?** (optional) element located by CSS|XPath|strict locator.
2139
-
2140
- Returns **void** automatically synchronized promise through #recorder
2141
-
2142
- ### waitForValue
2143
-
2144
- Waits for the specified value to be in value attribute.
2145
-
2146
- ```js
2147
- I.waitForValue('//input', "GoodValue");
2148
- ```
2149
-
2150
- #### Parameters
2151
-
2152
- - `field` **([string][6] | [object][4])** input field.
2153
- - `value` **[string][6]** expected value.
2154
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2155
-
2156
- Returns **void** automatically synchronized promise through #recorder
2157
-
2158
- ### waitForVisible
2159
-
2160
- Waits for an element to become visible on a page (by default waits for 1sec).
2161
- Element can be located by CSS or XPath.
2162
-
2163
- ```js
2164
- I.waitForVisible('#popup');
2165
- ```
2166
-
2167
- #### Parameters
2168
-
2169
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2170
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2171
-
2172
- Returns **void** automatically synchronized promise through #recorderThis method accepts [React selectors][24].
2173
-
2174
- ### waitInUrl
2175
-
2176
- Waiting for the part of the URL to match the expected. Useful for SPA to understand that page was changed.
2177
-
2178
- ```js
2179
- I.waitInUrl('/info', 2);
2180
- ```
2181
-
2182
- #### Parameters
2183
-
2184
- - `urlPart` **[string][6]** value to check.
2185
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2186
-
2187
- Returns **void** automatically synchronized promise through #recorder
2188
-
2189
- ### waitNumberOfVisibleElements
2190
-
2191
- Waits for a specified number of elements on the page.
2192
-
2193
- ```js
2194
- I.waitNumberOfVisibleElements('a', 3);
2195
- ```
2196
-
2197
- #### Parameters
2198
-
2199
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2200
- - `num` **[number][10]** number of elements.
2201
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2202
-
2203
- Returns **void** automatically synchronized promise through #recorder
2204
-
2205
-
2206
- This action supports [React locators](https://codecept.io/react#locators)
2207
-
2208
-
2209
- ### waitToHide
2210
-
2211
- Waits for an element to hide (by default waits for 1sec).
2212
- Element can be located by CSS or XPath.
2213
-
2214
- ```js
2215
- I.waitToHide('#popup');
2216
- ```
2217
-
2218
- #### Parameters
2219
-
2220
- - `locator` **([string][6] | [object][4])** element located by CSS|XPath|strict locator.
2221
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2222
-
2223
- Returns **void** automatically synchronized promise through #recorder
2224
-
2225
- ### waitUrlEquals
2226
-
2227
- Waits for the entire URL to match the expected
2228
-
2229
- ```js
2230
- I.waitUrlEquals('/info', 2);
2231
- I.waitUrlEquals('http://127.0.0.1:8000/info');
2232
- ```
2233
-
2234
- #### Parameters
2235
-
2236
- - `urlPart` **[string][6]** value to check.
2237
- - `sec` **[number][10]** (optional, `1` by default) time in seconds to wait
2238
-
2239
- Returns **void** automatically synchronized promise through #recorder
2240
-
2241
- [1]: https://github.com/GoogleChrome/puppeteer
2242
-
2243
- [2]: https://codecept.io/helpers/Puppeteer-firefox
2244
-
2245
- [3]: https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target
2246
-
2247
- [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
2248
-
2249
- [5]: http://jster.net/category/windows-modals-popups
2250
-
2251
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
2252
-
2253
- [7]: https://github.com/puppeteer/puppeteer/issues/5420
2254
-
2255
- [8]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
2256
-
2257
- [9]: https://playwright.dev/docs/api/class-locator#locator-blur
2258
-
2259
- [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
2260
-
2261
- [11]: https://vuejs.org/v2/api/#Vue-nextTick
2262
-
2263
- [12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
2264
-
2265
- [13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
2266
-
2267
- [14]: https://playwright.dev/docs/api/class-locator#locator-focus
2268
-
2269
- [15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
2270
-
2271
- [16]: https://codecept.io/helpers/FileSystem
2272
-
2273
- [17]: #fillfield
2274
-
2275
- [18]: https://github.com/GoogleChrome/puppeteer/issues/1313
2276
-
2277
- [19]: #click
2278
-
2279
- [20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
2280
-
2281
- [21]: https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-page
2282
-
2283
- [22]: https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-browser
2284
-
2285
- [23]: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagewaitfornavigationoptions
2286
-
2287
- [24]: https://codecept.io/react
2288
-
2289
- [25]: https://pptr.dev/api/puppeteer.tracing
2290
-
2291
- [26]: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions