codeceptjs 3.6.0-beta.1.ai-healers → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +2 -2
  2. package/bin/codecept.js +2 -1
  3. package/docs/webapi/dontSeeTraffic.mustache +13 -0
  4. package/docs/webapi/flushNetworkTraffics.mustache +5 -0
  5. package/docs/webapi/grabRecordedNetworkTraffics.mustache +10 -0
  6. package/docs/webapi/seeTraffic.mustache +36 -0
  7. package/docs/webapi/startRecordingTraffic.mustache +8 -0
  8. package/docs/webapi/startRecordingWebSocketMessages.mustache +8 -0
  9. package/docs/webapi/stopRecordingTraffic.mustache +5 -0
  10. package/docs/webapi/stopRecordingWebSocketMessages.mustache +7 -0
  11. package/docs/webapi/waitForCookie.mustache +9 -0
  12. package/lib/actor.js +6 -3
  13. package/lib/command/dryRun.js +44 -13
  14. package/lib/helper/Appium.js +36 -12
  15. package/lib/helper/Expect.js +11 -8
  16. package/lib/helper/JSONResponse.js +8 -8
  17. package/lib/helper/MockServer.js +221 -0
  18. package/lib/helper/Playwright.js +107 -371
  19. package/lib/helper/Puppeteer.js +404 -71
  20. package/lib/helper/REST.js +4 -1
  21. package/lib/helper/WebDriver.js +189 -13
  22. package/lib/helper/errors/ElementAssertion.js +38 -0
  23. package/lib/helper/extras/PlaywrightReactVueLocator.js +6 -1
  24. package/lib/helper/network/actions.js +123 -0
  25. package/lib/helper/network/utils.js +187 -0
  26. package/lib/locator.js +36 -5
  27. package/lib/plugin/coverage.js +112 -99
  28. package/lib/step.js +3 -1
  29. package/package.json +48 -37
  30. package/typings/index.d.ts +19 -2
  31. package/typings/promiseBasedTypes.d.ts +505 -41
  32. package/typings/types.d.ts +609 -56
  33. package/docs/advanced.md +0 -351
  34. package/docs/ai.md +0 -365
  35. package/docs/api.md +0 -323
  36. package/docs/basics.md +0 -979
  37. package/docs/bdd.md +0 -539
  38. package/docs/best.md +0 -237
  39. package/docs/books.md +0 -37
  40. package/docs/bootstrap.md +0 -135
  41. package/docs/build/AI.js +0 -124
  42. package/docs/build/ApiDataFactory.js +0 -410
  43. package/docs/build/Appium.js +0 -2027
  44. package/docs/build/Expect.js +0 -422
  45. package/docs/build/FileSystem.js +0 -228
  46. package/docs/build/GraphQL.js +0 -229
  47. package/docs/build/GraphQLDataFactory.js +0 -309
  48. package/docs/build/JSONResponse.js +0 -338
  49. package/docs/build/Mochawesome.js +0 -71
  50. package/docs/build/Nightmare.js +0 -2152
  51. package/docs/build/OpenAI.js +0 -126
  52. package/docs/build/Playwright.js +0 -5110
  53. package/docs/build/Protractor.js +0 -2706
  54. package/docs/build/Puppeteer.js +0 -3905
  55. package/docs/build/REST.js +0 -344
  56. package/docs/build/TestCafe.js +0 -2125
  57. package/docs/build/WebDriver.js +0 -4240
  58. package/docs/changelog.md +0 -2572
  59. package/docs/commands.md +0 -266
  60. package/docs/community-helpers.md +0 -58
  61. package/docs/configuration.md +0 -157
  62. package/docs/continuous-integration.md +0 -22
  63. package/docs/custom-helpers.md +0 -306
  64. package/docs/data.md +0 -379
  65. package/docs/detox.md +0 -235
  66. package/docs/docker.md +0 -136
  67. package/docs/email.md +0 -183
  68. package/docs/examples.md +0 -149
  69. package/docs/heal.md +0 -186
  70. package/docs/helpers/ApiDataFactory.md +0 -266
  71. package/docs/helpers/Appium.md +0 -1374
  72. package/docs/helpers/Detox.md +0 -586
  73. package/docs/helpers/Expect.md +0 -275
  74. package/docs/helpers/FileSystem.md +0 -152
  75. package/docs/helpers/GraphQL.md +0 -151
  76. package/docs/helpers/GraphQLDataFactory.md +0 -226
  77. package/docs/helpers/JSONResponse.md +0 -254
  78. package/docs/helpers/Mochawesome.md +0 -8
  79. package/docs/helpers/MockRequest.md +0 -377
  80. package/docs/helpers/Nightmare.md +0 -1305
  81. package/docs/helpers/OpenAI.md +0 -70
  82. package/docs/helpers/Playwright.md +0 -2759
  83. package/docs/helpers/Polly.md +0 -44
  84. package/docs/helpers/Protractor.md +0 -1769
  85. package/docs/helpers/Puppeteer-firefox.md +0 -86
  86. package/docs/helpers/Puppeteer.md +0 -2317
  87. package/docs/helpers/REST.md +0 -218
  88. package/docs/helpers/TestCafe.md +0 -1321
  89. package/docs/helpers/WebDriver.md +0 -2547
  90. package/docs/hooks.md +0 -340
  91. package/docs/index.md +0 -111
  92. package/docs/installation.md +0 -75
  93. package/docs/internal-api.md +0 -266
  94. package/docs/locators.md +0 -339
  95. package/docs/mobile-react-native-locators.md +0 -67
  96. package/docs/mobile.md +0 -338
  97. package/docs/pageobjects.md +0 -291
  98. package/docs/parallel.md +0 -400
  99. package/docs/playwright.md +0 -632
  100. package/docs/plugins.md +0 -1247
  101. package/docs/puppeteer.md +0 -316
  102. package/docs/quickstart.md +0 -162
  103. package/docs/react.md +0 -70
  104. package/docs/reports.md +0 -392
  105. package/docs/secrets.md +0 -36
  106. package/docs/shadow.md +0 -68
  107. package/docs/shared/keys.mustache +0 -31
  108. package/docs/shared/react.mustache +0 -1
  109. package/docs/testcafe.md +0 -174
  110. package/docs/translation.md +0 -247
  111. package/docs/tutorial.md +0 -271
  112. package/docs/typescript.md +0 -180
  113. package/docs/ui.md +0 -59
  114. package/docs/videos.md +0 -28
  115. package/docs/visual.md +0 -202
  116. package/docs/vue.md +0 -143
  117. package/docs/webdriver.md +0 -701
  118. package/docs/wiki/Books-&-Posts.md +0 -27
  119. package/docs/wiki/Community-Helpers-&-Plugins.md +0 -53
  120. package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -61
  121. package/docs/wiki/Examples.md +0 -145
  122. package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
  123. package/docs/wiki/Home.md +0 -16
  124. package/docs/wiki/Migration-to-Appium-v2---CodeceptJS.md +0 -83
  125. package/docs/wiki/Release-Process.md +0 -24
  126. package/docs/wiki/Roadmap.md +0 -23
  127. package/docs/wiki/Tests.md +0 -1393
  128. package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
  129. package/docs/wiki/Videos.md +0 -19
package/docs/plugins.md DELETED
@@ -1,1247 +0,0 @@
1
- ---
2
- permalink: plugins
3
- sidebarDepth:
4
- sidebar: auto
5
- title: Plugins
6
- ---
7
-
8
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9
-
10
- ## autoDelay
11
-
12
- Sometimes it takes some time for a page to respond to user's actions.
13
- Depending on app's performance this can be either slow or fast.
14
-
15
- For instance, if you click a button and nothing happens - probably JS event is not attached to this button yet
16
- Also, if you fill field and input validation doesn't accept your input - maybe because you typed value too fast.
17
-
18
- This plugin allows to slow down tests execution when a test running too fast.
19
- It puts a tiny delay for before and after action commands.
20
-
21
- Commands affected (by default):
22
-
23
- - `click`
24
- - `fillField`
25
- - `checkOption`
26
- - `pressKey`
27
- - `doubleClick`
28
- - `rightClick`
29
-
30
- #### Configuration
31
-
32
- ```js
33
- plugins: {
34
- autoDelay: {
35
- enabled: true
36
- }
37
- }
38
- ```
39
-
40
- Possible config options:
41
-
42
- - `methods`: list of affected commands. Can be overridden
43
- - `delayBefore`: put a delay before a command. 100ms by default
44
- - `delayAfter`: put a delay after a command. 200ms by default
45
-
46
- ### Parameters
47
-
48
- - `config`
49
-
50
- ## autoLogin
51
-
52
- Logs user in for the first test and reuses session for next tests.
53
- Works by saving cookies into memory or file.
54
- If a session expires automatically logs in again.
55
-
56
- > For better development experience cookies can be saved into file, so a session can be reused while writing tests.
57
-
58
- #### Usage
59
-
60
- 1. Enable this plugin and configure as described below
61
- 2. Define user session names (example: `user`, `editor`, `admin`, etc).
62
- 3. Define how users are logged in and how to check that user is logged in
63
- 4. Use `login` object inside your tests to log in:
64
-
65
- ```js
66
- // inside a test file
67
- // use login to inject auto-login function
68
- Feature('Login');
69
-
70
- Before(({ login }) => {
71
- login('user'); // login using user session
72
- });
73
-
74
- // Alternatively log in for one scenario.
75
- Scenario('log me in', ( { I, login } ) => {
76
- login('admin');
77
- I.see('I am logged in');
78
- });
79
- ```
80
-
81
- #### Configuration
82
-
83
- - `saveToFile` (default: false) - save cookies to file. Allows to reuse session between execution.
84
- - `inject` (default: `login`) - name of the login function to use
85
- - `users` - an array containing different session names and functions to:
86
- - `login` - sign in into the system
87
- - `check` - check that user is logged in
88
- - `fetch` - to get current cookies (by default `I.grabCookie()`)
89
- - `restore` - to set cookies (by default `I.amOnPage('/'); I.setCookie(cookie)`)
90
-
91
- #### How It Works
92
-
93
- 1. `restore` method is executed. It should open a page and set credentials.
94
- 2. `check` method is executed. It should reload a page (so cookies are applied) and check that this page belongs to logged-in user. When you pass the second args `session`, you could perform the validation using passed session.
95
- 3. If `restore` and `check` were not successful, `login` is executed
96
- 4. `login` should fill in login form
97
- 5. After successful login, `fetch` is executed to save cookies into memory or file.
98
-
99
- #### Example: Simple login
100
-
101
- ```js
102
- autoLogin: {
103
- enabled: true,
104
- saveToFile: true,
105
- inject: 'login',
106
- users: {
107
- admin: {
108
- // loginAdmin function is defined in `steps_file.js`
109
- login: (I) => I.loginAdmin(),
110
- // if we see `Admin` on page, we assume we are logged in
111
- check: (I) => {
112
- I.amOnPage('/');
113
- I.see('Admin');
114
- }
115
- }
116
- }
117
- }
118
- ```
119
-
120
- #### Example: Multiple users
121
-
122
- ```js
123
- autoLogin: {
124
- enabled: true,
125
- saveToFile: true,
126
- inject: 'loginAs', // use `loginAs` instead of login
127
- users: {
128
- user: {
129
- login: (I) => {
130
- I.amOnPage('/login');
131
- I.fillField('email', 'user@site.com');
132
- I.fillField('password', '123456');
133
- I.click('Login');
134
- },
135
- check: (I) => {
136
- I.amOnPage('/');
137
- I.see('User', '.navbar');
138
- },
139
- },
140
- admin: {
141
- login: (I) => {
142
- I.amOnPage('/login');
143
- I.fillField('email', 'admin@site.com');
144
- I.fillField('password', '123456');
145
- I.click('Login');
146
- },
147
- check: (I) => {
148
- I.amOnPage('/');
149
- I.see('Admin', '.navbar');
150
- },
151
- },
152
- }
153
- }
154
- ```
155
-
156
- #### Example: Keep cookies between tests
157
-
158
- If you decide to keep cookies between tests you don't need to save/retrieve cookies between tests.
159
- But you need to login once work until session expires.
160
- For this case, disable `fetch` and `restore` methods.
161
-
162
- ```js
163
- helpers: {
164
- WebDriver: {
165
- // config goes here
166
- keepCookies: true; // keep cookies for all tests
167
- }
168
- },
169
- plugins: {
170
- autoLogin: {
171
- users: {
172
- admin: {
173
- login: (I) => {
174
- I.amOnPage('/login');
175
- I.fillField('email', 'admin@site.com');
176
- I.fillField('password', '123456');
177
- I.click('Login');
178
- },
179
- check: (I) => {
180
- I.amOnPage('/dashboard');
181
- I.see('Admin', '.navbar');
182
- },
183
- fetch: () => {}, // empty function
184
- restore: () => {}, // empty funciton
185
- }
186
- }
187
- }
188
- }
189
- ```
190
-
191
- #### Example: Getting sessions from local storage
192
-
193
- If your session is stored in local storage instead of cookies you still can obtain sessions.
194
-
195
- ```js
196
- plugins: {
197
- autoLogin: {
198
- admin: {
199
- login: (I) => I.loginAsAdmin(),
200
- check: (I) => I.see('Admin', '.navbar'),
201
- fetch: (I) => {
202
- return I.executeScript(() => localStorage.getItem('session_id'));
203
- },
204
- restore: (I, session) => {
205
- I.amOnPage('/');
206
- I.executeScript((session) => localStorage.setItem('session_id', session), session);
207
- },
208
- }
209
- }
210
- }
211
- ```
212
-
213
- #### Tips: Using async function in the autoLogin
214
-
215
- If you use async functions in the autoLogin plugin, login function should be used with `await` keyword.
216
-
217
- ```js
218
- autoLogin: {
219
- enabled: true,
220
- saveToFile: true,
221
- inject: 'login',
222
- users: {
223
- admin: {
224
- login: async (I) => { // If you use async function in the autoLogin plugin
225
- const phrase = await I.grabTextFrom('#phrase')
226
- I.fillField('username', 'admin'),
227
- I.fillField('password', 'password')
228
- I.fillField('phrase', phrase)
229
- },
230
- check: (I) => {
231
- I.amOnPage('/');
232
- I.see('Admin');
233
- },
234
- }
235
- }
236
- }
237
- ```
238
-
239
- ```js
240
- Scenario('login', async ( {I, login} ) => {
241
- await login('admin') // you should use `await`
242
- })
243
- ```
244
-
245
- #### Tips: Using session to validate user
246
-
247
- Instead of asserting on page elements for the current user in `check`, you can use the `session` you saved in `fetch`
248
-
249
- ```js
250
- autoLogin: {
251
- enabled: true,
252
- saveToFile: true,
253
- inject: 'login',
254
- users: {
255
- admin: {
256
- login: async (I) => { // If you use async function in the autoLogin plugin
257
- const phrase = await I.grabTextFrom('#phrase')
258
- I.fillField('username', 'admin'),
259
- I.fillField('password', 'password')
260
- I.fillField('phrase', phrase)
261
- },
262
- check: (I, session) => {
263
- // Throwing an error in `check` will make CodeceptJS perform the login step for the user
264
- if (session.profile.email !== the.email.you.expect@some-mail.com) {
265
- throw new Error ('Wrong user signed in');
266
- }
267
- },
268
- }
269
- }
270
- }
271
- ```
272
-
273
- ```js
274
- Scenario('login', async ( {I, login} ) => {
275
- await login('admin') // you should use `await`
276
- })
277
- ```
278
-
279
- ### Parameters
280
-
281
- - `config`
282
-
283
- ## commentStep
284
-
285
- Add descriptive nested steps for your tests:
286
-
287
- ```js
288
- Scenario('project update test', async (I) => {
289
- __`Given`;
290
- const projectId = await I.have('project');
291
-
292
- __`When`;
293
- projectPage.update(projectId, { title: 'new title' });
294
-
295
- __`Then`;
296
- projectPage.open(projectId);
297
- I.see('new title', 'h1');
298
- })
299
- ```
300
-
301
- Steps prefixed with `__` will be printed as nested steps in `--steps` output:
302
-
303
- Given
304
- I have "project"
305
- When
306
- projectPage update
307
- Then
308
- projectPage open
309
- I see "new title", "h1"
310
-
311
- Also those steps will be exported to allure reports.
312
-
313
- This plugin can be used
314
-
315
- ### Config
316
-
317
- - `enabled` - (default: false) enable a plugin
318
- - `registerGlobal` - (default: false) register `__` template literal function globally. You can override function global name by providing a name as a value.
319
-
320
- ### Examples
321
-
322
- Registering `__` globally:
323
-
324
- ```js
325
- plugins: {
326
- commentStep: {
327
- enabled: true,
328
- registerGlobal: true
329
- }
330
- }
331
- ```
332
-
333
- Registering `Step` globally:
334
-
335
- ```js
336
- plugins: {
337
- commentStep: {
338
- enabled: true,
339
- registerGlobal: 'Step'
340
- }
341
- }
342
- ```
343
-
344
- Using only local function names:
345
-
346
- ```js
347
- plugins: {
348
- commentStep: {
349
- enabled: true
350
- }
351
- }
352
- ```
353
-
354
- Then inside a test import a comment function from a plugin.
355
- For instance, you can prepare Given/When/Then functions to use them inside tests:
356
-
357
- ```js
358
- // inside a test
359
- const step = codeceptjs.container.plugins('commentStep');
360
-
361
- const Given = () => step`Given`;
362
- const When = () => step`When`;
363
- const Then = () => step`Then`;
364
- ```
365
-
366
- Scenario('project update test', async (I) => {
367
- Given();
368
- const projectId = await I.have('project');
369
-
370
- When();
371
- projectPage.update(projectId, { title: 'new title' });
372
-
373
- Then();
374
- projectPage.open(projectId);
375
- I.see('new title', 'h1');
376
- });
377
-
378
- ```
379
-
380
- ```
381
-
382
- ### Parameters
383
-
384
- - `config`
385
-
386
- ## coverage
387
-
388
- Dumps code coverage from Playwright/Puppeteer after every test.
389
-
390
- #### Configuration
391
-
392
- ```js
393
- plugins: {
394
- coverage: {
395
- enabled: true
396
- }
397
- }
398
- ```
399
-
400
- Possible config options:
401
-
402
- - `coverageDir`: directory to dump coverage files
403
- - `uniqueFileName`: generate a unique filename by adding uuid
404
-
405
- ### Parameters
406
-
407
- - `config`
408
-
409
- ## customLocator
410
-
411
- Creates a [custom locator][1] by using special attributes in HTML.
412
-
413
- If you have a convention to use `data-test-id` or `data-qa` attributes to mark active elements for e2e tests,
414
- you can enable this plugin to simplify matching elements with these attributes:
415
-
416
- ```js
417
- // replace this:
418
- I.click({ css: '[data-test-id=register_button]');
419
- // with this:
420
- I.click('$register_button');
421
- ```
422
-
423
- This plugin will create a valid XPath locator for you.
424
-
425
- #### Configuration
426
-
427
- - `enabled` (default: `false`) should a locator be enabled
428
- - `prefix` (default: `$`) sets a prefix for a custom locator.
429
- - `attribute` (default: `data-test-id`) to set an attribute to be matched.
430
- - `strategy` (default: `xpath`) actual locator strategy to use in query (`css` or `xpath`).
431
- - `showActual` (default: false) show in the output actually produced XPath or CSS locator. By default shows custom locator value.
432
-
433
- #### Examples:
434
-
435
- Using `data-test` attribute with `$` prefix:
436
-
437
- ```js
438
- // in codecept.conf.js
439
- plugins: {
440
- customLocator: {
441
- enabled: true,
442
- attribute: 'data-test'
443
- }
444
- }
445
- ```
446
-
447
- In a test:
448
-
449
- ```js
450
- I.seeElement('$user'); // matches => [data-test=user]
451
- I.click('$sign-up'); // matches => [data-test=sign-up]
452
- ```
453
-
454
- Using `data-qa` attribute with `=` prefix:
455
-
456
- ```js
457
- // in codecept.conf.js
458
- plugins: {
459
- customLocator: {
460
- enabled: true,
461
- prefix: '=',
462
- attribute: 'data-qa'
463
- }
464
- }
465
- ```
466
-
467
- In a test:
468
-
469
- ```js
470
- I.seeElement('=user'); // matches => [data-qa=user]
471
- I.click('=sign-up'); // matches => [data-qa=sign-up]
472
- ```
473
-
474
- Using `data-qa` OR `data-test` attribute with `=` prefix:
475
-
476
- ```js
477
- // in codecept.conf.js
478
- plugins: {
479
- customLocator: {
480
- enabled: true,
481
- prefix: '=',
482
- attribute: ['data-qa', 'data-test'],
483
- strategy: 'xpath'
484
- }
485
- }
486
- ```
487
-
488
- In a test:
489
-
490
- ```js
491
- I.seeElement('=user'); // matches => //*[@data-qa=user or @data-test=user]
492
- I.click('=sign-up'); // matches => //*[data-qa=sign-up or @data-test=sign-up]
493
- ```
494
-
495
- ```js
496
- // in codecept.conf.js
497
- plugins: {
498
- customLocator: {
499
- enabled: true,
500
- prefix: '=',
501
- attribute: ['data-qa', 'data-test'],
502
- strategy: 'css'
503
- }
504
- }
505
- ```
506
-
507
- In a test:
508
-
509
- ```js
510
- I.seeElement('=user'); // matches => [data-qa=user],[data-test=user]
511
- I.click('=sign-up'); // matches => [data-qa=sign-up],[data-test=sign-up]
512
- ```
513
-
514
- ### Parameters
515
-
516
- - `config`
517
-
518
- ## debugErrors
519
-
520
- Prints errors found in HTML code after each failed test.
521
-
522
- It scans HTML and searches for elements with error classes.
523
- If an element found prints a text from it to console and adds as artifact to the test.
524
-
525
- Enable this plugin in config:
526
-
527
- ```js
528
- plugins: {
529
- debugErrors: {
530
- enabled: true,
531
- }
532
- ```
533
-
534
- Additional config options:
535
-
536
- - `errorClasses` - list of classes to search for errors (default: `['error', 'warning', 'alert', 'danger']`)
537
-
538
- ### Parameters
539
-
540
- - `config` (optional, default `{}`)
541
-
542
- ## eachElement
543
-
544
- Provides `eachElement` global function to iterate over found elements to perform actions on them.
545
-
546
- `eachElement` takes following args:
547
-
548
- - `purpose` - the goal of an action. A comment text that will be displayed in output.
549
- - `locator` - a CSS/XPath locator to match elements
550
- - `fn(element, index)` - **asynchronous** function which will be executed for each matched element.
551
-
552
- Example of usage:
553
-
554
- ```js
555
- // this example works with Playwright and Puppeteer helper
556
- await eachElement('click all checkboxes', 'form input[type=checkbox]', async (el) => {
557
- await el.click();
558
- });
559
- ```
560
-
561
- Click odd elements:
562
-
563
- ```js
564
- // this example works with Playwright and Puppeteer helper
565
- await eachElement('click odd buttons', '.button-select', async (el, index) => {
566
- if (index % 2) await el.click();
567
- });
568
- ```
569
-
570
- Check all elements for visibility:
571
-
572
- ```js
573
- // this example works with Playwright and Puppeteer helper
574
- const assert = require('assert');
575
- await eachElement('check all items are visible', '.item', async (el) => {
576
- assert(await el.isVisible());
577
- });
578
- ```
579
-
580
- This method works with WebDriver, Playwright, Puppeteer, Appium helpers.
581
-
582
- Function parameter `el` represents a matched element.
583
- Depending on a helper API of `el` can be different. Refer to API of corresponding browser testing engine for a complete API list:
584
-
585
- - [Playwright ElementHandle][2]
586
- - [Puppeteer][3]
587
- - [webdriverio element][4]
588
-
589
- #### Configuration
590
-
591
- - `registerGlobal` - to register `eachElement` function globally, true by default
592
-
593
- If `registerGlobal` is false you can use eachElement from the plugin:
594
-
595
- ```js
596
- const eachElement = codeceptjs.container.plugins('eachElement');
597
- ```
598
-
599
- ### Parameters
600
-
601
- - `purpose` **[string][5]**
602
- - `locator` **CodeceptJS.LocatorOrString**
603
- - `fn` **[Function][6]**
604
-
605
- Returns **([Promise][7]&lt;any> | [undefined][8])**
606
-
607
- ## fakerTransform
608
-
609
- Use the `@faker-js/faker` package to generate fake data inside examples on your gherkin tests
610
-
611
- #### Usage
612
-
613
- To start please install `@faker-js/faker` package
614
-
615
- npm install -D @faker-js/faker
616
-
617
- yarn add -D @faker-js/faker
618
-
619
- Add this plugin to config file:
620
-
621
- ```js
622
- plugins: {
623
- fakerTransform: {
624
- enabled: true
625
- }
626
- }
627
- ```
628
-
629
- Add the faker API using a mustache string format inside examples tables in your gherkin scenario outline
630
-
631
- ```feature
632
- Scenario Outline: ...
633
- Given ...
634
- When ...
635
- Then ...
636
- Examples:
637
- | productName | customer | email | anythingMore |
638
- | {{commerce.product}} | Dr. {{name.findName}} | {{internet.email}} | staticData |
639
- ```
640
-
641
- ### Parameters
642
-
643
- - `config`
644
-
645
- ## heal
646
-
647
- Self-healing tests with OpenAI.
648
-
649
- This plugin is experimental and requires OpenAI API key.
650
-
651
- To use it you need to set OPENAI_API_KEY env variable and enable plugin inside the config.
652
-
653
- ```js
654
- plugins: {
655
- heal: {
656
- enabled: true,
657
- }
658
- }
659
- ```
660
-
661
- More config options are available:
662
-
663
- - `healLimit` - how many steps can be healed in a single test (default: 2)
664
-
665
- ### Parameters
666
-
667
- - `config` (optional, default `{}`)
668
-
669
- ## pauseOnFail
670
-
671
- Automatically launches [interactive pause][9] when a test fails.
672
-
673
- Useful for debugging flaky tests on local environment.
674
- Add this plugin to config file:
675
-
676
- ```js
677
- plugins: {
678
- pauseOnFail: {},
679
- }
680
- ```
681
-
682
- Unlike other plugins, `pauseOnFail` is not recommended to be enabled by default.
683
- Enable it manually on each run via `-p` option:
684
-
685
- npx codeceptjs run -p pauseOnFail
686
-
687
- ## retryFailedStep
688
-
689
- Retries each failed step in a test.
690
-
691
- Add this plugin to config file:
692
-
693
- ```js
694
- plugins: {
695
- retryFailedStep: {
696
- enabled: true
697
- }
698
- }
699
- ```
700
-
701
- Run tests with plugin enabled:
702
-
703
- npx codeceptjs run --plugins retryFailedStep
704
-
705
- #### Configuration:
706
-
707
- - `retries` - number of retries (by default 3),
708
- - `when` - function, when to perform a retry (accepts error as parameter)
709
- - `factor` - The exponential factor to use. Default is 1.5.
710
- - `minTimeout` - The number of milliseconds before starting the first retry. Default is 1000.
711
- - `maxTimeout` - The maximum number of milliseconds between two retries. Default is Infinity.
712
- - `randomize` - Randomizes the timeouts by multiplying with a factor from 1 to 2. Default is false.
713
- - `defaultIgnoredSteps` - an array of steps to be ignored for retry. Includes:
714
- - `amOnPage`
715
- - `wait*`
716
- - `send*`
717
- - `execute*`
718
- - `run*`
719
- - `have*`
720
- - `ignoredSteps` - an array for custom steps to ignore on retry. Use it to append custom steps to ignored list.
721
- You can use step names or step prefixes ending with `*`. As such, `wait*` will match all steps starting with `wait`.
722
- To append your own steps to ignore list - copy and paste a default steps list. Regexp values are accepted as well.
723
-
724
- #### Example
725
-
726
- ```js
727
- plugins: {
728
- retryFailedStep: {
729
- enabled: true,
730
- ignoredSteps: [
731
- 'scroll*', // ignore all scroll steps
732
- /Cookie/, // ignore all steps with a Cookie in it (by regexp)
733
- ]
734
- }
735
- }
736
- ```
737
-
738
- #### Disable Per Test
739
-
740
- This plugin can be disabled per test. In this case you will need to stet `I.retry()` to all flaky steps:
741
-
742
- Use scenario configuration to disable plugin for a test
743
-
744
- ```js
745
- Scenario('scenario tite', () => {
746
- // test goes here
747
- }).config(test => test.disableRetryFailedStep = true)
748
- ```
749
-
750
- ### Parameters
751
-
752
- - `config`
753
-
754
- ## retryTo
755
-
756
- Adds global `retryTo` which retries steps a few times before failing.
757
-
758
- Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
759
-
760
- ```js
761
- plugins: {
762
- retryTo: {
763
- enabled: true
764
- }
765
- }
766
- ```
767
-
768
- Use it in your tests:
769
-
770
- ```js
771
- // retry these steps 5 times before failing
772
- await retryTo((tryNum) => {
773
- I.switchTo('#editor frame');
774
- I.click('Open');
775
- I.see('Opened')
776
- }, 5);
777
- ```
778
-
779
- Set polling interval as 3rd argument (200ms by default):
780
-
781
- ```js
782
- // retry these steps 5 times before failing
783
- await retryTo((tryNum) => {
784
- I.switchTo('#editor frame');
785
- I.click('Open');
786
- I.see('Opened')
787
- }, 5, 100);
788
- ```
789
-
790
- Default polling interval can be changed in a config:
791
-
792
- ```js
793
- plugins: {
794
- retryTo: {
795
- enabled: true,
796
- pollInterval: 500,
797
- }
798
- }
799
- ```
800
-
801
- Disables retryFailedStep plugin for steps inside a block;
802
-
803
- Use this plugin if:
804
-
805
- - you need repeat a set of actions in flaky tests
806
- - iframe was not rendered and you need to retry switching to it
807
-
808
- #### Configuration
809
-
810
- - `pollInterval` - default interval between retries in ms. 200 by default.
811
- - `registerGlobal` - to register `retryTo` function globally, true by default
812
-
813
- If `registerGlobal` is false you can use retryTo from the plugin:
814
-
815
- ```js
816
- const retryTo = codeceptjs.container.plugins('retryTo');
817
- ```
818
-
819
- ### Parameters
820
-
821
- - `config`
822
-
823
- ## screenshotOnFail
824
-
825
- Creates screenshot on failure. Screenshot is saved into `output` directory.
826
-
827
- Initially this functionality was part of corresponding helper but has been moved into plugin since 1.4
828
-
829
- This plugin is **enabled by default**.
830
-
831
- #### Configuration
832
-
833
- Configuration can either be taken from a corresponding helper (deprecated) or a from plugin config (recommended).
834
-
835
- ```js
836
- plugins: {
837
- screenshotOnFail: {
838
- enabled: true
839
- }
840
- }
841
- ```
842
-
843
- Possible config options:
844
-
845
- - `uniqueScreenshotNames`: use unique names for screenshot. Default: false.
846
- - `fullPageScreenshots`: make full page screenshots. Default: false.
847
-
848
- ### Parameters
849
-
850
- - `config`
851
-
852
- ## selenoid
853
-
854
- [Selenoid][10] plugin automatically starts browsers and video recording.
855
- Works with WebDriver helper.
856
-
857
- ### Prerequisite
858
-
859
- This plugin **requires Docker** to be installed.
860
-
861
- > If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][11] tool from Selenoid
862
-
863
- ### Usage
864
-
865
- Selenoid plugin can be started in two ways:
866
-
867
- 1. **Automatic** - this plugin will create and manage selenoid container for you.
868
- 2. **Manual** - you create the conatainer and configure it with a plugin (recommended).
869
-
870
- #### Automatic
871
-
872
- If you are new to Selenoid and you want plug and play setup use automatic mode.
873
-
874
- Add plugin configuration in `codecept.conf.js`:
875
-
876
- ```js
877
- plugins: {
878
- selenoid: {
879
- enabled: true,
880
- deletePassed: true,
881
- autoCreate: true,
882
- autoStart: true,
883
- sessionTimeout: '30m',
884
- enableVideo: true,
885
- enableLog: true,
886
- },
887
- }
888
- ```
889
-
890
- When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][12] and start Selenoid automatically.
891
- It will also create `browsers.json` file required by Selenoid.
892
-
893
- In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
894
-
895
- > **If you are using Windows machine or if `autoCreate` does not work properly, create container manually**
896
-
897
- #### Manual
898
-
899
- While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
900
- This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
901
-
902
- > Use [Selenoid Configuration Manager][11] to create and start containers semi-automatically.
903
-
904
- 1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
905
- [Refer to Selenoid documentation][13] to know more about browsers.json.
906
-
907
- _Sample browsers.json_
908
-
909
- ```js
910
- {
911
- "chrome": {
912
- "default": "latest",
913
- "versions": {
914
- "latest": {
915
- "image": "selenoid/chrome:latest",
916
- "port": "4444",
917
- "path": "/"
918
- }
919
- }
920
- }
921
- }
922
- ```
923
-
924
- > It is recommended to use specific versions of browsers in `browsers.json` instead of latest. This will prevent tests fail when browsers will be updated.
925
-
926
- **⚠ At first launch selenoid plugin takes extra time to download all Docker images before tests starts**.
927
-
928
- 2. Create Selenoid container
929
-
930
- Run the following command to create a container. To know more [refer here][14]
931
-
932
- ```bash
933
- docker create \
934
- --name selenoid \
935
- -p 4444:4444 \
936
- -v /var/run/docker.sock:/var/run/docker.sock \
937
- -v `pwd`/:/etc/selenoid/:ro \
938
- -v `pwd`/output/video/:/opt/selenoid/video/ \
939
- -e OVERRIDE_VIDEO_OUTPUT_DIR=`pwd`/output/video/ \
940
- aerokube/selenoid:latest-release
941
- ```
942
-
943
- ### Video Recording
944
-
945
- This plugin allows to record and save video per each executed tests.
946
-
947
- When `enableVideo` is `true` this plugin saves video in `output/videos` directory with each test by name
948
- To save space videos for all succesful tests are deleted. This can be changed by `deletePassed` option.
949
-
950
- When `allure` plugin is enabled a video is attached to report automatically.
951
-
952
- ### Options:
953
-
954
- | Param | Description |
955
- | ---------------- | ------------------------------------------------------------------------------ |
956
- | name | Name of the container (default : selenoid) |
957
- | port | Port of selenium server (default : 4444) |
958
- | autoCreate | Will automatically create container (Linux only) (default : true) |
959
- | autoStart | If disabled start the container manually before running tests (default : true) |
960
- | enableVideo | Enable video recording and use `video` folder of output (default: false) |
961
- | enableLog | Enable log recording and use `logs` folder of output (default: false) |
962
- | deletePassed | Delete video and logs of passed tests (default : true) |
963
- | additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][15] to know more |
964
-
965
- ### Parameters
966
-
967
- - `config`
968
-
969
- ## stepByStepReport
970
-
971
- ![step-by-step-report][16]
972
-
973
- Generates step by step report for a test.
974
- After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow.
975
- By default, reports are generated only for failed tests.
976
-
977
- Run tests with plugin enabled:
978
-
979
- npx codeceptjs run --plugins stepByStepReport
980
-
981
- #### Configuration
982
-
983
- ```js
984
- "plugins": {
985
- "stepByStepReport": {
986
- "enabled": true
987
- }
988
- }
989
- ```
990
-
991
- Possible config options:
992
-
993
- - `deleteSuccessful`: do not save screenshots for successfully executed tests. Default: true.
994
- - `animateSlides`: should animation for slides to be used. Default: true.
995
- - `ignoreSteps`: steps to ignore in report. Array of RegExps is expected. Recommended to skip `grab*` and `wait*` steps.
996
- - `fullPageScreenshots`: should full page screenshots be used. Default: false.
997
- - `output`: a directory where reports should be stored. Default: `output`.
998
- - `screenshotsForAllureReport`: If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. Default: false.
999
- - \`disableScreenshotOnFail : Disables the capturing of screeshots after the failed step. Default: true.
1000
-
1001
- ### Parameters
1002
-
1003
- - `config` **any**
1004
-
1005
- ## stepTimeout
1006
-
1007
- Set timeout for test steps globally.
1008
-
1009
- Add this plugin to config file:
1010
-
1011
- ```js
1012
- plugins: {
1013
- stepTimeout: {
1014
- enabled: true
1015
- }
1016
- }
1017
- ```
1018
-
1019
- Run tests with plugin enabled:
1020
-
1021
- npx codeceptjs run --plugins stepTimeout
1022
-
1023
- #### Configuration:
1024
-
1025
- - `timeout` - global step timeout, default 150 seconds
1026
- - `overrideStepLimits` - whether to use timeouts set in plugin config to override step timeouts set in code with I.limitTime(x).action(...), default false
1027
- - `noTimeoutSteps` - an array of steps with no timeout. Default:
1028
-
1029
- - `amOnPage`
1030
- - `wait*`
1031
-
1032
- you could set your own noTimeoutSteps which would replace the default one.
1033
-
1034
- - `customTimeoutSteps` - an array of step actions with custom timeout. Use it to override or extend noTimeoutSteps.
1035
- You can use step names or step prefixes ending with `*`. As such, `wait*` will match all steps starting with `wait`.
1036
-
1037
- #### Example
1038
-
1039
- ```js
1040
- plugins: {
1041
- stepTimeout: {
1042
- enabled: true,
1043
- overrideStepLimits: true,
1044
- noTimeoutSteps: [
1045
- 'scroll*', // ignore all scroll steps
1046
- /Cookie/, // ignore all steps with a Cookie in it (by regexp)
1047
- ],
1048
- customTimeoutSteps: [
1049
- ['myFlakyStep*', 1],
1050
- ['scrollWhichRequiresTimeout', 5],
1051
- ]
1052
- }
1053
- }
1054
- ```
1055
-
1056
- ### Parameters
1057
-
1058
- - `config`
1059
-
1060
- ## subtitles
1061
-
1062
- Automatically captures steps as subtitle, and saves it as an artifact when a video is found for a failed test
1063
-
1064
- #### Configuration
1065
-
1066
- ```js
1067
- plugins: {
1068
- subtitles: {
1069
- enabled: true
1070
- }
1071
- }
1072
- ```
1073
-
1074
- ## tryTo
1075
-
1076
- Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
1077
-
1078
- Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
1079
-
1080
- ```js
1081
- plugins: {
1082
- tryTo: {
1083
- enabled: true
1084
- }
1085
- }
1086
- ```
1087
-
1088
- Use it in your tests:
1089
-
1090
- ```js
1091
- const result = await tryTo(() => I.see('Welcome'));
1092
-
1093
- // if text "Welcome" is on page, result => true
1094
- // if text "Welcome" is not on page, result => false
1095
- ```
1096
-
1097
- Disables retryFailedStep plugin for steps inside a block;
1098
-
1099
- Use this plugin if:
1100
-
1101
- - you need to perform multiple assertions inside a test
1102
- - there is A/B testing on a website you test
1103
- - there is "Accept Cookie" banner which may surprisingly appear on a page.
1104
-
1105
- #### Usage
1106
-
1107
- #### Multiple Conditional Assertions
1108
-
1109
- ````js
1110
- Add assert requires first:
1111
- ```js
1112
- const assert = require('assert');
1113
- ````
1114
-
1115
- Then use the assertion:
1116
- const result1 = await tryTo(() => I.see('Hello, user'));
1117
- const result2 = await tryTo(() => I.seeElement('.welcome'));
1118
- assert.ok(result1 && result2, 'Assertions were not succesful');
1119
-
1120
- ##### Optional click
1121
-
1122
- ```js
1123
- I.amOnPage('/');
1124
- tryTo(() => I.click('Agree', '.cookies'));
1125
-
1126
- #### Configuration
1127
-
1128
- - `registerGlobal` - to register `tryTo` function globally, true by default
1129
-
1130
- If `registerGlobal` is false you can use tryTo from the plugin:
1131
-
1132
- ```js
1133
- const tryTo = codeceptjs.container.plugins('tryTo');
1134
- ```
1135
-
1136
- ### Parameters
1137
-
1138
- - `config`
1139
-
1140
- ## wdio
1141
-
1142
- Webdriverio services runner.
1143
-
1144
- This plugin allows to run webdriverio services like:
1145
-
1146
- - selenium-standalone
1147
- - sauce
1148
- - testingbot
1149
- - browserstack
1150
- - appium
1151
-
1152
- A complete list of all available services can be found on [webdriverio website][17].
1153
-
1154
- #### Setup
1155
-
1156
- 1. Install a webdriverio service
1157
- 2. Enable `wdio` plugin in config
1158
- 3. Add service name to `services` array inside wdio plugin config.
1159
-
1160
- See examples below:
1161
-
1162
- #### Selenium Standalone Service
1163
-
1164
- Install `@wdio/selenium-standalone-service` package, as [described here][18].
1165
- It is important to make sure it is compatible with current webdriverio version.
1166
-
1167
- Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
1168
-
1169
- ```js
1170
- plugins: {
1171
- wdio: {
1172
- enabled: true,
1173
- services: ['selenium-standalone']
1174
- // additional config for service can be passed here
1175
- }
1176
- }
1177
- ```
1178
-
1179
- #### Sauce Service
1180
-
1181
- Install `@wdio/sauce-service` package, as [described here][19].
1182
- It is important to make sure it is compatible with current webdriverio version.
1183
-
1184
- Enable `wdio` plugin in plugins list and add `sauce` service:
1185
-
1186
- ```js
1187
- plugins: {
1188
- wdio: {
1189
- enabled: true,
1190
- services: ['sauce'],
1191
- user: ... ,// saucelabs username
1192
- key: ... // saucelabs api key
1193
- // additional config, from sauce service
1194
- }
1195
- }
1196
- ```
1197
-
1198
- * * *
1199
-
1200
- In the same manner additional services from webdriverio can be installed, enabled, and configured.
1201
-
1202
- #### Configuration
1203
-
1204
- - `services` - list of enabled services
1205
- - ... - additional configuration passed into services.
1206
-
1207
- ### Parameters
1208
-
1209
- - `config`
1210
-
1211
- [1]: https://codecept.io/locators#custom-locators
1212
-
1213
- [2]: https://playwright.dev/docs/api/class-elementhandle
1214
-
1215
- [3]: https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle
1216
-
1217
- [4]: https://webdriver.io/docs/api
1218
-
1219
- [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
1220
-
1221
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1222
-
1223
- [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
1224
-
1225
- [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
1226
-
1227
- [9]: /basics/#pause
1228
-
1229
- [10]: https://aerokube.com/selenoid/
1230
-
1231
- [11]: https://aerokube.com/cm/latest/
1232
-
1233
- [12]: https://hub.docker.com/u/selenoid
1234
-
1235
- [13]: https://aerokube.com/selenoid/latest/#_prepare_configuration
1236
-
1237
- [14]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
1238
-
1239
- [15]: https://docs.docker.com/engine/reference/commandline/create/
1240
-
1241
- [16]: https://codecept.io/img/codeceptjs-slideshow.gif
1242
-
1243
- [17]: https://webdriver.io
1244
-
1245
- [18]: https://webdriver.io/docs/selenium-standalone-service.html
1246
-
1247
- [19]: https://webdriver.io/docs/sauce-service.html