codeceptjs 3.5.0 → 3.5.1-2.beta.7

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