codeceptjs 3.5.10 → 3.5.12-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/README.md +3 -3
  2. package/lib/command/run-multiple.js +3 -1
  3. package/lib/command/run-workers.js +32 -1
  4. package/lib/command/workers/runTests.js +18 -2
  5. package/lib/helper/Expect.js +33 -33
  6. package/lib/helper/Playwright.js +49 -26
  7. package/lib/helper/Puppeteer.js +41 -19
  8. package/lib/helper/WebDriver.js +155 -48
  9. package/lib/helper/extras/PlaywrightReactVueLocator.js +38 -0
  10. package/lib/locator.js +17 -4
  11. package/lib/plugin/retryFailedStep.js +6 -2
  12. package/lib/plugin/retryTo.js +2 -2
  13. package/lib/plugin/tryTo.js +5 -4
  14. package/package.json +25 -22
  15. package/typings/index.d.ts +8 -5
  16. package/typings/promiseBasedTypes.d.ts +203 -75
  17. package/typings/types.d.ts +213 -145
  18. package/docs/advanced.md +0 -351
  19. package/docs/ai.md +0 -248
  20. package/docs/api.md +0 -323
  21. package/docs/basics.md +0 -979
  22. package/docs/bdd.md +0 -539
  23. package/docs/best.md +0 -237
  24. package/docs/books.md +0 -37
  25. package/docs/bootstrap.md +0 -135
  26. package/docs/build/ApiDataFactory.js +0 -410
  27. package/docs/build/Appium.js +0 -2027
  28. package/docs/build/Expect.js +0 -422
  29. package/docs/build/FileSystem.js +0 -228
  30. package/docs/build/GraphQL.js +0 -229
  31. package/docs/build/GraphQLDataFactory.js +0 -309
  32. package/docs/build/JSONResponse.js +0 -338
  33. package/docs/build/Mochawesome.js +0 -71
  34. package/docs/build/Nightmare.js +0 -2152
  35. package/docs/build/OpenAI.js +0 -126
  36. package/docs/build/Playwright.js +0 -5078
  37. package/docs/build/Protractor.js +0 -2706
  38. package/docs/build/Puppeteer.js +0 -3874
  39. package/docs/build/REST.js +0 -344
  40. package/docs/build/TestCafe.js +0 -2125
  41. package/docs/build/WebDriver.js +0 -4124
  42. package/docs/changelog.md +0 -2572
  43. package/docs/commands.md +0 -266
  44. package/docs/community-helpers.md +0 -58
  45. package/docs/configuration.md +0 -157
  46. package/docs/continuous-integration.md +0 -22
  47. package/docs/custom-helpers.md +0 -306
  48. package/docs/data.md +0 -379
  49. package/docs/detox.md +0 -235
  50. package/docs/docker.md +0 -136
  51. package/docs/email.md +0 -183
  52. package/docs/examples.md +0 -149
  53. package/docs/helpers/ApiDataFactory.md +0 -266
  54. package/docs/helpers/Appium.md +0 -1374
  55. package/docs/helpers/Detox.md +0 -586
  56. package/docs/helpers/Expect.md +0 -275
  57. package/docs/helpers/FileSystem.md +0 -152
  58. package/docs/helpers/GraphQL.md +0 -151
  59. package/docs/helpers/GraphQLDataFactory.md +0 -226
  60. package/docs/helpers/JSONResponse.md +0 -254
  61. package/docs/helpers/Mochawesome.md +0 -8
  62. package/docs/helpers/MockRequest.md +0 -377
  63. package/docs/helpers/Nightmare.md +0 -1305
  64. package/docs/helpers/OpenAI.md +0 -70
  65. package/docs/helpers/Playwright.md +0 -2706
  66. package/docs/helpers/Polly.md +0 -44
  67. package/docs/helpers/Protractor.md +0 -1769
  68. package/docs/helpers/Puppeteer-firefox.md +0 -86
  69. package/docs/helpers/Puppeteer.md +0 -2291
  70. package/docs/helpers/REST.md +0 -218
  71. package/docs/helpers/TestCafe.md +0 -1321
  72. package/docs/helpers/WebDriver.md +0 -2460
  73. package/docs/hooks.md +0 -340
  74. package/docs/index.md +0 -111
  75. package/docs/installation.md +0 -75
  76. package/docs/internal-api.md +0 -266
  77. package/docs/locators.md +0 -331
  78. package/docs/mobile-react-native-locators.md +0 -67
  79. package/docs/mobile.md +0 -338
  80. package/docs/pageobjects.md +0 -291
  81. package/docs/parallel.md +0 -400
  82. package/docs/playwright.md +0 -632
  83. package/docs/plugins.md +0 -1259
  84. package/docs/puppeteer.md +0 -316
  85. package/docs/quickstart.md +0 -162
  86. package/docs/react.md +0 -69
  87. package/docs/reports.md +0 -392
  88. package/docs/secrets.md +0 -36
  89. package/docs/shadow.md +0 -68
  90. package/docs/shared/keys.mustache +0 -31
  91. package/docs/shared/react.mustache +0 -1
  92. package/docs/testcafe.md +0 -174
  93. package/docs/translation.md +0 -247
  94. package/docs/tutorial.md +0 -271
  95. package/docs/typescript.md +0 -180
  96. package/docs/ui.md +0 -59
  97. package/docs/videos.md +0 -28
  98. package/docs/visual.md +0 -202
  99. package/docs/vue.md +0 -121
  100. package/docs/webapi/amOnPage.mustache +0 -11
  101. package/docs/webapi/appendField.mustache +0 -11
  102. package/docs/webapi/attachFile.mustache +0 -12
  103. package/docs/webapi/blur.mustache +0 -18
  104. package/docs/webapi/checkOption.mustache +0 -13
  105. package/docs/webapi/clearCookie.mustache +0 -9
  106. package/docs/webapi/clearField.mustache +0 -9
  107. package/docs/webapi/click.mustache +0 -25
  108. package/docs/webapi/clickLink.mustache +0 -8
  109. package/docs/webapi/closeCurrentTab.mustache +0 -7
  110. package/docs/webapi/closeOtherTabs.mustache +0 -8
  111. package/docs/webapi/dontSee.mustache +0 -11
  112. package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
  113. package/docs/webapi/dontSeeCookie.mustache +0 -8
  114. package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
  115. package/docs/webapi/dontSeeElement.mustache +0 -8
  116. package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
  117. package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
  118. package/docs/webapi/dontSeeInField.mustache +0 -11
  119. package/docs/webapi/dontSeeInSource.mustache +0 -8
  120. package/docs/webapi/dontSeeInTitle.mustache +0 -8
  121. package/docs/webapi/doubleClick.mustache +0 -13
  122. package/docs/webapi/downloadFile.mustache +0 -12
  123. package/docs/webapi/dragAndDrop.mustache +0 -9
  124. package/docs/webapi/dragSlider.mustache +0 -11
  125. package/docs/webapi/executeAsyncScript.mustache +0 -24
  126. package/docs/webapi/executeScript.mustache +0 -26
  127. package/docs/webapi/fillField.mustache +0 -16
  128. package/docs/webapi/focus.mustache +0 -13
  129. package/docs/webapi/forceClick.mustache +0 -28
  130. package/docs/webapi/forceRightClick.mustache +0 -18
  131. package/docs/webapi/grabAllWindowHandles.mustache +0 -7
  132. package/docs/webapi/grabAttributeFrom.mustache +0 -10
  133. package/docs/webapi/grabAttributeFromAll.mustache +0 -9
  134. package/docs/webapi/grabBrowserLogs.mustache +0 -9
  135. package/docs/webapi/grabCookie.mustache +0 -11
  136. package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
  137. package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
  138. package/docs/webapi/grabCurrentUrl.mustache +0 -9
  139. package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
  140. package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
  141. package/docs/webapi/grabElementBoundingRect.mustache +0 -20
  142. package/docs/webapi/grabGeoLocation.mustache +0 -8
  143. package/docs/webapi/grabHTMLFrom.mustache +0 -10
  144. package/docs/webapi/grabHTMLFromAll.mustache +0 -9
  145. package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
  146. package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
  147. package/docs/webapi/grabPageScrollPosition.mustache +0 -8
  148. package/docs/webapi/grabPopupText.mustache +0 -5
  149. package/docs/webapi/grabSource.mustache +0 -8
  150. package/docs/webapi/grabTextFrom.mustache +0 -10
  151. package/docs/webapi/grabTextFromAll.mustache +0 -9
  152. package/docs/webapi/grabTitle.mustache +0 -8
  153. package/docs/webapi/grabValueFrom.mustache +0 -9
  154. package/docs/webapi/grabValueFromAll.mustache +0 -8
  155. package/docs/webapi/grabWebElement.mustache +0 -9
  156. package/docs/webapi/grabWebElements.mustache +0 -9
  157. package/docs/webapi/moveCursorTo.mustache +0 -12
  158. package/docs/webapi/openNewTab.mustache +0 -7
  159. package/docs/webapi/pressKey.mustache +0 -12
  160. package/docs/webapi/pressKeyDown.mustache +0 -12
  161. package/docs/webapi/pressKeyUp.mustache +0 -12
  162. package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
  163. package/docs/webapi/refreshPage.mustache +0 -6
  164. package/docs/webapi/resizeWindow.mustache +0 -6
  165. package/docs/webapi/rightClick.mustache +0 -14
  166. package/docs/webapi/saveElementScreenshot.mustache +0 -10
  167. package/docs/webapi/saveScreenshot.mustache +0 -12
  168. package/docs/webapi/say.mustache +0 -10
  169. package/docs/webapi/scrollIntoView.mustache +0 -11
  170. package/docs/webapi/scrollPageToBottom.mustache +0 -6
  171. package/docs/webapi/scrollPageToTop.mustache +0 -6
  172. package/docs/webapi/scrollTo.mustache +0 -12
  173. package/docs/webapi/see.mustache +0 -11
  174. package/docs/webapi/seeAttributesOnElements.mustache +0 -9
  175. package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
  176. package/docs/webapi/seeCookie.mustache +0 -8
  177. package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
  178. package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
  179. package/docs/webapi/seeElement.mustache +0 -8
  180. package/docs/webapi/seeElementInDOM.mustache +0 -8
  181. package/docs/webapi/seeInCurrentUrl.mustache +0 -8
  182. package/docs/webapi/seeInField.mustache +0 -12
  183. package/docs/webapi/seeInPopup.mustache +0 -8
  184. package/docs/webapi/seeInSource.mustache +0 -7
  185. package/docs/webapi/seeInTitle.mustache +0 -8
  186. package/docs/webapi/seeNumberOfElements.mustache +0 -11
  187. package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
  188. package/docs/webapi/seeTextEquals.mustache +0 -9
  189. package/docs/webapi/seeTitleEquals.mustache +0 -8
  190. package/docs/webapi/selectOption.mustache +0 -21
  191. package/docs/webapi/setCookie.mustache +0 -16
  192. package/docs/webapi/setGeoLocation.mustache +0 -12
  193. package/docs/webapi/switchTo.mustache +0 -9
  194. package/docs/webapi/switchToNextTab.mustache +0 -10
  195. package/docs/webapi/switchToPreviousTab.mustache +0 -10
  196. package/docs/webapi/type.mustache +0 -21
  197. package/docs/webapi/uncheckOption.mustache +0 -13
  198. package/docs/webapi/wait.mustache +0 -8
  199. package/docs/webapi/waitForClickable.mustache +0 -11
  200. package/docs/webapi/waitForDetached.mustache +0 -10
  201. package/docs/webapi/waitForElement.mustache +0 -11
  202. package/docs/webapi/waitForEnabled.mustache +0 -6
  203. package/docs/webapi/waitForFunction.mustache +0 -17
  204. package/docs/webapi/waitForInvisible.mustache +0 -10
  205. package/docs/webapi/waitForText.mustache +0 -13
  206. package/docs/webapi/waitForValue.mustache +0 -10
  207. package/docs/webapi/waitForVisible.mustache +0 -10
  208. package/docs/webapi/waitInUrl.mustache +0 -9
  209. package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
  210. package/docs/webapi/waitToHide.mustache +0 -10
  211. package/docs/webapi/waitUrlEquals.mustache +0 -10
  212. package/docs/webdriver.md +0 -655
  213. package/docs/wiki/Books-&-Posts.md +0 -27
  214. package/docs/wiki/Community-Helpers-&-Plugins.md +0 -53
  215. package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -61
  216. package/docs/wiki/Examples.md +0 -145
  217. package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
  218. package/docs/wiki/Home.md +0 -16
  219. package/docs/wiki/Migration-to-Appium-v2---CodeceptJS.md +0 -83
  220. package/docs/wiki/Release-Process.md +0 -24
  221. package/docs/wiki/Roadmap.md +0 -23
  222. package/docs/wiki/Tests.md +0 -1393
  223. package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
  224. package/docs/wiki/Videos.md +0 -19
  225. package/lib/helper/extras/PlaywrightReact.js +0 -9
@@ -1,2706 +0,0 @@
1
- ---
2
- permalink: /helpers/Playwright
3
- editLink: false
4
- sidebar: auto
5
- title: Playwright
6
- ---
7
-
8
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9
-
10
- ## Playwright
11
-
12
- **Extends Helper**
13
-
14
- Uses [Playwright][1] library to run tests inside:
15
-
16
- - Chromium
17
- - Firefox
18
- - Webkit (Safari)
19
-
20
- This helper works with a browser out of the box with no additional tools required to install.
21
-
22
- Requires `playwright` or `playwright-core` package version ^1 to be installed:
23
-
24
- npm i playwright@^1.18 --save
25
-
26
- or
27
-
28
- npm i playwright-core@^1.18 --save
29
-
30
- Breaking Changes: if you use Playwright v1.38 and later, it will no longer download browsers automatically.
31
-
32
- Run `npx playwright install` to download browsers after `npm install`.
33
-
34
- Using playwright-core package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
35
-
36
-
37
-
38
- ## Configuration
39
-
40
- This helper should be configured in codecept.conf.(js|ts)
41
-
42
- Type: [object][6]
43
-
44
- ### Properties
45
-
46
- - `url` **[string][9]?** base url of website to be tested
47
- - `browser` **(`"chromium"` | `"firefox"` | `"webkit"` | `"electron"`)?** a browser to test on, either: `chromium`, `firefox`, `webkit`, `electron`. Default: chromium.
48
- - `show` **[boolean][26]?** show browser window.
49
- - `restart` **([string][9] | [boolean][26])?** restart strategy between tests. Possible values:- 'context' or **false** - restarts [browser context][44] but keeps running browser. Recommended by Playwright team to keep tests isolated.
50
- - 'browser' or **true** - closes browser and opens it again between tests.
51
- - 'session' or 'keep' - keeps browser context and session, but cleans up cookies and localStorage between tests. The fastest option when running tests in windowed mode. Works with `keepCookies` and `keepBrowserState` options. This behavior was default before CodeceptJS 3.1
52
- - `timeout` **[number][20]?** - [timeout][45] in ms of all Playwright actions .
53
- - `disableScreenshots` **[boolean][26]?** don't save screenshot on failure.
54
- - `emulate` **any?** browser in device emulation mode.
55
- - `video` **[boolean][26]?** enables video recording for failed tests; videos are saved into `output/videos` folder
56
- - `keepVideoForPassedTests` **[boolean][26]?** save videos for passed tests; videos are saved into `output/videos` folder
57
- - `trace` **[boolean][26]?** record [tracing information][46] with screenshots and snapshots.
58
- - `keepTraceForPassedTests` **[boolean][26]?** save trace for passed tests.
59
- - `fullPageScreenshots` **[boolean][26]?** make full page screenshots on failure.
60
- - `uniqueScreenshotNames` **[boolean][26]?** option to prevent screenshot override if you have scenarios with the same name in different suites.
61
- - `keepBrowserState` **[boolean][26]?** keep browser state between tests when `restart` is set to 'session'.
62
- - `keepCookies` **[boolean][26]?** keep cookies between tests when `restart` is set to 'session'.
63
- - `waitForAction` **[number][20]?** how long to wait after click, doubleClick or PressKey actions in ms. Default: 100.
64
- - `waitForNavigation` **(`"load"` | `"domcontentloaded"` | `"commit"`)?** When to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `commit`. Choose one of those options is possible. See [Playwright API][42].
65
- - `pressKeyDelay` **[number][20]?** Delay between key presses in ms. Used when calling Playwrights page.type(...) in fillField/appendField
66
- - `getPageTimeout` **[number][20]?** config option to set maximum navigation time in milliseconds.
67
- - `waitForTimeout` **[number][20]?** default wait* timeout in ms. Default: 1000.
68
- - `basicAuth` **[object][6]?** the basic authentication to pass to base url. Example: {username: 'username', password: 'password'}
69
- - `windowSize` **[string][9]?** default window size. Set a dimension like `640x480`.
70
- - `colorScheme` **(`"dark"` | `"light"` | `"no-preference"`)?** default color scheme. Possible values: `dark` | `light` | `no-preference`.
71
- - `userAgent` **[string][9]?** user-agent string.
72
- - `locale` **[string][9]?** locale string. Example: 'en-GB', 'de-DE', 'fr-FR', ...
73
- - `manualStart` **[boolean][26]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Playwright"]._startBrowser()`.
74
- - `chromium` **[object][6]?** pass additional chromium options
75
- - `firefox` **[object][6]?** pass additional firefox options
76
- - `electron` **[object][6]?** (pass additional electron options
77
- - `channel` **any?** (While Playwright can operate against the stock Google Chrome and Microsoft Edge browsers available on the machine. In particular, current Playwright version will support Stable and Beta channels of these browsers. See [Google Chrome & Microsoft Edge][47].
78
- - `ignoreLog` **[Array][10]&lt;[string][9]>?** An array with console message types that are not logged to debug log. Default value is `['warning', 'log']`. E.g. you can set `[]` to log all messages. See all possible [values][48].
79
- - `ignoreHTTPSErrors` **[boolean][26]?** Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false`
80
- - `bypassCSP` **[boolean][26]?** bypass Content Security Policy or CSP
81
- - `highlightElement` **[boolean][26]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
82
- - `recordHar` **[object][6]?** record HAR and will be saved to `output/har`. See more of [HAR options][3].
83
-
84
-
85
-
86
- #### Video Recording Customization
87
-
88
- By default, video is saved to `output/video` dir. You can customize this path by passing `dir` option to `recordVideo` option.
89
-
90
- `video`: enables video recording for failed tests; videos are saved into `output/videos` folder
91
-
92
- - `keepVideoForPassedTests`: - save videos for passed tests
93
- - `recordVideo`: [additional options for videos customization][2]
94
-
95
- #### Trace Recording Customization
96
-
97
- Trace recording provides complete information on test execution and includes DOM snapshots, screenshots, and network requests logged during run.
98
- Traces will be saved to `output/trace`
99
-
100
- - `trace`: enables trace recording for failed tests; trace are saved into `output/trace` folder
101
- - `keepTraceForPassedTests`: - save trace for passed tests
102
-
103
- #### HAR Recording Customization
104
-
105
- A HAR file is an HTTP Archive file that contains a record of all the network requests that are made when a page is loaded.
106
- It contains information about the request and response headers, cookies, content, timings, and more. You can use HAR files to mock network requests in your tests.
107
- HAR will be saved to `output/har`. More info could be found here [https://playwright.dev/docs/api/class-browser#browser-new-context-option-record-har][3].
108
-
109
- ...
110
- recordHar: {
111
- mode: 'minimal', // possible values: 'minimal'|'full'.
112
- content: 'embed' // possible values: "omit"|"embed"|"attach".
113
- }
114
- ...
115
-
116
- #### Example #1: Wait for 0 network connections.
117
-
118
- ```js
119
- {
120
- helpers: {
121
- Playwright : {
122
- url: "http://localhost",
123
- restart: false,
124
- waitForNavigation: "networkidle0",
125
- waitForAction: 500
126
- }
127
- }
128
- }
129
- ```
130
-
131
- #### Example #2: Wait for DOMContentLoaded event
132
-
133
- ```js
134
- {
135
- helpers: {
136
- Playwright : {
137
- url: "http://localhost",
138
- restart: false,
139
- waitForNavigation: "domcontentloaded",
140
- waitForAction: 500
141
- }
142
- }
143
- }
144
- ```
145
-
146
- #### Example #3: Debug in window mode
147
-
148
- ```js
149
- {
150
- helpers: {
151
- Playwright : {
152
- url: "http://localhost",
153
- show: true
154
- }
155
- }
156
- }
157
- ```
158
-
159
- #### Example #4: Connect to remote browser by specifying [websocket endpoint][4]
160
-
161
- ```js
162
- {
163
- helpers: {
164
- Playwright: {
165
- url: "http://localhost",
166
- chromium: {
167
- browserWSEndpoint: 'ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a',
168
- cdpConnection: false // default is false
169
- }
170
- }
171
- }
172
- }
173
- ```
174
-
175
- #### Example #5: Testing with Chromium extensions
176
-
177
- [official docs][5]
178
-
179
- ```js
180
- {
181
- helpers: {
182
- Playwright: {
183
- url: "http://localhost",
184
- show: true // headless mode not supported for extensions
185
- chromium: {
186
- // Note: due to this would launch persistent context, so to avoid the error when running tests with run-workers a timestamp would be appended to the defined folder name. For instance: playwright-tmp_1692715649511
187
- userDataDir: '/tmp/playwright-tmp', // necessary to launch the browser in normal mode instead of incognito,
188
- args: [
189
- `--disable-extensions-except=${pathToExtension}`,
190
- `--load-extension=${pathToExtension}`
191
- ]
192
- }
193
- }
194
- }
195
- }
196
- ```
197
-
198
- #### Example #6: Launch tests emulating iPhone 6
199
-
200
- ```js
201
- const { devices } = require('playwright');
202
-
203
- {
204
- helpers: {
205
- Playwright: {
206
- url: "http://localhost",
207
- emulate: devices['iPhone 6'],
208
- }
209
- }
210
- }
211
- ```
212
-
213
- #### Example #7: Launch test with a specific user locale
214
-
215
- ```js
216
- {
217
- helpers: {
218
- Playwright : {
219
- url: "http://localhost",
220
- locale: "fr-FR",
221
- }
222
- }
223
- }
224
- ```
225
-
226
- - #### Example #8: Launch test with a specific color scheme
227
-
228
- ```js
229
- {
230
- helpers: {
231
- Playwright : {
232
- url: "http://localhost",
233
- colorScheme: "dark",
234
- }
235
- }
236
- }
237
- ```
238
-
239
- - #### Example #9: Launch electron test
240
-
241
- ```js
242
- {
243
- helpers: {
244
- Playwright: {
245
- browser: 'electron',
246
- electron: {
247
- executablePath: require("electron"),
248
- args: [path.join('../', "main.js")],
249
- },
250
- }
251
- },
252
- }
253
- ```
254
-
255
- Note: When connecting to remote browser `show` and specific `chrome` options (e.g. `headless` or `devtools`) are ignored.
256
-
257
- ## Access From Helpers
258
-
259
- Receive Playwright client from a custom helper by accessing `browser` for the Browser object or `page` for the current Page object:
260
-
261
- ```js
262
- const { browser } = this.helpers.Playwright;
263
- await browser.pages(); // List of pages in the browser
264
-
265
- // get current page
266
- const { page } = this.helpers.Playwright;
267
- await page.url(); // Get the url of the current page
268
-
269
- const { browserContext } = this.helpers.Playwright;
270
- await browserContext.cookies(); // get current browser context
271
- ```
272
-
273
- ### Parameters
274
-
275
- - `config`
276
-
277
- ### _addPopupListener
278
-
279
- Add the 'dialog' event listener to a page
280
-
281
- #### Parameters
282
-
283
- - `page`
284
-
285
- ### _contextLocator
286
-
287
- Grab Locator if called within Context
288
-
289
- #### Parameters
290
-
291
- - `locator` **any**
292
-
293
- ### _createContextPage
294
-
295
- Create a new browser context with a page.
296
- Usually it should be run from a custom helper after call of `_startBrowser()`
297
-
298
- #### Parameters
299
-
300
- - `contextOptions` **[object][6]?** See [https://playwright.dev/docs/api/class-browser#browser-new-context][7]
301
-
302
- ### _getPageUrl
303
-
304
- Gets page URL including hash.
305
-
306
- ### _locate
307
-
308
- Get elements by different locator types, including strict locator
309
- Should be used in custom helpers:
310
-
311
- ```js
312
- const elements = await this.helpers['Playwright']._locate({name: 'password'});
313
- ```
314
-
315
- #### Parameters
316
-
317
- - `locator`
318
-
319
- ### _locateCheckable
320
-
321
- Find a checkbox by providing human-readable text:
322
- NOTE: Assumes the checkable element exists
323
-
324
- ```js
325
- this.helpers['Playwright']._locateCheckable('I agree with terms and conditions').then // ...
326
- ```
327
-
328
- #### Parameters
329
-
330
- - `locator`
331
- - `providedContext`
332
-
333
- ### _locateClickable
334
-
335
- Find a clickable element by providing human-readable text:
336
-
337
- ```js
338
- this.helpers['Playwright']._locateClickable('Next page').then // ...
339
- ```
340
-
341
- #### Parameters
342
-
343
- - `locator`
344
-
345
- ### _locateElement
346
-
347
- Get the first element by different locator types, including strict locator
348
- Should be used in custom helpers:
349
-
350
- ```js
351
- const element = await this.helpers['Playwright']._locateElement({name: 'password'});
352
- ```
353
-
354
- #### Parameters
355
-
356
- - `locator`
357
-
358
- ### _locateFields
359
-
360
- Find field elements by providing human-readable text:
361
-
362
- ```js
363
- this.helpers['Playwright']._locateFields('Your email').then // ...
364
- ```
365
-
366
- #### Parameters
367
-
368
- - `locator`
369
-
370
- ### _setPage
371
-
372
- Set current page
373
-
374
- #### Parameters
375
-
376
- - `page` **[object][6]** page to set
377
-
378
- ### acceptPopup
379
-
380
- Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt.
381
- Don't confuse popups with modal windows, as created by [various
382
- libraries][8].
383
-
384
- ### amAcceptingPopups
385
-
386
- Set the automatic popup response to Accept.
387
- This must be set before a popup is triggered.
388
-
389
- ```js
390
- I.amAcceptingPopups();
391
- I.click('#triggerPopup');
392
- I.acceptPopup();
393
- ```
394
-
395
- ### amCancellingPopups
396
-
397
- Set the automatic popup response to Cancel/Dismiss.
398
- This must be set before a popup is triggered.
399
-
400
- ```js
401
- I.amCancellingPopups();
402
- I.click('#triggerPopup');
403
- I.cancelPopup();
404
- ```
405
-
406
- ### amOnPage
407
-
408
- Opens a web page in a browser. Requires relative or absolute url.
409
- If url starts with `/`, opens a web page of a site defined in `url` config parameter.
410
-
411
- ```js
412
- I.amOnPage('/'); // opens main page of website
413
- I.amOnPage('https://github.com'); // opens github
414
- I.amOnPage('/login'); // opens a login page
415
- ```
416
-
417
- #### Parameters
418
-
419
- - `url` **[string][9]** url path or global url.
420
-
421
- Returns **void** automatically synchronized promise through #recorder
422
-
423
- ### appendField
424
-
425
- Appends text to a input field or textarea.
426
- Field is located by name, label, CSS or XPath
427
-
428
- ```js
429
- I.appendField('#myTextField', 'appended');
430
- // typing secret
431
- I.appendField('password', secret('123456'));
432
- ```
433
-
434
- #### Parameters
435
-
436
- - `field` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator
437
- - `value` **[string][9]** text value to append.
438
-
439
- Returns **void** automatically synchronized promise through #recorder
440
-
441
- ### attachFile
442
-
443
- Attaches a file to element located by label, name, CSS or XPath
444
- Path to file is relative current codecept directory (where codecept.conf.ts or codecept.conf.js is located).
445
- File will be uploaded to remote system (if tests are running remotely).
446
-
447
- ```js
448
- I.attachFile('Avatar', 'data/avatar.jpg');
449
- I.attachFile('form input[name=avatar]', 'data/avatar.jpg');
450
- ```
451
-
452
- #### Parameters
453
-
454
- - `locator` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
455
- - `pathToFile` **[string][9]** local file path relative to codecept.conf.ts or codecept.conf.js config file.
456
-
457
- Returns **void** automatically synchronized promise through #recorder
458
-
459
- ### blockTraffic
460
-
461
- Blocks traffic of a given URL or a list of URLs.
462
-
463
- Examples:
464
-
465
- ```js
466
- I.blockTraffic('http://example.com/css/style.css');
467
- I.blockTraffic('http://example.com/css/*.css');
468
- I.blockTraffic('http://example.com/**');
469
- I.blockTraffic(/.css$/);
470
- ```
471
-
472
- ```js
473
- I.blockTraffic(['http://example.com/css/style.css', 'http://example.com/css/*.css']);
474
- ```
475
-
476
- #### Parameters
477
-
478
- - `urls` **([string][9] | [Array][10] | [RegExp][11])** URL or a list of URLs to block . URL can contain * for wildcards. Example: [https://www.example.com**][12] to block all traffic for that domain. Regexp are also supported.
479
-
480
- ### blur
481
-
482
- Remove focus from a text input, button, etc.
483
- Calls [blur][13] on the element.
484
-
485
- Examples:
486
-
487
- ```js
488
- I.blur('.text-area')
489
- ```
490
-
491
- ```js
492
- //element `#product-tile` is focused
493
- I.see('#add-to-cart-btn');
494
- I.blur('#product-tile')
495
- I.dontSee('#add-to-cart-btn');
496
- ```
497
-
498
- #### Parameters
499
-
500
- - `locator` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
501
- - `options` **any?** Playwright only: [Additional options][14] for available options object as 2nd argument.
502
-
503
- Returns **void** automatically synchronized promise through #recorder
504
-
505
- ### cancelPopup
506
-
507
- Dismisses the active JavaScript popup, as created by window.alert|window.confirm|window.prompt.
508
-
509
- ### checkOption
510
-
511
- Selects a checkbox or radio button.
512
- Element is located by label or name or CSS or XPath.
513
-
514
- The second parameter is a context (CSS or XPath locator) to narrow the search.
515
-
516
- ```js
517
- I.checkOption('#agree');
518
- I.checkOption('I Agree to Terms and Conditions');
519
- I.checkOption('agree', '//form');
520
- ```
521
-
522
- #### Parameters
523
-
524
- - `field` **([string][9] | [object][6])** checkbox located by label | name | CSS | XPath | strict locator.
525
- - `context` **([string][9]? | [object][6])** (optional, `null` by default) element located by CSS | XPath | strict locator.
526
- - `options`
527
-
528
- Returns **void** automatically synchronized promise through #recorder[Additional options][15] for check available as 3rd argument.Examples:```js
529
- // click on element at position
530
- I.checkOption('Agree', '.signup', { position: { x: 5, y: 5 } })
531
- ```> ⚠️ To avoid flakiness, option `force: true` is set by default
532
-
533
- ### clearCookie
534
-
535
- Clears a cookie by name,
536
- if none provided clears all cookies.
537
-
538
- ```js
539
- I.clearCookie();
540
- I.clearCookie('test'); // Playwright currently doesn't support clear a particular cookie name
541
- ```
542
-
543
- #### Parameters
544
-
545
- - `cookie` **[string][9]?** (optional, `null` by default) cookie name
546
-
547
- ### clearField
548
-
549
- Clears the text input element: `<input>`, `<textarea>` or `[contenteditable]` .
550
-
551
- Examples:
552
-
553
- ```js
554
- I.clearField('.text-area')
555
-
556
- // if this doesn't work use force option
557
- I.clearField('#submit', { force: true })
558
- ```
559
-
560
- Use `force` to bypass the [actionability][16] checks.
561
-
562
- #### Parameters
563
-
564
- - `locator` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
565
- - `options` **any?** [Additional options][17] for available options object as 2nd argument.
566
-
567
- ### click
568
-
569
- Perform a click on a link or a button, given by a locator.
570
- If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
571
- For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
572
- For images, the "alt" attribute and inner text of any parent links are searched.
573
-
574
- The second parameter is a context (CSS or XPath locator) to narrow the search.
575
-
576
- ```js
577
- // simple link
578
- I.click('Logout');
579
- // button of form
580
- I.click('Submit');
581
- // CSS button
582
- I.click('#form input[type=submit]');
583
- // XPath
584
- I.click('//form/*[@type=submit]');
585
- // link in context
586
- I.click('Logout', '#nav');
587
- // using strict locator
588
- I.click({css: 'nav a.login'});
589
- ```
590
-
591
- #### Parameters
592
-
593
- - `locator` **([string][9] | [object][6])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
594
- - `context` **([string][9]? | [object][6] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
595
- - `options` **any?** [Additional options][18] for click available as 3rd argument.Examples:```js
596
- // click on element at position
597
- I.click('canvas', '.model', { position: { x: 20, y: 40 } })
598
-
599
- // make ctrl-click
600
- I.click('.edit', null, { modifiers: ['Ctrl'] } )
601
- ```
602
-
603
- Returns **void** automatically synchronized promise through #recorder
604
-
605
- ### clickLink
606
-
607
- Clicks link and waits for navigation (deprecated)
608
-
609
- #### Parameters
610
-
611
- - `locator`
612
- - `context`
613
-
614
- ### closeCurrentTab
615
-
616
- Close current tab and switches to previous.
617
-
618
- ```js
619
- I.closeCurrentTab();
620
- ```
621
-
622
- ### closeOtherTabs
623
-
624
- Close all tabs except for the current one.
625
-
626
- ```js
627
- I.closeOtherTabs();
628
- ```
629
-
630
- ### dontSee
631
-
632
- Opposite to `see`. Checks that a text is not present on a page.
633
- Use context parameter to narrow down the search.
634
-
635
- ```js
636
- I.dontSee('Login'); // assume we are already logged in.
637
- I.dontSee('Login', '.nav'); // no login inside .nav element
638
- ```
639
-
640
- #### Parameters
641
-
642
- - `text` **[string][9]** which is not present.
643
- - `context` **([string][9] | [object][6])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search.
644
-
645
- Returns **void** automatically synchronized promise through #recorder
646
-
647
- ### dontSeeCheckboxIsChecked
648
-
649
- Verifies that the specified checkbox is not checked.
650
-
651
- ```js
652
- I.dontSeeCheckboxIsChecked('#agree'); // located by ID
653
- I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label
654
- I.dontSeeCheckboxIsChecked('agree'); // located by name
655
- ```
656
-
657
- #### Parameters
658
-
659
- - `field` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator.
660
-
661
- Returns **void** automatically synchronized promise through #recorder
662
-
663
- ### dontSeeCookie
664
-
665
- Checks that cookie with given name does not exist.
666
-
667
- ```js
668
- I.dontSeeCookie('auth'); // no auth cookie
669
- ```
670
-
671
- #### Parameters
672
-
673
- - `name` **[string][9]** cookie name.
674
-
675
- Returns **void** automatically synchronized promise through #recorder
676
-
677
- ### dontSeeCurrentUrlEquals
678
-
679
- Checks that current url is not equal to provided one.
680
- If a relative url provided, a configured url will be prepended to it.
681
-
682
- ```js
683
- I.dontSeeCurrentUrlEquals('/login'); // relative url are ok
684
- I.dontSeeCurrentUrlEquals('http://mysite.com/login'); // absolute urls are also ok
685
- ```
686
-
687
- #### Parameters
688
-
689
- - `url` **[string][9]** value to check.
690
-
691
- Returns **void** automatically synchronized promise through #recorder
692
-
693
- ### dontSeeElement
694
-
695
- Opposite to `seeElement`. Checks that element is not visible (or in DOM)
696
-
697
- ```js
698
- I.dontSeeElement('.modal'); // modal is not shown
699
- ```
700
-
701
- #### Parameters
702
-
703
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|Strict locator.
704
-
705
- Returns **void** automatically synchronized promise through #recorder
706
-
707
- ### dontSeeElementInDOM
708
-
709
- Opposite to `seeElementInDOM`. Checks that element is not on page.
710
-
711
- ```js
712
- I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not
713
- ```
714
-
715
- #### Parameters
716
-
717
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|Strict locator.
718
-
719
- Returns **void** automatically synchronized promise through #recorder
720
-
721
- ### dontSeeInCurrentUrl
722
-
723
- Checks that current url does not contain a provided fragment.
724
-
725
- #### Parameters
726
-
727
- - `url` **[string][9]** value to check.
728
-
729
- Returns **void** automatically synchronized promise through #recorder
730
-
731
- ### dontSeeInField
732
-
733
- Checks that value of input field or textarea doesn't equal to given value
734
- Opposite to `seeInField`.
735
-
736
- ```js
737
- I.dontSeeInField('email', 'user@user.com'); // field by name
738
- I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
739
- ```
740
-
741
- #### Parameters
742
-
743
- - `field` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator.
744
- - `value` **([string][9] | [object][6])** value to check.
745
-
746
- Returns **void** automatically synchronized promise through #recorder
747
-
748
- ### dontSeeInSource
749
-
750
- Checks that the current page does not contains the given string in its raw source code.
751
-
752
- ```js
753
- I.dontSeeInSource('<!--'); // no comments in source
754
- ```
755
-
756
- #### Parameters
757
-
758
- - `text`
759
- - `value` **[string][9]** to check.
760
-
761
- Returns **void** automatically synchronized promise through #recorder
762
-
763
- ### dontSeeInTitle
764
-
765
- Checks that title does not contain text.
766
-
767
- ```js
768
- I.dontSeeInTitle('Error');
769
- ```
770
-
771
- #### Parameters
772
-
773
- - `text` **[string][9]** value to check.
774
-
775
- Returns **void** automatically synchronized promise through #recorder
776
-
777
- ### dontSeeTraffic
778
-
779
- Verifies that a certain request is not part of network traffic.
780
-
781
- Examples:
782
-
783
- ```js
784
- I.dontSeeTraffic({ name: 'Unexpected API Call', url: 'https://api.example.com' });
785
- I.dontSeeTraffic({ name: 'Unexpected API Call of "user" endpoint', url: /api.example.com.*user/ });
786
- ```
787
-
788
- #### Parameters
789
-
790
- - `opts` **[Object][6]** options when checking the traffic network.
791
- - `opts.name` **[string][9]** A name of that request. Can be any value. Only relevant to have a more meaningful error message in case of fail.
792
- - `opts.url` **([string][9] | [RegExp][11])** Expected URL of request in network traffic. Can be a string or a regular expression.
793
-
794
- ### doubleClick
795
-
796
- Performs a double-click on an element matched by link|button|label|CSS or XPath.
797
- Context can be specified as second parameter to narrow search.
798
-
799
- ```js
800
- I.doubleClick('Edit');
801
- I.doubleClick('Edit', '.actions');
802
- I.doubleClick({css: 'button.accept'});
803
- I.doubleClick('.btn.edit');
804
- ```
805
-
806
- #### Parameters
807
-
808
- - `locator` **([string][9] | [object][6])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
809
- - `context` **([string][9]? | [object][6])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
810
-
811
- Returns **void** automatically synchronized promise through #recorder
812
-
813
- ### dragAndDrop
814
-
815
- Drag an item to a destination element.
816
-
817
- ```js
818
- I.dragAndDrop('#dragHandle', '#container');
819
- ```
820
-
821
- #### Parameters
822
-
823
- - `srcElement` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
824
- - `destElement` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
825
- - `options` **any?** [Additional options][19] can be passed as 3rd argument.```js
826
- // specify coordinates for source position
827
- I.dragAndDrop('img.src', 'img.dst', { sourcePosition: {x: 10, y: 10} })
828
- ```> When no option is set, custom drag and drop would be used, to use the dragAndDrop API from Playwright, please set options, for example `force: true`
829
-
830
- Returns **void** automatically synchronized promise through #recorder
831
-
832
- ### dragSlider
833
-
834
- Drag the scrubber of a slider to a given position
835
- For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
836
-
837
- ```js
838
- I.dragSlider('#slider', 30);
839
- I.dragSlider('#slider', -70);
840
- ```
841
-
842
- #### Parameters
843
-
844
- - `locator` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator.
845
- - `offsetX` **[number][20]** position to drag.
846
-
847
- Returns **void** automatically synchronized promise through #recorder
848
-
849
- ### executeScript
850
-
851
- Executes a script on the page:
852
-
853
- ```js
854
- I.executeScript(() => window.alert('Hello world'));
855
- ```
856
-
857
- Additional parameters of the function can be passed as an object argument:
858
-
859
- ```js
860
- I.executeScript(({x, y}) => x + y, {x, y});
861
- ```
862
-
863
- You can pass only one parameter into a function
864
- but you can pass in array or object.
865
-
866
- ```js
867
- I.executeScript(([x, y]) => x + y, [x, y]);
868
- ```
869
-
870
- If a function returns a Promise it will wait for its resolution.
871
-
872
- #### Parameters
873
-
874
- - `fn` **([string][9] | [function][21])** function to be executed in browser context.
875
- - `arg` **any?** optional argument to pass to the function
876
-
877
- Returns **[Promise][22]&lt;any>**
878
-
879
- ### fillField
880
-
881
- Fills a text field or textarea, after clearing its value, with the given string.
882
- Field is located by name, label, CSS, or XPath.
883
-
884
- ```js
885
- // by label
886
- I.fillField('Email', 'hello@world.com');
887
- // by name
888
- I.fillField('password', secret('123456'));
889
- // by CSS
890
- I.fillField('form#login input[name=username]', 'John');
891
- // or by strict locator
892
- I.fillField({css: 'form#login input[name=username]'}, 'John');
893
- ```
894
-
895
- #### Parameters
896
-
897
- - `field` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator.
898
- - `value` **([string][9] | [object][6])** text value to fill.
899
-
900
- Returns **void** automatically synchronized promise through #recorder
901
-
902
- ### flushNetworkTraffics
903
-
904
- Resets all recorded network requests.
905
-
906
- ### flushWebSocketMessages
907
-
908
- Resets all recorded WS messages.
909
-
910
- ### focus
911
-
912
- Calls [focus][13] on the matching element.
913
-
914
- Examples:
915
-
916
- ```js
917
- I.dontSee('#add-to-cart-btn');
918
- I.focus('#product-tile')
919
- I.see('#add-to-cart-bnt');
920
- ```
921
-
922
- #### Parameters
923
-
924
- - `locator` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
925
- - `options` **any?** Playwright only: [Additional options][23] for available options object as 2nd argument.
926
-
927
- Returns **void** automatically synchronized promise through #recorder
928
-
929
- ### forceClick
930
-
931
- Perform an emulated click on a link or a button, given by a locator.
932
- Unlike normal click instead of sending native event, emulates a click with JavaScript.
933
- This works on hidden, animated or inactive elements as well.
934
-
935
- If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
936
- For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
937
- For images, the "alt" attribute and inner text of any parent links are searched.
938
-
939
- The second parameter is a context (CSS or XPath locator) to narrow the search.
940
-
941
- ```js
942
- // simple link
943
- I.forceClick('Logout');
944
- // button of form
945
- I.forceClick('Submit');
946
- // CSS button
947
- I.forceClick('#form input[type=submit]');
948
- // XPath
949
- I.forceClick('//form/*[@type=submit]');
950
- // link in context
951
- I.forceClick('Logout', '#nav');
952
- // using strict locator
953
- I.forceClick({css: 'nav a.login'});
954
- ```
955
-
956
- #### Parameters
957
-
958
- - `locator` **([string][9] | [object][6])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
959
- - `context` **([string][9]? | [object][6])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
960
-
961
- Returns **void** automatically synchronized promise through #recorder
962
-
963
- ### grabAttributeFrom
964
-
965
- Retrieves an attribute from an element located by CSS or XPath and returns it to test.
966
- Resumes test execution, so **should be used inside async with `await`** operator.
967
- If more than one element is found - attribute of first element is returned.
968
-
969
- ```js
970
- let hint = await I.grabAttributeFrom('#tooltip', 'title');
971
- ```
972
-
973
- #### Parameters
974
-
975
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
976
- - `attr` **[string][9]** attribute name.
977
-
978
- Returns **[Promise][22]&lt;[string][9]>** attribute value
979
-
980
- ### grabAttributeFromAll
981
-
982
- Retrieves an array of attributes from elements located by CSS or XPath and returns it to test.
983
- Resumes test execution, so **should be used inside async with `await`** operator.
984
-
985
- ```js
986
- let hints = await I.grabAttributeFromAll('.tooltip', 'title');
987
- ```
988
-
989
- #### Parameters
990
-
991
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
992
- - `attr` **[string][9]** attribute name.
993
-
994
- Returns **[Promise][22]&lt;[Array][10]&lt;[string][9]>>** attribute value
995
-
996
- ### grabBrowserLogs
997
-
998
- Get JS log from browser.
999
-
1000
- ```js
1001
- const logs = await I.grabBrowserLogs();
1002
- const errors = logs.map(l => ({ type: l.type(), text: l.text() })).filter(l => l.type === 'error');
1003
- console.log(JSON.stringify(errors));
1004
- ```
1005
-
1006
- [Learn more about console messages][24]
1007
-
1008
- Returns **[Promise][22]&lt;[Array][10]&lt;any>>**
1009
-
1010
- ### grabCheckedElementStatus
1011
-
1012
- Return the checked status of given element.
1013
-
1014
- #### Parameters
1015
-
1016
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1017
- - `options` **[object][6]?** See [https://playwright.dev/docs/api/class-locator#locator-is-checked][25]
1018
-
1019
- Returns **[Promise][22]&lt;[boolean][26]>**
1020
-
1021
- ### grabCookie
1022
-
1023
- Gets a cookie object by name.
1024
- If none provided gets all cookies.
1025
- Resumes test execution, so **should be used inside async function with `await`** operator.
1026
-
1027
- ```js
1028
- let cookie = await I.grabCookie('auth');
1029
- assert(cookie.value, '123456');
1030
- ```
1031
-
1032
- #### Parameters
1033
-
1034
- - `name` **[string][9]?** cookie name.
1035
-
1036
- Returns **any** attribute valueReturns cookie in JSON format. If name not passed returns all cookies for this domain.
1037
-
1038
- ### grabCssPropertyFrom
1039
-
1040
- Grab CSS property for given locator
1041
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1042
- If more than one element is found - value of first element is returned.
1043
-
1044
- ```js
1045
- const value = await I.grabCssPropertyFrom('h3', 'font-weight');
1046
- ```
1047
-
1048
- #### Parameters
1049
-
1050
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1051
- - `cssProperty` **[string][9]** CSS property name.
1052
-
1053
- Returns **[Promise][22]&lt;[string][9]>** CSS value
1054
-
1055
- ### grabCssPropertyFromAll
1056
-
1057
- Grab array of CSS properties for given locator
1058
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1059
-
1060
- ```js
1061
- const values = await I.grabCssPropertyFromAll('h3', 'font-weight');
1062
- ```
1063
-
1064
- #### Parameters
1065
-
1066
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1067
- - `cssProperty` **[string][9]** CSS property name.
1068
-
1069
- Returns **[Promise][22]&lt;[Array][10]&lt;[string][9]>>** CSS value
1070
-
1071
- ### grabCurrentUrl
1072
-
1073
- Get current URL from browser.
1074
- Resumes test execution, so should be used inside an async function.
1075
-
1076
- ```js
1077
- let url = await I.grabCurrentUrl();
1078
- console.log(`Current URL is [${url}]`);
1079
- ```
1080
-
1081
- Returns **[Promise][22]&lt;[string][9]>** current URL
1082
-
1083
- ### grabDataFromPerformanceTiming
1084
-
1085
- Grab the data from performance timing using Navigation Timing API.
1086
- The returned data will contain following things in ms:
1087
-
1088
- - responseEnd,
1089
- - domInteractive,
1090
- - domContentLoadedEventEnd,
1091
- - loadEventEnd
1092
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1093
-
1094
- ```js
1095
- await I.amOnPage('https://example.com');
1096
- let data = await I.grabDataFromPerformanceTiming();
1097
- //Returned data
1098
- { // all results are in [ms]
1099
- responseEnd: 23,
1100
- domInteractive: 44,
1101
- domContentLoadedEventEnd: 196,
1102
- loadEventEnd: 241
1103
- }
1104
- ```
1105
-
1106
- Returns **void** automatically synchronized promise through #recorder
1107
-
1108
- ### grabDisabledElementStatus
1109
-
1110
- Return the disabled status of given element.
1111
-
1112
- #### Parameters
1113
-
1114
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1115
- - `options` **[object][6]?** See [https://playwright.dev/docs/api/class-locator#locator-is-disabled][27]
1116
-
1117
- Returns **[Promise][22]&lt;[boolean][26]>**
1118
-
1119
- ### grabElementBoundingRect
1120
-
1121
- Grab the width, height, location of given locator.
1122
- Provide `width` or `height`as second param to get your desired prop.
1123
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1124
-
1125
- Returns an object with `x`, `y`, `width`, `height` keys.
1126
-
1127
- ```js
1128
- const value = await I.grabElementBoundingRect('h3');
1129
- // value is like { x: 226.5, y: 89, width: 527, height: 220 }
1130
- ```
1131
-
1132
- To get only one metric use second parameter:
1133
-
1134
- ```js
1135
- const width = await I.grabElementBoundingRect('h3', 'width');
1136
- // width == 527
1137
- ```
1138
-
1139
- #### Parameters
1140
-
1141
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1142
- - `prop`
1143
- - `elementSize` **[string][9]?** x, y, width or height of the given element.
1144
-
1145
- Returns **([Promise][22]&lt;DOMRect> | [Promise][22]&lt;[number][20]>)** Element bounding rectangle
1146
-
1147
- ### grabHTMLFrom
1148
-
1149
- Retrieves the innerHTML from an element located by CSS or XPath and returns it to test.
1150
- Resumes test execution, so **should be used inside async function with `await`** operator.
1151
- If more than one element is found - HTML of first element is returned.
1152
-
1153
- ```js
1154
- let postHTML = await I.grabHTMLFrom('#post');
1155
- ```
1156
-
1157
- #### Parameters
1158
-
1159
- - `locator`
1160
- - `element` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1161
-
1162
- Returns **[Promise][22]&lt;[string][9]>** HTML code for an element
1163
-
1164
- ### grabHTMLFromAll
1165
-
1166
- Retrieves all the innerHTML from elements located by CSS or XPath and returns it to test.
1167
- Resumes test execution, so **should be used inside async function with `await`** operator.
1168
-
1169
- ```js
1170
- let postHTMLs = await I.grabHTMLFromAll('.post');
1171
- ```
1172
-
1173
- #### Parameters
1174
-
1175
- - `locator`
1176
- - `element` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1177
-
1178
- Returns **[Promise][22]&lt;[Array][10]&lt;[string][9]>>** HTML code for an element
1179
-
1180
- ### grabMetrics
1181
-
1182
- Return a performance metric from the chrome cdp session.
1183
- Note: Chrome-only
1184
-
1185
- Examples:
1186
-
1187
- ```js
1188
- const metrics = await I.grabMetrics();
1189
-
1190
- // returned metrics
1191
-
1192
- [
1193
- { name: 'Timestamp', value: 1584904.203473 },
1194
- { name: 'AudioHandlers', value: 0 },
1195
- { name: 'AudioWorkletProcessors', value: 0 },
1196
- { name: 'Documents', value: 22 },
1197
- { name: 'Frames', value: 10 },
1198
- { name: 'JSEventListeners', value: 366 },
1199
- { name: 'LayoutObjects', value: 1240 },
1200
- { name: 'MediaKeySessions', value: 0 },
1201
- { name: 'MediaKeys', value: 0 },
1202
- { name: 'Nodes', value: 4505 },
1203
- { name: 'Resources', value: 141 },
1204
- { name: 'ContextLifecycleStateObservers', value: 34 },
1205
- { name: 'V8PerContextDatas', value: 4 },
1206
- { name: 'WorkerGlobalScopes', value: 0 },
1207
- { name: 'UACSSResources', value: 0 },
1208
- { name: 'RTCPeerConnections', value: 0 },
1209
- { name: 'ResourceFetchers', value: 22 },
1210
- { name: 'AdSubframes', value: 0 },
1211
- { name: 'DetachedScriptStates', value: 2 },
1212
- { name: 'ArrayBufferContents', value: 1 },
1213
- { name: 'LayoutCount', value: 0 },
1214
- { name: 'RecalcStyleCount', value: 0 },
1215
- { name: 'LayoutDuration', value: 0 },
1216
- { name: 'RecalcStyleDuration', value: 0 },
1217
- { name: 'DevToolsCommandDuration', value: 0.000013 },
1218
- { name: 'ScriptDuration', value: 0 },
1219
- { name: 'V8CompileDuration', value: 0 },
1220
- { name: 'TaskDuration', value: 0.000014 },
1221
- { name: 'TaskOtherDuration', value: 0.000001 },
1222
- { name: 'ThreadTime', value: 0.000046 },
1223
- { name: 'ProcessTime', value: 0.616852 },
1224
- { name: 'JSHeapUsedSize', value: 19004908 },
1225
- { name: 'JSHeapTotalSize', value: 26820608 },
1226
- { name: 'FirstMeaningfulPaint', value: 0 },
1227
- { name: 'DomContentLoaded', value: 1584903.690491 },
1228
- { name: 'NavigationStart', value: 1584902.841845 }
1229
- ]
1230
- ```
1231
-
1232
- Returns **[Promise][22]&lt;[Array][10]&lt;[Object][6]>>**
1233
-
1234
- ### grabNumberOfOpenTabs
1235
-
1236
- Grab number of open tabs.
1237
- Resumes test execution, so **should be used inside async function with `await`** operator.
1238
-
1239
- ```js
1240
- let tabs = await I.grabNumberOfOpenTabs();
1241
- ```
1242
-
1243
- Returns **[Promise][22]&lt;[number][20]>** number of open tabs
1244
-
1245
- ### grabNumberOfVisibleElements
1246
-
1247
- Grab number of visible elements by locator.
1248
- Resumes test execution, so **should be used inside async function with `await`** operator.
1249
-
1250
- ```js
1251
- let numOfElements = await I.grabNumberOfVisibleElements('p');
1252
- ```
1253
-
1254
- #### Parameters
1255
-
1256
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1257
-
1258
- Returns **[Promise][22]&lt;[number][20]>** number of visible elements
1259
-
1260
- ### grabPageScrollPosition
1261
-
1262
- Retrieves a page scroll position and returns it to test.
1263
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1264
-
1265
- ```js
1266
- let { x, y } = await I.grabPageScrollPosition();
1267
- ```
1268
-
1269
- Returns **[Promise][22]&lt;PageScrollPosition>** scroll position
1270
-
1271
- ### grabPopupText
1272
-
1273
- Grab the text within the popup. If no popup is visible then it will return null
1274
-
1275
- ```js
1276
- await I.grabPopupText();
1277
- ```
1278
-
1279
- Returns **[Promise][22]&lt;([string][9] | null)>**
1280
-
1281
- ### grabRecordedNetworkTraffics
1282
-
1283
- Grab the recording network traffics
1284
-
1285
- ```js
1286
- const traffics = await I.grabRecordedNetworkTraffics();
1287
- expect(traffics[0].url).to.equal('https://reqres.in/api/comments/1');
1288
- expect(traffics[0].response.status).to.equal(200);
1289
- expect(traffics[0].response.body).to.contain({ name: 'this was mocked' });
1290
- ```
1291
-
1292
- Returns **[Promise][22]&lt;[Array][10]&lt;any>>**
1293
-
1294
- ### grabSource
1295
-
1296
- Retrieves page source and returns it to test.
1297
- Resumes test execution, so **should be used inside async function with `await`** operator.
1298
-
1299
- ```js
1300
- let pageSource = await I.grabSource();
1301
- ```
1302
-
1303
- Returns **[Promise][22]&lt;[string][9]>** source code
1304
-
1305
- ### grabTextFrom
1306
-
1307
- Retrieves a text from an element located by CSS or XPath and returns it to test.
1308
- Resumes test execution, so **should be used inside async with `await`** operator.
1309
-
1310
- ```js
1311
- let pin = await I.grabTextFrom('#pin');
1312
- ```
1313
-
1314
- If multiple elements found returns first element.
1315
-
1316
- #### Parameters
1317
-
1318
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1319
-
1320
- Returns **[Promise][22]&lt;[string][9]>** attribute value
1321
-
1322
- ### grabTextFromAll
1323
-
1324
- Retrieves all texts from an element located by CSS or XPath and returns it to test.
1325
- Resumes test execution, so **should be used inside async with `await`** operator.
1326
-
1327
- ```js
1328
- let pins = await I.grabTextFromAll('#pin li');
1329
- ```
1330
-
1331
- #### Parameters
1332
-
1333
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1334
-
1335
- Returns **[Promise][22]&lt;[Array][10]&lt;[string][9]>>** attribute value
1336
-
1337
- ### grabTitle
1338
-
1339
- Retrieves a page title and returns it to test.
1340
- Resumes test execution, so **should be used inside async with `await`** operator.
1341
-
1342
- ```js
1343
- let title = await I.grabTitle();
1344
- ```
1345
-
1346
- Returns **[Promise][22]&lt;[string][9]>** title
1347
-
1348
- ### grabTrafficUrl
1349
-
1350
- Returns full URL of request matching parameter "urlMatch".
1351
-
1352
- #### Parameters
1353
-
1354
- - `urlMatch` **([string][9] | [RegExp][11])** Expected URL of request in network traffic. Can be a string or a regular expression.Examples:```js
1355
- I.grabTrafficUrl('https://api.example.com/session');
1356
- I.grabTrafficUrl(/session.*start/);
1357
- ```
1358
-
1359
- Returns **[Promise][22]&lt;any>**
1360
-
1361
- ### grabValueFrom
1362
-
1363
- Retrieves a value from a form element located by CSS or XPath and returns it to test.
1364
- Resumes test execution, so **should be used inside async function with `await`** operator.
1365
- If more than one element is found - value of first element is returned.
1366
-
1367
- ```js
1368
- let email = await I.grabValueFrom('input[name=email]');
1369
- ```
1370
-
1371
- #### Parameters
1372
-
1373
- - `locator` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
1374
-
1375
- Returns **[Promise][22]&lt;[string][9]>** attribute value
1376
-
1377
- ### grabValueFromAll
1378
-
1379
- Retrieves an array of value from a form located by CSS or XPath and returns it to test.
1380
- Resumes test execution, so **should be used inside async function with `await`** operator.
1381
-
1382
- ```js
1383
- let inputs = await I.grabValueFromAll('//form/input');
1384
- ```
1385
-
1386
- #### Parameters
1387
-
1388
- - `locator` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
1389
-
1390
- Returns **[Promise][22]&lt;[Array][10]&lt;[string][9]>>** attribute value
1391
-
1392
- ### grabWebElement
1393
-
1394
- Grab WebElement for given locator
1395
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1396
-
1397
- ```js
1398
- const webElement = await I.grabWebElement('#button');
1399
- ```
1400
-
1401
- #### Parameters
1402
-
1403
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1404
-
1405
- Returns **[Promise][22]&lt;any>** WebElement of being used Web helper
1406
-
1407
- ### grabWebElements
1408
-
1409
- Grab WebElements for given locator
1410
- Resumes test execution, so **should be used inside an async function with `await`** operator.
1411
-
1412
- ```js
1413
- const webElements = await I.grabWebElements('#button');
1414
- ```
1415
-
1416
- #### Parameters
1417
-
1418
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1419
-
1420
- Returns **[Promise][22]&lt;any>** WebElement of being used Web helper
1421
-
1422
- ### grabWebSocketMessages
1423
-
1424
- Grab the recording WS messages
1425
-
1426
- Returns **[Array][10]&lt;any>**
1427
-
1428
- ### handleDownloads
1429
-
1430
- Handles a file download. A file name is required to save the file on disk.
1431
- Files are saved to "output" directory.
1432
-
1433
- Should be used with [FileSystem helper][28] to check that file were downloaded correctly.
1434
-
1435
- ```js
1436
- I.handleDownloads('downloads/avatar.jpg');
1437
- I.click('Download Avatar');
1438
- I.amInPath('output/downloads');
1439
- I.waitForFile('avatar.jpg', 5);
1440
- ```
1441
-
1442
- #### Parameters
1443
-
1444
- - `fileName` **[string][9]** set filename for downloaded file
1445
-
1446
- Returns **[Promise][22]&lt;void>**
1447
-
1448
- ### makeApiRequest
1449
-
1450
- Performs [api request][29] using
1451
- the cookies from the current browser session.
1452
-
1453
- ```js
1454
- const users = await I.makeApiRequest('GET', '/api/users', { params: { page: 1 }});
1455
- users[0]
1456
- I.makeApiRequest('PATCH', )
1457
- ```
1458
-
1459
- > This is Playwright's built-in alternative to using REST helper's sendGet, sendPost, etc methods.
1460
-
1461
- #### Parameters
1462
-
1463
- - `method` **[string][9]** HTTP method
1464
- - `url` **[string][9]** endpoint
1465
- - `options` **[object][6]** request options depending on method used
1466
-
1467
- Returns **[Promise][22]&lt;[object][6]>** response
1468
-
1469
- ### mockRoute
1470
-
1471
- Mocks network request using [`browserContext.route`][30] of Playwright
1472
-
1473
- ```js
1474
- I.mockRoute(/(.png$)|(.jpg$)/, route => route.abort());
1475
- ```
1476
-
1477
- This method allows intercepting and mocking requests & responses. [Learn more about it][31]
1478
-
1479
- #### Parameters
1480
-
1481
- - `url` **([string][9] | [RegExp][11])?** URL, regex or pattern for to match URL
1482
- - `handler` **[function][21]?** a function to process reques
1483
-
1484
- ### mockTraffic
1485
-
1486
- Mocks traffic for URL(s).
1487
- This is a powerful feature to manipulate network traffic. Can be used e.g. to stabilize your tests, speed up your tests or as a last resort to make some test scenarios even possible.
1488
-
1489
- Examples:
1490
-
1491
- ```js
1492
- I.mockTraffic('/api/users/1', '{ id: 1, name: 'John Doe' }');
1493
- I.mockTraffic('/api/users/*', JSON.stringify({ id: 1, name: 'John Doe' }));
1494
- I.mockTraffic([/^https://api.example.com/v1/, 'https://api.example.com/v2/**'], 'Internal Server Error', 'text/html');
1495
- ```
1496
-
1497
- #### Parameters
1498
-
1499
- - `urls` string|Array These are the URL(s) to mock, e.g. "/fooapi/_" or "['/fooapi_1/_', '/barapi_2/*']". Regular expressions are also supported.
1500
- - `responseString` string The string to return in fake response's body.
1501
- - `contentType` Content type of fake response. If not specified default value 'application/json' is used.
1502
-
1503
- ### moveCursorTo
1504
-
1505
- Moves cursor to element matched by locator.
1506
- Extra shift can be set with offsetX and offsetY options.
1507
-
1508
- ```js
1509
- I.moveCursorTo('.tooltip');
1510
- I.moveCursorTo('#submit', 5,5);
1511
- ```
1512
-
1513
- #### Parameters
1514
-
1515
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1516
- - `offsetX` **[number][20]** (optional, `0` by default) X-axis offset.
1517
- - `offsetY` **[number][20]** (optional, `0` by default) Y-axis offset.
1518
-
1519
- Returns **void** automatically synchronized promise through #recorder
1520
-
1521
- ### openNewTab
1522
-
1523
- Open new tab and automatically switched to new tab
1524
-
1525
- ```js
1526
- I.openNewTab();
1527
- ```
1528
-
1529
- You can pass in [page options][32] to emulate device on this page
1530
-
1531
- ```js
1532
- // enable mobile
1533
- I.openNewTab({ isMobile: true });
1534
- ```
1535
-
1536
- #### Parameters
1537
-
1538
- - `options`
1539
-
1540
- ### pressKey
1541
-
1542
- Presses a key in the browser (on a focused element).
1543
-
1544
- _Hint:_ For populating text field or textarea, it is recommended to use [`fillField`][33].
1545
-
1546
- ```js
1547
- I.pressKey('Backspace');
1548
- ```
1549
-
1550
- 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.
1551
-
1552
- ```js
1553
- I.pressKey(['Control', 'Z']);
1554
- ```
1555
-
1556
- For specifying operation modifier key based on operating system it is suggested to use `'CommandOrControl'`.
1557
- This will press `'Command'` (also known as `'Meta'`) on macOS machines and `'Control'` on non-macOS machines.
1558
-
1559
- ```js
1560
- I.pressKey(['CommandOrControl', 'Z']);
1561
- ```
1562
-
1563
- Some of the supported key names are:
1564
-
1565
- - `'AltLeft'` or `'Alt'`
1566
- - `'AltRight'`
1567
- - `'ArrowDown'`
1568
- - `'ArrowLeft'`
1569
- - `'ArrowRight'`
1570
- - `'ArrowUp'`
1571
- - `'Backspace'`
1572
- - `'Clear'`
1573
- - `'ControlLeft'` or `'Control'`
1574
- - `'ControlRight'`
1575
- - `'Command'`
1576
- - `'CommandOrControl'`
1577
- - `'Delete'`
1578
- - `'End'`
1579
- - `'Enter'`
1580
- - `'Escape'`
1581
- - `'F1'` to `'F12'`
1582
- - `'Home'`
1583
- - `'Insert'`
1584
- - `'MetaLeft'` or `'Meta'`
1585
- - `'MetaRight'`
1586
- - `'Numpad0'` to `'Numpad9'`
1587
- - `'NumpadAdd'`
1588
- - `'NumpadDecimal'`
1589
- - `'NumpadDivide'`
1590
- - `'NumpadMultiply'`
1591
- - `'NumpadSubtract'`
1592
- - `'PageDown'`
1593
- - `'PageUp'`
1594
- - `'Pause'`
1595
- - `'Return'`
1596
- - `'ShiftLeft'` or `'Shift'`
1597
- - `'ShiftRight'`
1598
- - `'Space'`
1599
- - `'Tab'`
1600
-
1601
- #### Parameters
1602
-
1603
- - `key` **([string][9] | [Array][10]&lt;[string][9]>)** key or array of keys to press.
1604
-
1605
- Returns **void** automatically synchronized promise through #recorder_Note:_ Shortcuts like `'Meta'` + `'A'` do not work on macOS ([GoogleChrome/Puppeteer#1313][34]).
1606
-
1607
- ### pressKeyDown
1608
-
1609
- Presses a key in the browser and leaves it in a down state.
1610
-
1611
- To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][35]).
1612
-
1613
- ```js
1614
- I.pressKeyDown('Control');
1615
- I.click('#element');
1616
- I.pressKeyUp('Control');
1617
- ```
1618
-
1619
- #### Parameters
1620
-
1621
- - `key` **[string][9]** name of key to press down.
1622
-
1623
- Returns **void** automatically synchronized promise through #recorder
1624
-
1625
- ### pressKeyUp
1626
-
1627
- Releases a key in the browser which was previously set to a down state.
1628
-
1629
- To make combinations with modifier key and user operation (e.g. `'Control'` + [`click`][35]).
1630
-
1631
- ```js
1632
- I.pressKeyDown('Control');
1633
- I.click('#element');
1634
- I.pressKeyUp('Control');
1635
- ```
1636
-
1637
- #### Parameters
1638
-
1639
- - `key` **[string][9]** name of key to release.
1640
-
1641
- Returns **void** automatically synchronized promise through #recorder
1642
-
1643
- ### refreshPage
1644
-
1645
- Reload the current page.
1646
-
1647
- ```js
1648
- I.refreshPage();
1649
- ```
1650
-
1651
- Returns **void** automatically synchronized promise through #recorder
1652
-
1653
- ### replayFromHar
1654
-
1655
- Replaying from HAR
1656
-
1657
- ```js
1658
- // Replay API requests from HAR.
1659
- // Either use a matching response from the HAR,
1660
- // or abort the request if nothing matches.
1661
- I.replayFromHar('./output/har/something.har', { url: "*/**/api/v1/fruits" });
1662
- I.amOnPage('https://demo.playwright.dev/api-mocking');
1663
- I.see('CodeceptJS');
1664
- ```
1665
-
1666
- #### Parameters
1667
-
1668
- - `harFilePath` **[string][9]** Path to recorded HAR file
1669
- - `opts` **[object][6]?** [Options for replaying from HAR][36]
1670
-
1671
- Returns **any** Promise<void>
1672
-
1673
- ### resizeWindow
1674
-
1675
- Resize the current window to provided width and height.
1676
- First parameter can be set to `maximize`.
1677
-
1678
- #### Parameters
1679
-
1680
- - `width` **[number][20]** width in pixels or `maximize`.
1681
- - `height` **[number][20]** height in pixels.
1682
-
1683
- Returns **void** automatically synchronized promise through #recorderUnlike other drivers Playwright changes the size of a viewport, not the window!
1684
- Playwright does not control the window of a browser so it can't adjust its real size.
1685
- It also can't maximize a window.Update configuration to change real window size on start:```js
1686
- // inside codecept.conf.js
1687
- // @codeceptjs/configure package must be installed
1688
- { setWindowSize } = require('@codeceptjs/configure');
1689
- ```
1690
-
1691
- ### restartBrowser
1692
-
1693
- Restart browser with a new context and a new page
1694
-
1695
- ```js
1696
- // Restart browser and use a new timezone
1697
- I.restartBrowser({ timezoneId: 'America/Phoenix' });
1698
- // Open URL in a new page in changed timezone
1699
- I.amOnPage('/');
1700
- // Restart browser, allow reading/copying of text from/into clipboard in Chrome
1701
- I.restartBrowser({ permissions: ['clipboard-read', 'clipboard-write'] });
1702
- ```
1703
-
1704
- #### Parameters
1705
-
1706
- - `contextOptions` **[object][6]?** [Options for browser context][7] when starting new browser
1707
-
1708
- ### rightClick
1709
-
1710
- Performs right click on a clickable element matched by semantic locator, CSS or XPath.
1711
-
1712
- ```js
1713
- // right click element with id el
1714
- I.rightClick('#el');
1715
- // right click link or button with text "Click me"
1716
- I.rightClick('Click me');
1717
- // right click button with text "Click me" inside .context
1718
- I.rightClick('Click me', '.context');
1719
- ```
1720
-
1721
- #### Parameters
1722
-
1723
- - `locator` **([string][9] | [object][6])** clickable element located by CSS|XPath|strict locator.
1724
- - `context` **([string][9]? | [object][6])** (optional, `null` by default) element located by CSS|XPath|strict locator.
1725
-
1726
- Returns **void** automatically synchronized promise through #recorder
1727
-
1728
- ### saveElementScreenshot
1729
-
1730
- Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
1731
- Filename is relative to output folder.
1732
-
1733
- ```js
1734
- I.saveElementScreenshot(`#submit`,'debug.png');
1735
- ```
1736
-
1737
- #### Parameters
1738
-
1739
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1740
- - `fileName` **[string][9]** file name to save.
1741
-
1742
- Returns **void** automatically synchronized promise through #recorder
1743
-
1744
- ### saveScreenshot
1745
-
1746
- Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
1747
- Filename is relative to output folder.
1748
- 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.
1749
-
1750
- ```js
1751
- I.saveScreenshot('debug.png');
1752
- I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1753
- ```
1754
-
1755
- #### Parameters
1756
-
1757
- - `fileName` **[string][9]** file name to save.
1758
- - `fullPage` **[boolean][26]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1759
-
1760
- Returns **void** automatically synchronized promise through #recorder
1761
-
1762
- ### scrollPageToBottom
1763
-
1764
- Scroll page to the bottom.
1765
-
1766
- ```js
1767
- I.scrollPageToBottom();
1768
- ```
1769
-
1770
- Returns **void** automatically synchronized promise through #recorder
1771
-
1772
- ### scrollPageToTop
1773
-
1774
- Scroll page to the top.
1775
-
1776
- ```js
1777
- I.scrollPageToTop();
1778
- ```
1779
-
1780
- Returns **void** automatically synchronized promise through #recorder
1781
-
1782
- ### scrollTo
1783
-
1784
- Scrolls to element matched by locator.
1785
- Extra shift can be set with offsetX and offsetY options.
1786
-
1787
- ```js
1788
- I.scrollTo('footer');
1789
- I.scrollTo('#submit', 5, 5);
1790
- ```
1791
-
1792
- #### Parameters
1793
-
1794
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1795
- - `offsetX` **[number][20]** (optional, `0` by default) X-axis offset.
1796
- - `offsetY` **[number][20]** (optional, `0` by default) Y-axis offset.
1797
-
1798
- Returns **void** automatically synchronized promise through #recorder
1799
-
1800
- ### see
1801
-
1802
- Checks that a page contains a visible text.
1803
- Use context parameter to narrow down the search.
1804
-
1805
- ```js
1806
- I.see('Welcome'); // text welcome on a page
1807
- I.see('Welcome', '.content'); // text inside .content div
1808
- I.see('Register', {css: 'form.register'}); // use strict locator
1809
- ```
1810
-
1811
- #### Parameters
1812
-
1813
- - `text` **[string][9]** expected on page.
1814
- - `context` **([string][9]? | [object][6])** (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text.
1815
-
1816
- Returns **void** automatically synchronized promise through #recorder
1817
-
1818
- ### seeAttributesOnElements
1819
-
1820
- Checks that all elements with given locator have given attributes.
1821
-
1822
- ```js
1823
- I.seeAttributesOnElements('//form', { method: "post"});
1824
- ```
1825
-
1826
- #### Parameters
1827
-
1828
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1829
- - `attributes` **[object][6]** attributes and their values to check.
1830
-
1831
- Returns **void** automatically synchronized promise through #recorder
1832
-
1833
- ### seeCheckboxIsChecked
1834
-
1835
- Verifies that the specified checkbox is checked.
1836
-
1837
- ```js
1838
- I.seeCheckboxIsChecked('Agree');
1839
- I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
1840
- I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'});
1841
- ```
1842
-
1843
- #### Parameters
1844
-
1845
- - `field` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator.
1846
-
1847
- Returns **void** automatically synchronized promise through #recorder
1848
-
1849
- ### seeCookie
1850
-
1851
- Checks that cookie with given name exists.
1852
-
1853
- ```js
1854
- I.seeCookie('Auth');
1855
- ```
1856
-
1857
- #### Parameters
1858
-
1859
- - `name` **[string][9]** cookie name.
1860
-
1861
- Returns **void** automatically synchronized promise through #recorder
1862
-
1863
- ### seeCssPropertiesOnElements
1864
-
1865
- Checks that all elements with given locator have given CSS properties.
1866
-
1867
- ```js
1868
- I.seeCssPropertiesOnElements('h3', { 'font-weight': "bold"});
1869
- ```
1870
-
1871
- #### Parameters
1872
-
1873
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1874
- - `cssProperties` **[object][6]** object with CSS properties and their values to check.
1875
-
1876
- Returns **void** automatically synchronized promise through #recorder
1877
-
1878
- ### seeCurrentUrlEquals
1879
-
1880
- Checks that current url is equal to provided one.
1881
- If a relative url provided, a configured url will be prepended to it.
1882
- So both examples will work:
1883
-
1884
- ```js
1885
- I.seeCurrentUrlEquals('/register');
1886
- I.seeCurrentUrlEquals('http://my.site.com/register');
1887
- ```
1888
-
1889
- #### Parameters
1890
-
1891
- - `url` **[string][9]** value to check.
1892
-
1893
- Returns **void** automatically synchronized promise through #recorder
1894
-
1895
- ### seeElement
1896
-
1897
- Checks that a given Element is visible
1898
- Element is located by CSS or XPath.
1899
-
1900
- ```js
1901
- I.seeElement('#modal');
1902
- ```
1903
-
1904
- #### Parameters
1905
-
1906
- - `locator` **([string][9] | [object][6])** located by CSS|XPath|strict locator.
1907
-
1908
- Returns **void** automatically synchronized promise through #recorder
1909
-
1910
- ### seeElementInDOM
1911
-
1912
- Checks that a given Element is present in the DOM
1913
- Element is located by CSS or XPath.
1914
-
1915
- ```js
1916
- I.seeElementInDOM('#modal');
1917
- ```
1918
-
1919
- #### Parameters
1920
-
1921
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
1922
-
1923
- Returns **void** automatically synchronized promise through #recorder
1924
-
1925
- ### seeInCurrentUrl
1926
-
1927
- Checks that current url contains a provided fragment.
1928
-
1929
- ```js
1930
- I.seeInCurrentUrl('/register'); // we are on registration page
1931
- ```
1932
-
1933
- #### Parameters
1934
-
1935
- - `url` **[string][9]** a fragment to check
1936
-
1937
- Returns **void** automatically synchronized promise through #recorder
1938
-
1939
- ### seeInField
1940
-
1941
- Checks that the given input field or textarea equals to given value.
1942
- For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
1943
-
1944
- ```js
1945
- I.seeInField('Username', 'davert');
1946
- I.seeInField({css: 'form textarea'},'Type your comment here');
1947
- I.seeInField('form input[type=hidden]','hidden_value');
1948
- I.seeInField('#searchform input','Search');
1949
- ```
1950
-
1951
- #### Parameters
1952
-
1953
- - `field` **([string][9] | [object][6])** located by label|name|CSS|XPath|strict locator.
1954
- - `value` **([string][9] | [object][6])** value to check.
1955
-
1956
- Returns **void** automatically synchronized promise through #recorder
1957
-
1958
- ### seeInPopup
1959
-
1960
- Checks that the active JavaScript popup, as created by `window.alert|window.confirm|window.prompt`, contains the
1961
- given string.
1962
-
1963
- ```js
1964
- I.seeInPopup('Popup text');
1965
- ```
1966
-
1967
- #### Parameters
1968
-
1969
- - `text` **[string][9]** value to check.
1970
-
1971
- Returns **void** automatically synchronized promise through #recorder
1972
-
1973
- ### seeInSource
1974
-
1975
- Checks that the current page contains the given string in its raw source code.
1976
-
1977
- ```js
1978
- I.seeInSource('<h1>Green eggs &amp; ham</h1>');
1979
- ```
1980
-
1981
- #### Parameters
1982
-
1983
- - `text` **[string][9]** value to check.
1984
-
1985
- Returns **void** automatically synchronized promise through #recorder
1986
-
1987
- ### seeInTitle
1988
-
1989
- Checks that title contains text.
1990
-
1991
- ```js
1992
- I.seeInTitle('Home Page');
1993
- ```
1994
-
1995
- #### Parameters
1996
-
1997
- - `text` **[string][9]** text value to check.
1998
-
1999
- Returns **void** automatically synchronized promise through #recorder
2000
-
2001
- ### seeNumberOfElements
2002
-
2003
- Asserts that an element appears a given number of times in the DOM.
2004
- Element is located by label or name or CSS or XPath.
2005
-
2006
- ```js
2007
- I.seeNumberOfElements('#submitBtn', 1);
2008
- ```
2009
-
2010
- #### Parameters
2011
-
2012
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2013
- - `num` **[number][20]** number of elements.
2014
-
2015
- Returns **void** automatically synchronized promise through #recorder
2016
-
2017
- ### seeNumberOfVisibleElements
2018
-
2019
- Asserts that an element is visible a given number of times.
2020
- Element is located by CSS or XPath.
2021
-
2022
- ```js
2023
- I.seeNumberOfVisibleElements('.buttons', 3);
2024
- ```
2025
-
2026
- #### Parameters
2027
-
2028
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2029
- - `num` **[number][20]** number of elements.
2030
-
2031
- Returns **void** automatically synchronized promise through #recorder
2032
-
2033
- ### seeTextEquals
2034
-
2035
- Checks that text is equal to provided one.
2036
-
2037
- ```js
2038
- I.seeTextEquals('text', 'h1');
2039
- ```
2040
-
2041
- #### Parameters
2042
-
2043
- - `text` **[string][9]** element value to check.
2044
- - `context` **([string][9] | [object][6])?** element located by CSS|XPath|strict locator.
2045
-
2046
- Returns **void** automatically synchronized promise through #recorder
2047
-
2048
- ### seeTitleEquals
2049
-
2050
- Checks that title is equal to provided one.
2051
-
2052
- ```js
2053
- I.seeTitleEquals('Test title.');
2054
- ```
2055
-
2056
- #### Parameters
2057
-
2058
- - `text` **[string][9]** value to check.
2059
-
2060
- Returns **void** automatically synchronized promise through #recorder
2061
-
2062
- ### seeTraffic
2063
-
2064
- Verifies that a certain request is part of network traffic.
2065
-
2066
- ```js
2067
- // checking the request url contains certain query strings
2068
- I.amOnPage('https://openai.com/blog/chatgpt');
2069
- I.startRecordingTraffic();
2070
- await I.seeTraffic({
2071
- name: 'sentry event',
2072
- url: 'https://images.openai.com/blob/cf717bdb-0c8c-428a-b82b-3c3add87a600',
2073
- parameters: {
2074
- width: '1919',
2075
- height: '1138',
2076
- },
2077
- });
2078
- ```
2079
-
2080
- ```js
2081
- // checking the request url contains certain post data
2082
- I.amOnPage('https://openai.com/blog/chatgpt');
2083
- I.startRecordingTraffic();
2084
- await I.seeTraffic({
2085
- name: 'event',
2086
- url: 'https://cloudflareinsights.com/cdn-cgi/rum',
2087
- requestPostData: {
2088
- st: 2,
2089
- },
2090
- });
2091
- ```
2092
-
2093
- #### Parameters
2094
-
2095
- - `opts` **[Object][6]** options when checking the traffic network.
2096
- - `opts.name` **[string][9]** A name of that request. Can be any value. Only relevant to have a more meaningful error message in case of fail.
2097
- - `opts.url` **[string][9]** Expected URL of request in network traffic
2098
- - `opts.parameters` **[Object][6]?** Expected parameters of that request in network traffic
2099
- - `opts.requestPostData` **[Object][6]?** Expected that request contains post data in network traffic
2100
- - `opts.timeout` **[number][20]?** Timeout to wait for request in seconds. Default is 10 seconds.
2101
-
2102
- Returns **[Promise][22]&lt;any>**
2103
-
2104
- ### selectOption
2105
-
2106
- Selects an option in a drop-down select.
2107
- Field is searched by label | name | CSS | XPath.
2108
- Option is selected by visible text or by value.
2109
-
2110
- ```js
2111
- I.selectOption('Choose Plan', 'Monthly'); // select by label
2112
- I.selectOption('subscription', 'Monthly'); // match option by text
2113
- I.selectOption('subscription', '0'); // or by value
2114
- I.selectOption('//form/select[@name=account]','Premium');
2115
- I.selectOption('form select[name=account]', 'Premium');
2116
- I.selectOption({css: 'form select[name=account]'}, 'Premium');
2117
- ```
2118
-
2119
- Provide an array for the second argument to select multiple options.
2120
-
2121
- ```js
2122
- I.selectOption('Which OS do you use?', ['Android', 'iOS']);
2123
- ```
2124
-
2125
- #### Parameters
2126
-
2127
- - `select` **([string][9] | [object][6])** field located by label|name|CSS|XPath|strict locator.
2128
- - `option` **([string][9] | [Array][10]&lt;any>)** visible text or value of option.
2129
-
2130
- Returns **void** automatically synchronized promise through #recorder
2131
-
2132
- ### setCookie
2133
-
2134
- Sets cookie(s).
2135
-
2136
- Can be a single cookie object or an array of cookies:
2137
-
2138
- ```js
2139
- I.setCookie({name: 'auth', value: true});
2140
-
2141
- // as array
2142
- I.setCookie([
2143
- {name: 'auth', value: true},
2144
- {name: 'agree', value: true}
2145
- ]);
2146
- ```
2147
-
2148
- #### Parameters
2149
-
2150
- - `cookie` **(Cookie | [Array][10]&lt;Cookie>)** a cookie object or array of cookie objects.
2151
-
2152
- Returns **void** automatically synchronized promise through #recorder
2153
-
2154
- ### setPlaywrightRequestHeaders
2155
-
2156
- Set headers for all next requests
2157
-
2158
- ```js
2159
- I.setPlaywrightRequestHeaders({
2160
- 'X-Sent-By': 'CodeceptJS',
2161
- });
2162
- ```
2163
-
2164
- #### Parameters
2165
-
2166
- - `customHeaders` **[object][6]** headers to set
2167
-
2168
- ### startRecordingTraffic
2169
-
2170
- Starts recording the network traffics.
2171
- This also resets recorded network requests.
2172
-
2173
- ```js
2174
- I.startRecordingTraffic();
2175
- ```
2176
-
2177
- Returns **void**
2178
-
2179
- ### startRecordingWebSocketMessages
2180
-
2181
- Starts recording of websocket messages.
2182
- This also resets recorded websocket messages.
2183
-
2184
- ```js
2185
- await I.startRecordingWebSocketMessages();
2186
- ```
2187
-
2188
- ### stopMockingRoute
2189
-
2190
- Stops network mocking created by `mockRoute`.
2191
-
2192
- ```js
2193
- I.stopMockingRoute(/(.png$)|(.jpg$)/);
2194
- I.stopMockingRoute(/(.png$)|(.jpg$)/, previouslySetHandler);
2195
- ```
2196
-
2197
- If no handler is passed, all mock requests for the rote are disabled.
2198
-
2199
- #### Parameters
2200
-
2201
- - `url` **([string][9] | [RegExp][11])?** URL, regex or pattern for to match URL
2202
- - `handler` **[function][21]?** a function to process reques
2203
-
2204
- ### stopRecordingTraffic
2205
-
2206
- Stops recording of network traffic. Recorded traffic is not flashed.
2207
-
2208
- ```js
2209
- I.stopRecordingTraffic();
2210
- ```
2211
-
2212
- ### stopRecordingWebSocketMessages
2213
-
2214
- Stops recording WS messages. Recorded WS messages is not flashed.
2215
-
2216
- ```js
2217
- await I.stopRecordingWebSocketMessages();
2218
- ```
2219
-
2220
- ### switchTo
2221
-
2222
- Switches frame or in case of null locator reverts to parent.
2223
-
2224
- ```js
2225
- I.switchTo('iframe'); // switch to first iframe
2226
- I.switchTo(); // switch back to main page
2227
- ```
2228
-
2229
- #### Parameters
2230
-
2231
- - `locator` **([string][9]? | [object][6])** (optional, `null` by default) element located by CSS|XPath|strict locator.
2232
-
2233
- Returns **void** automatically synchronized promise through #recorder
2234
-
2235
- ### switchToNextTab
2236
-
2237
- Switch focus to a particular tab by its number. It waits tabs loading and then switch tab
2238
-
2239
- ```js
2240
- I.switchToNextTab();
2241
- I.switchToNextTab(2);
2242
- ```
2243
-
2244
- #### Parameters
2245
-
2246
- - `num` **[number][20]**
2247
-
2248
- ### switchToPreviousTab
2249
-
2250
- Switch focus to a particular tab by its number. It waits tabs loading and then switch tab
2251
-
2252
- ```js
2253
- I.switchToPreviousTab();
2254
- I.switchToPreviousTab(2);
2255
- ```
2256
-
2257
- #### Parameters
2258
-
2259
- - `num` **[number][20]**
2260
-
2261
- ### type
2262
-
2263
- Types out the given text into an active field.
2264
- To slow down typing use a second parameter, to set interval between key presses.
2265
- _Note:_ Should be used when [`fillField`][33] is not an option.
2266
-
2267
- ```js
2268
- // passing in a string
2269
- I.type('Type this out.');
2270
-
2271
- // typing values with a 100ms interval
2272
- I.type('4141555311111111', 100);
2273
-
2274
- // passing in an array
2275
- I.type(['T', 'E', 'X', 'T']);
2276
-
2277
- // passing a secret
2278
- I.type(secret('123456'));
2279
- ```
2280
-
2281
- #### Parameters
2282
-
2283
- - `keys`
2284
- - `delay` **[number][20]?** (optional) delay in ms between key presses
2285
- - `key` **([string][9] | [Array][10]&lt;[string][9]>)** or array of keys to type.
2286
-
2287
- Returns **void** automatically synchronized promise through #recorder
2288
-
2289
- ### uncheckOption
2290
-
2291
- Unselects a checkbox or radio button.
2292
- Element is located by label or name or CSS or XPath.
2293
-
2294
- The second parameter is a context (CSS or XPath locator) to narrow the search.
2295
-
2296
- ```js
2297
- I.uncheckOption('#agree');
2298
- I.uncheckOption('I Agree to Terms and Conditions');
2299
- I.uncheckOption('agree', '//form');
2300
- ```
2301
-
2302
- #### Parameters
2303
-
2304
- - `field` **([string][9] | [object][6])** checkbox located by label | name | CSS | XPath | strict locator.
2305
- - `context` **([string][9]? | [object][6])** (optional, `null` by default) element located by CSS | XPath | strict locator.
2306
- - `options`
2307
-
2308
- Returns **void** automatically synchronized promise through #recorder[Additional options][37] for uncheck available as 3rd argument.Examples:```js
2309
- // click on element at position
2310
- I.uncheckOption('Agree', '.signup', { position: { x: 5, y: 5 } })
2311
- ```> ⚠️ To avoid flakiness, option `force: true` is set by default
2312
-
2313
- ### usePlaywrightTo
2314
-
2315
- Use Playwright API inside a test.
2316
-
2317
- First argument is a description of an action.
2318
- Second argument is async function that gets this helper as parameter.
2319
-
2320
- { [`page`][38], [`browserContext`][39] [`browser`][40] } objects from Playwright API are available.
2321
-
2322
- ```js
2323
- I.usePlaywrightTo('emulate offline mode', async ({ browserContext }) => {
2324
- await browserContext.setOffline(true);
2325
- });
2326
- ```
2327
-
2328
- #### Parameters
2329
-
2330
- - `description` **[string][9]** used to show in logs.
2331
- - `fn` **[function][21]** async function that executed with Playwright helper as argumen
2332
-
2333
- ### wait
2334
-
2335
- Pauses execution for a number of seconds.
2336
-
2337
- ```js
2338
- I.wait(2); // wait 2 secs
2339
- ```
2340
-
2341
- #### Parameters
2342
-
2343
- - `sec` **[number][20]** number of second to wait.
2344
-
2345
- Returns **void** automatically synchronized promise through #recorder
2346
-
2347
- ### waitForClickable
2348
-
2349
- Waits for element to be clickable (by default waits for 1sec).
2350
- Element can be located by CSS or XPath.
2351
-
2352
- ```js
2353
- I.waitForClickable('.btn.continue');
2354
- I.waitForClickable('.btn.continue', 5); // wait for 5 secs
2355
- ```
2356
-
2357
- #### Parameters
2358
-
2359
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2360
- - `waitTimeout`
2361
- - `sec` **[number][20]?** (optional, `1` by default) time in seconds to wait
2362
-
2363
- Returns **void** automatically synchronized promise through #recorder
2364
-
2365
- ### waitForDetached
2366
-
2367
- Waits for an element to become not attached to the DOM on a page (by default waits for 1sec).
2368
- Element can be located by CSS or XPath.
2369
-
2370
- ```js
2371
- I.waitForDetached('#popup');
2372
- ```
2373
-
2374
- #### Parameters
2375
-
2376
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2377
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2378
-
2379
- Returns **void** automatically synchronized promise through #recorder
2380
-
2381
- ### waitForElement
2382
-
2383
- Waits for element to be present on page (by default waits for 1sec).
2384
- Element can be located by CSS or XPath.
2385
-
2386
- ```js
2387
- I.waitForElement('.btn.continue');
2388
- I.waitForElement('.btn.continue', 5); // wait for 5 secs
2389
- ```
2390
-
2391
- #### Parameters
2392
-
2393
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2394
- - `sec` **[number][20]?** (optional, `1` by default) time in seconds to wait
2395
-
2396
- Returns **void** automatically synchronized promise through #recorder
2397
-
2398
- ### waitForEnabled
2399
-
2400
- Waits for element to become enabled (by default waits for 1sec).
2401
- Element can be located by CSS or XPath.
2402
-
2403
- #### Parameters
2404
-
2405
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2406
- - `sec` **[number][20]** (optional) time in seconds to wait, 1 by default.
2407
-
2408
- Returns **void** automatically synchronized promise through #recorder
2409
-
2410
- ### waitForFunction
2411
-
2412
- Waits for a function to return true (waits for 1 sec by default).
2413
- Running in browser context.
2414
-
2415
- ```js
2416
- I.waitForFunction(fn[, [args[, timeout]])
2417
- ```
2418
-
2419
- ```js
2420
- I.waitForFunction(() => window.requests == 0);
2421
- I.waitForFunction(() => window.requests == 0, 5); // waits for 5 sec
2422
- I.waitForFunction((count) => window.requests == count, [3], 5) // pass args and wait for 5 sec
2423
- ```
2424
-
2425
- #### Parameters
2426
-
2427
- - `fn` **([string][9] | [function][21])** to be executed in browser context.
2428
- - `argsOrSec` **([Array][10]&lt;any> | [number][20])?** (optional, `1` by default) arguments for function or seconds.
2429
- - `sec` **[number][20]?** (optional, `1` by default) time in seconds to wait
2430
-
2431
- Returns **void** automatically synchronized promise through #recorder
2432
-
2433
- ### waitForInvisible
2434
-
2435
- Waits for an element to be removed or become invisible on a page (by default waits for 1sec).
2436
- Element can be located by CSS or XPath.
2437
-
2438
- ```js
2439
- I.waitForInvisible('#popup');
2440
- ```
2441
-
2442
- #### Parameters
2443
-
2444
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2445
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2446
-
2447
- Returns **void** automatically synchronized promise through #recorder
2448
-
2449
- ### waitForNavigation
2450
-
2451
- Waits for navigation to finish. By default, it takes configured `waitForNavigation` option.
2452
-
2453
- See [Playwright's reference][41]
2454
-
2455
- #### Parameters
2456
-
2457
- - `options` **any**
2458
-
2459
- ### waitForRequest
2460
-
2461
- Waits for a network request.
2462
-
2463
- ```js
2464
- I.waitForRequest('http://example.com/resource');
2465
- I.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET');
2466
- ```
2467
-
2468
- #### Parameters
2469
-
2470
- - `urlOrPredicate` **([string][9] | [function][21])**
2471
- - `sec` **[number][20]?** seconds to wait
2472
-
2473
- ### waitForResponse
2474
-
2475
- Waits for a network response.
2476
-
2477
- ```js
2478
- I.waitForResponse('http://example.com/resource');
2479
- I.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200);
2480
- ```
2481
-
2482
- #### Parameters
2483
-
2484
- - `urlOrPredicate` **([string][9] | [function][21])**
2485
- - `sec` **[number][20]?** number of seconds to wait
2486
-
2487
- ### waitForText
2488
-
2489
- Waits for a text to appear (by default waits for 1sec).
2490
- Element can be located by CSS or XPath.
2491
- Narrow down search results by providing context.
2492
-
2493
- ```js
2494
- I.waitForText('Thank you, form has been submitted');
2495
- I.waitForText('Thank you, form has been submitted', 5, '#modal');
2496
- ```
2497
-
2498
- #### Parameters
2499
-
2500
- - `text` **[string][9]** to wait for.
2501
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2502
- - `context` **([string][9] | [object][6])?** (optional) element located by CSS|XPath|strict locator.
2503
-
2504
- Returns **void** automatically synchronized promise through #recorder
2505
-
2506
- ### waitForURL
2507
-
2508
- Waits for page navigates to a new URL or reloads. By default, it takes configured `waitForNavigation` option.
2509
-
2510
- See [Playwright's reference][42]
2511
-
2512
- #### Parameters
2513
-
2514
- - `url` **([string][9] | [RegExp][11])** A glob pattern, regex pattern or predicate receiving URL to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
2515
- - `options` **any**
2516
-
2517
- ### waitForValue
2518
-
2519
- Waits for the specified value to be in value attribute.
2520
-
2521
- ```js
2522
- I.waitForValue('//input', "GoodValue");
2523
- ```
2524
-
2525
- #### Parameters
2526
-
2527
- - `field` **([string][9] | [object][6])** input field.
2528
- - `value` **[string][9]** expected value.
2529
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2530
-
2531
- Returns **void** automatically synchronized promise through #recorder
2532
-
2533
- ### waitForVisible
2534
-
2535
- Waits for an element to become visible on a page (by default waits for 1sec).
2536
- Element can be located by CSS or XPath.
2537
-
2538
- ```js
2539
- I.waitForVisible('#popup');
2540
- ```
2541
-
2542
- #### Parameters
2543
-
2544
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2545
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2546
-
2547
- Returns **void** automatically synchronized promise through #recorderThis method accepts [React selectors][43].
2548
-
2549
- ### waitInUrl
2550
-
2551
- Waiting for the part of the URL to match the expected. Useful for SPA to understand that page was changed.
2552
-
2553
- ```js
2554
- I.waitInUrl('/info', 2);
2555
- ```
2556
-
2557
- #### Parameters
2558
-
2559
- - `urlPart` **[string][9]** value to check.
2560
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2561
-
2562
- Returns **void** automatically synchronized promise through #recorder
2563
-
2564
- ### waitNumberOfVisibleElements
2565
-
2566
- Waits for a specified number of elements on the page.
2567
-
2568
- ```js
2569
- I.waitNumberOfVisibleElements('a', 3);
2570
- ```
2571
-
2572
- #### Parameters
2573
-
2574
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2575
- - `num` **[number][20]** number of elements.
2576
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2577
-
2578
- Returns **void** automatically synchronized promise through #recorder
2579
-
2580
- ### waitToHide
2581
-
2582
- Waits for an element to hide (by default waits for 1sec).
2583
- Element can be located by CSS or XPath.
2584
-
2585
- ```js
2586
- I.waitToHide('#popup');
2587
- ```
2588
-
2589
- #### Parameters
2590
-
2591
- - `locator` **([string][9] | [object][6])** element located by CSS|XPath|strict locator.
2592
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2593
-
2594
- Returns **void** automatically synchronized promise through #recorder
2595
-
2596
- ### waitUrlEquals
2597
-
2598
- Waits for the entire URL to match the expected
2599
-
2600
- ```js
2601
- I.waitUrlEquals('/info', 2);
2602
- I.waitUrlEquals('http://127.0.0.1:8000/info');
2603
- ```
2604
-
2605
- #### Parameters
2606
-
2607
- - `urlPart` **[string][9]** value to check.
2608
- - `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
2609
-
2610
- Returns **void** automatically synchronized promise through #recorder
2611
-
2612
- [1]: https://github.com/microsoft/playwright
2613
-
2614
- [2]: https://playwright.dev/docs/next/api/class-browser#browser-new-context
2615
-
2616
- [3]: https://playwright.dev/docs/api/class-browser#browser-new-context-option-record-har
2617
-
2618
- [4]: https://playwright.dev/docs/api/class-browsertype#browsertypeconnectparams
2619
-
2620
- [5]: https://github.com/microsoft/playwright/blob/v0.11.0/docs/api.md#working-with-chrome-extensions
2621
-
2622
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
2623
-
2624
- [7]: https://playwright.dev/docs/api/class-browser#browser-new-context
2625
-
2626
- [8]: http://jster.net/category/windows-modals-popups
2627
-
2628
- [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
2629
-
2630
- [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
2631
-
2632
- [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp
2633
-
2634
- [12]: https://www.example.com**
2635
-
2636
- [13]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
2637
-
2638
- [14]: https://playwright.dev/docs/api/class-locator#locator-blur
2639
-
2640
- [15]: https://playwright.dev/docs/api/class-elementhandle#element-handle-check
2641
-
2642
- [16]: https://playwright.dev/docs/actionability
2643
-
2644
- [17]: https://playwright.dev/docs/api/class-locator#locator-clear
2645
-
2646
- [18]: https://playwright.dev/docs/api/class-page#page-click
2647
-
2648
- [19]: https://playwright.dev/docs/api/class-page#page-drag-and-drop
2649
-
2650
- [20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
2651
-
2652
- [21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
2653
-
2654
- [22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
2655
-
2656
- [23]: https://playwright.dev/docs/api/class-locator#locator-focus
2657
-
2658
- [24]: https://playwright.dev/docs/api/class-consolemessage
2659
-
2660
- [25]: https://playwright.dev/docs/api/class-locator#locator-is-checked
2661
-
2662
- [26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
2663
-
2664
- [27]: https://playwright.dev/docs/api/class-locator#locator-is-disabled
2665
-
2666
- [28]: https://codecept.io/helpers/FileSystem
2667
-
2668
- [29]: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get
2669
-
2670
- [30]: https://playwright.dev/docs/api/class-browsercontext#browser-context-route
2671
-
2672
- [31]: https://playwright.dev/docs/network#handle-requests
2673
-
2674
- [32]: https://github.com/microsoft/playwright/blob/main/docs/api.md#browsernewpageoptions
2675
-
2676
- [33]: #fillfield
2677
-
2678
- [34]: https://github.com/GoogleChrome/puppeteer/issues/1313
2679
-
2680
- [35]: #click
2681
-
2682
- [36]: https://playwright.dev/docs/api/class-page#page-route-from-har
2683
-
2684
- [37]: https://playwright.dev/docs/api/class-elementhandle#element-handle-uncheck
2685
-
2686
- [38]: https://github.com/microsoft/playwright/blob/main/docs/src/api/class-page.md
2687
-
2688
- [39]: https://github.com/microsoft/playwright/blob/main/docs/src/api/class-browsercontext.md
2689
-
2690
- [40]: https://github.com/microsoft/playwright/blob/main/docs/src/api/class-browser.md
2691
-
2692
- [41]: https://playwright.dev/docs/api/class-page?_highlight=waitfornavi#pagewaitfornavigationoptions
2693
-
2694
- [42]: https://playwright.dev/docs/api/class-page#page-wait-for-url
2695
-
2696
- [43]: https://codecept.io/react
2697
-
2698
- [44]: https://playwright.dev/docs/api/class-browsercontext
2699
-
2700
- [45]: https://playwright.dev/docs/api/class-page#page-set-default-timeout
2701
-
2702
- [46]: https://playwright.dev/docs/trace-viewer
2703
-
2704
- [47]: https://playwright.dev/docs/browsers/#google-chrome--microsoft-edge
2705
-
2706
- [48]: https://playwright.dev/docs/api/class-consolemessage#console-message-type