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