codeceptjs 3.6.10 → 3.7.0-beta.10

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 (127) hide show
  1. package/README.md +89 -119
  2. package/bin/codecept.js +9 -2
  3. package/docs/webapi/clearCookie.mustache +1 -1
  4. package/lib/actor.js +66 -102
  5. package/lib/ai.js +130 -121
  6. package/lib/assert/empty.js +3 -5
  7. package/lib/assert/equal.js +4 -7
  8. package/lib/assert/include.js +4 -6
  9. package/lib/assert/throws.js +2 -4
  10. package/lib/assert/truth.js +2 -2
  11. package/lib/codecept.js +87 -83
  12. package/lib/command/check.js +186 -0
  13. package/lib/command/configMigrate.js +2 -4
  14. package/lib/command/definitions.js +8 -26
  15. package/lib/command/generate.js +10 -14
  16. package/lib/command/gherkin/snippets.js +10 -8
  17. package/lib/command/gherkin/steps.js +1 -1
  18. package/lib/command/info.js +1 -3
  19. package/lib/command/init.js +8 -12
  20. package/lib/command/interactive.js +2 -2
  21. package/lib/command/list.js +1 -1
  22. package/lib/command/run-multiple.js +12 -35
  23. package/lib/command/run-workers.js +5 -57
  24. package/lib/command/utils.js +5 -6
  25. package/lib/command/workers/runTests.js +68 -232
  26. package/lib/container.js +354 -237
  27. package/lib/data/context.js +10 -13
  28. package/lib/data/dataScenarioConfig.js +8 -8
  29. package/lib/data/dataTableArgument.js +6 -6
  30. package/lib/data/table.js +5 -11
  31. package/lib/effects.js +218 -0
  32. package/lib/els.js +158 -0
  33. package/lib/event.js +19 -17
  34. package/lib/heal.js +88 -80
  35. package/lib/helper/AI.js +2 -1
  36. package/lib/helper/ApiDataFactory.js +3 -6
  37. package/lib/helper/Appium.js +45 -51
  38. package/lib/helper/FileSystem.js +3 -3
  39. package/lib/helper/GraphQLDataFactory.js +3 -3
  40. package/lib/helper/JSONResponse.js +57 -37
  41. package/lib/helper/Nightmare.js +35 -53
  42. package/lib/helper/Playwright.js +211 -252
  43. package/lib/helper/Protractor.js +54 -77
  44. package/lib/helper/Puppeteer.js +139 -232
  45. package/lib/helper/REST.js +5 -17
  46. package/lib/helper/TestCafe.js +21 -44
  47. package/lib/helper/WebDriver.js +131 -169
  48. package/lib/helper/testcafe/testcafe-utils.js +26 -27
  49. package/lib/listener/emptyRun.js +55 -0
  50. package/lib/listener/exit.js +7 -10
  51. package/lib/listener/{retry.js → globalRetry.js} +5 -5
  52. package/lib/listener/globalTimeout.js +165 -0
  53. package/lib/listener/helpers.js +15 -15
  54. package/lib/listener/mocha.js +1 -1
  55. package/lib/listener/result.js +12 -0
  56. package/lib/listener/steps.js +20 -18
  57. package/lib/listener/store.js +20 -0
  58. package/lib/mocha/asyncWrapper.js +216 -0
  59. package/lib/{interfaces → mocha}/bdd.js +3 -3
  60. package/lib/mocha/cli.js +308 -0
  61. package/lib/mocha/factory.js +104 -0
  62. package/lib/{interfaces → mocha}/featureConfig.js +24 -12
  63. package/lib/{interfaces → mocha}/gherkin.js +26 -28
  64. package/lib/mocha/hooks.js +112 -0
  65. package/lib/mocha/index.js +12 -0
  66. package/lib/mocha/inject.js +29 -0
  67. package/lib/{interfaces → mocha}/scenarioConfig.js +21 -6
  68. package/lib/mocha/suite.js +81 -0
  69. package/lib/mocha/test.js +159 -0
  70. package/lib/mocha/types.d.ts +42 -0
  71. package/lib/mocha/ui.js +219 -0
  72. package/lib/output.js +82 -62
  73. package/lib/pause.js +155 -138
  74. package/lib/plugin/analyze.js +349 -0
  75. package/lib/plugin/autoDelay.js +6 -6
  76. package/lib/plugin/autoLogin.js +6 -7
  77. package/lib/plugin/commentStep.js +6 -1
  78. package/lib/plugin/coverage.js +10 -19
  79. package/lib/plugin/customLocator.js +3 -3
  80. package/lib/plugin/customReporter.js +52 -0
  81. package/lib/plugin/eachElement.js +1 -1
  82. package/lib/plugin/fakerTransform.js +1 -1
  83. package/lib/plugin/heal.js +36 -9
  84. package/lib/plugin/pageInfo.js +140 -0
  85. package/lib/plugin/retryFailedStep.js +4 -4
  86. package/lib/plugin/retryTo.js +18 -118
  87. package/lib/plugin/screenshotOnFail.js +17 -49
  88. package/lib/plugin/selenoid.js +15 -35
  89. package/lib/plugin/standardActingHelpers.js +4 -1
  90. package/lib/plugin/stepByStepReport.js +56 -17
  91. package/lib/plugin/stepTimeout.js +5 -12
  92. package/lib/plugin/subtitles.js +4 -4
  93. package/lib/plugin/tryTo.js +17 -107
  94. package/lib/plugin/wdio.js +8 -10
  95. package/lib/recorder.js +146 -125
  96. package/lib/rerun.js +43 -42
  97. package/lib/result.js +161 -0
  98. package/lib/secret.js +1 -1
  99. package/lib/step/base.js +228 -0
  100. package/lib/step/config.js +50 -0
  101. package/lib/step/func.js +46 -0
  102. package/lib/step/helper.js +50 -0
  103. package/lib/step/meta.js +99 -0
  104. package/lib/step/record.js +74 -0
  105. package/lib/step/retry.js +11 -0
  106. package/lib/step/section.js +55 -0
  107. package/lib/step.js +21 -332
  108. package/lib/steps.js +50 -0
  109. package/lib/store.js +10 -2
  110. package/lib/template/heal.js +2 -11
  111. package/lib/timeout.js +66 -0
  112. package/lib/utils.js +317 -216
  113. package/lib/within.js +73 -55
  114. package/lib/workers.js +259 -275
  115. package/package.json +56 -54
  116. package/typings/index.d.ts +175 -186
  117. package/typings/promiseBasedTypes.d.ts +164 -17
  118. package/typings/types.d.ts +284 -115
  119. package/lib/cli.js +0 -256
  120. package/lib/helper/ExpectHelper.js +0 -391
  121. package/lib/helper/SoftExpectHelper.js +0 -381
  122. package/lib/listener/artifacts.js +0 -19
  123. package/lib/listener/timeout.js +0 -109
  124. package/lib/mochaFactory.js +0 -113
  125. package/lib/plugin/debugErrors.js +0 -67
  126. package/lib/scenario.js +0 -224
  127. package/lib/ui.js +0 -236
package/README.md CHANGED
@@ -1,20 +1,17 @@
1
1
  [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)
2
2
 
3
-
4
-
5
3
  [<img src="https://img.shields.io/badge/slack-@codeceptjs-purple.svg?logo=slack">](https://join.slack.com/t/codeceptjs/shared_invite/enQtMzA5OTM4NDM2MzA4LWE4MThhN2NmYTgxNTU5MTc4YzAyYWMwY2JkMmZlYWI5MWQ2MDM5MmRmYzZmYmNiNmY5NTAzM2EwMGIwOTNhOGQ) [<img src="https://img.shields.io/badge/discourse-codeceptjs-purple">](https://codecept.discourse.group) [![NPM version][npm-image]][npm-url] [<img src="https://img.shields.io/badge/dockerhub-images-blue.svg?logo=codeceptjs">](https://hub.docker.com/r/codeceptjs/codeceptjs)
6
- [![AI features](https://img.shields.io/badge/AI-features?logo=openai&logoColor=white)](https://github.com/codeceptjs/CodeceptJS/edit/3.x/docs/ai.md) [![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
7
-
8
- Build Status:
4
+ [![AI features](https://img.shields.io/badge/AI-features?logo=openai&logoColor=white)](https://github.com/codeceptjs/CodeceptJS/edit/3.x/docs/ai.md) [![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
9
5
 
10
- Appium Helper:
11
- [![Appium V2 Tests - Android](https://github.com/codeceptjs/CodeceptJS/actions/workflows/appiumV2_Android.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/appiumV2_Android.yml)
6
+ ## Build Status
12
7
 
13
- Web Helper:
14
- [![Playwright Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/playwright.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/playwright.yml)
15
- [![Puppeteer Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/puppeteer.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/puppeteer.yml)
16
- [![WebDriver Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/webdriver.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/webdriver.yml)
17
- [![TestCafe Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/testcafe.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/testcafe.yml)
8
+ | Type | Engine | Status |
9
+ | --------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
10
+ | 🌐 Web | Playwright | [![Playwright Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/playwright.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/playwright.yml) |
11
+ | 🌐 Web | Puppeteer | [![Puppeteer Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/puppeteer.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/puppeteer.yml) |
12
+ | 🌐 Web | WebDriver | [![WebDriver Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/webdriver.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/webdriver.yml) |
13
+ | 🌐 Web | TestCafe | [![TestCafe Tests](https://github.com/codeceptjs/CodeceptJS/actions/workflows/testcafe.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/testcafe.yml) |
14
+ | 📱 Mobile | Appium | [![Appium Tests - Android](https://github.com/codeceptjs/CodeceptJS/actions/workflows/appium_Android.yml/badge.svg)](https://github.com/codeceptjs/CodeceptJS/actions/workflows/appium_Android.yml) |
18
15
 
19
16
  # CodeceptJS [![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua)
20
17
 
@@ -27,28 +24,28 @@ It abstracts browser interaction to simple steps that are written from a user's
27
24
  A simple test that verifies the "Welcome" text is present on a main page of a site will look like:
28
25
 
29
26
  ```js
30
- Feature('CodeceptJS demo');
27
+ Feature('CodeceptJS demo')
31
28
 
32
29
  Scenario('check Welcome page on site', ({ I }) => {
33
- I.amOnPage('/');
34
- I.see('Welcome');
35
- });
30
+ I.amOnPage('/')
31
+ I.see('Welcome')
32
+ })
36
33
  ```
37
34
 
38
35
  CodeceptJS tests are:
39
36
 
40
- * **Synchronous**. You don't need to care about callbacks or promises or test scenarios which are linear. But, your tests should be linear.
41
- * Written from **user's perspective**. Every action is a method of `I`. That makes test easy to read, write and maintain even for non-tech persons.
42
- * Backend **API agnostic**. We don't know which WebDriver implementation is running this test.
37
+ - **Synchronous**. You don't need to care about callbacks or promises or test scenarios which are linear. But, your tests should be linear.
38
+ - Written from **user's perspective**. Every action is a method of `I`. That makes test easy to read, write and maintain even for non-tech persons.
39
+ - Backend **API agnostic**. We don't know which WebDriver implementation is running this test.
43
40
 
44
41
  CodeceptJS uses **Helper** modules to provide actions to `I` object. Currently, CodeceptJS has these helpers:
45
42
 
46
- * [**Playwright**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Playwright.md) - is a Node library to automate the Chromium, WebKit and Firefox browsers with a single API.
47
- * [**Puppeteer**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Puppeteer.md) - uses Google Chrome's Puppeteer for fast headless testing.
48
- * [**WebDriver**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/WebDriver.md) - uses [webdriverio](http://webdriver.io/) to run tests via WebDriver or Devtools protocol.
49
- * [**TestCafe**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/TestCafe.md) - cheap and fast cross-browser test automation.
50
- * [**Appium**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Appium.md) - for **mobile testing** with Appium
51
- * [**Detox**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Detox.md) - This is a wrapper on top of Detox library, aimed to unify testing experience for CodeceptJS framework. Detox provides a grey box testing for mobile applications, playing especially well for React Native apps.
43
+ - [**Playwright**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Playwright.md) - is a Node library to automate the Chromium, WebKit and Firefox browsers with a single API.
44
+ - [**Puppeteer**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Puppeteer.md) - uses Google Chrome's Puppeteer for fast headless testing.
45
+ - [**WebDriver**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/WebDriver.md) - uses [webdriverio](http://webdriver.io/) to run tests via WebDriver or Devtools protocol.
46
+ - [**TestCafe**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/TestCafe.md) - cheap and fast cross-browser test automation.
47
+ - [**Appium**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Appium.md) - for **mobile testing** with Appium
48
+ - [**Detox**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Detox.md) - This is a wrapper on top of Detox library, aimed to unify testing experience for CodeceptJS framework. Detox provides a grey box testing for mobile applications, playing especially well for React Native apps.
52
49
 
53
50
  And more to come...
54
51
 
@@ -58,17 +55,16 @@ CodeceptJS is a successor of [Codeception](http://codeception.com), a popular fu
58
55
  With CodeceptJS your scenario-driven functional and acceptance tests will be as simple and clean as they can be.
59
56
  You don't need to worry about asynchronous nature of NodeJS or about various APIs of Playwright, Selenium, Puppeteer, TestCafe, etc. as CodeceptJS unifies them and makes them work as they are synchronous.
60
57
 
61
-
62
58
  ## Features
63
-
64
- * 🪄 **AI-powered** with GPT features to assist and heal failing tests.
65
- * ☕ Based on [Mocha](https://mochajs.org/) testing framework.
66
- * 💼 Designed for scenario driven acceptance testing in BDD-style.
67
- * 💻 Uses ES6 natively without transpiler.
68
- * Also plays nice with TypeScript.
69
- * </> Smart locators: use names, labels, matching text, CSS or XPath to locate elements.
70
- * 🌐 Interactive debugging shell: pause test at any point and try different commands in a browser.
71
- * Easily create tests, pageobjects, stepobjects with CLI generators.
59
+
60
+ - 🪄 **AI-powered** with GPT features to assist and heal failing tests.
61
+ - ☕ Based on [Mocha](https://mochajs.org/) testing framework.
62
+ - 💼 Designed for scenario driven acceptance testing in BDD-style.
63
+ - 💻 Uses ES6 natively without transpiler.
64
+ - Also plays nice with TypeScript.
65
+ - </> Smart locators: use names, labels, matching text, CSS or XPath to locate elements.
66
+ - 🌐 Interactive debugging shell: pause test at any point and try different commands in a browser.
67
+ - Easily create tests, pageobjects, stepobjects with CLI generators.
72
68
 
73
69
  ## Installation
74
70
 
@@ -105,7 +101,8 @@ npx codeceptjs def .
105
101
  Later you can even automagically update Type Definitions to include your own custom [helpers methods](docs/helpers.md).
106
102
 
107
103
  Note:
108
- - CodeceptJS requires Node.js version `12+` or later.
104
+
105
+ - CodeceptJS requires Node.js version `12+` or later.
109
106
 
110
107
  ## Usage
111
108
 
@@ -116,18 +113,18 @@ Learn CodeceptJS by examples. Let's assume we have CodeceptJS installed and WebD
116
113
  Let's see how we can handle basic form testing:
117
114
 
118
115
  ```js
119
- Feature('CodeceptJS Demonstration');
116
+ Feature('CodeceptJS Demonstration')
120
117
 
121
118
  Scenario('test some forms', ({ I }) => {
122
- I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation');
123
- I.fillField('Email', 'hello@world.com');
124
- I.fillField('Password', secret('123456'));
125
- I.checkOption('Active');
126
- I.checkOption('Male');
127
- I.click('Create User');
128
- I.see('User is valid');
129
- I.dontSeeInCurrentUrl('/documentation');
130
- });
119
+ I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation')
120
+ I.fillField('Email', 'hello@world.com')
121
+ I.fillField('Password', secret('123456'))
122
+ I.checkOption('Active')
123
+ I.checkOption('Male')
124
+ I.click('Create User')
125
+ I.see('User is valid')
126
+ I.dontSeeInCurrentUrl('/documentation')
127
+ })
131
128
  ```
132
129
 
133
130
  All actions are performed by `I` object; assertions functions start with `see` function.
@@ -172,11 +169,11 @@ The same way you can locate element by name, `CSS` or `XPath` locators in tests:
172
169
 
173
170
  ```js
174
171
  // by name
175
- I.fillField('user_basic[email]', 'hello@world.com');
172
+ I.fillField('user_basic[email]', 'hello@world.com')
176
173
  // by CSS
177
- I.fillField('#user_basic_email', 'hello@world.com');
174
+ I.fillField('#user_basic_email', 'hello@world.com')
178
175
  // don't make us guess locator type, specify it
179
- I.fillField({css: '#user_basic_email'}, 'hello@world.com');
176
+ I.fillField({ css: '#user_basic_email' }, 'hello@world.com')
180
177
  ```
181
178
 
182
179
  Other methods like `checkOption`, and `click` work in a similar manner. They can take labels or CSS or XPath locators to find elements to interact.
@@ -187,9 +184,9 @@ Assertions start with `see` or `dontSee` prefix. In our case we are asserting th
187
184
  However, we can narrow the search to particular element by providing a second parameter:
188
185
 
189
186
  ```js
190
- I.see('User is valid');
187
+ I.see('User is valid')
191
188
  // better to specify context:
192
- I.see('User is valid', '.alert-success');
189
+ I.see('User is valid', '.alert-success')
193
190
  ```
194
191
 
195
192
  In this case 'User is valid' string will be searched only inside elements located by CSS `.alert-success`.
@@ -200,13 +197,13 @@ In case you need to return a value from a webpage and use it directly in test, y
200
197
  They are expected to be used inside `async/await` functions, and their results will be available in test:
201
198
 
202
199
  ```js
203
- Feature('CodeceptJS Demonstration');
200
+ Feature('CodeceptJS Demonstration')
204
201
 
205
202
  Scenario('test page title', async ({ I }) => {
206
- I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation');
207
- const title = await I.grabTitle();
208
- I.expectEqual(title, 'Example application with SimpleForm and Twitter Bootstrap'); // Avaiable with Expect helper. -> https://codecept.io/helpers/Expect/
209
- });
203
+ I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation')
204
+ const title = await I.grabTitle()
205
+ I.expectEqual(title, 'Example application with SimpleForm and Twitter Bootstrap') // Avaiable with Expect helper. -> https://codecept.io/helpers/Expect/
206
+ })
210
207
  ```
211
208
 
212
209
  The same way you can grab text, attributes, or form values and use them in next test steps.
@@ -216,23 +213,24 @@ The same way you can grab text, attributes, or form values and use them in next
216
213
  Common preparation steps like opening a web page, logging in a user, can be placed in `Before` or `Background`:
217
214
 
218
215
  ```js
219
- const { I } = inject();
216
+ const { I } = inject()
220
217
 
221
- Feature('CodeceptJS Demonstration');
218
+ Feature('CodeceptJS Demonstration')
222
219
 
223
- Before(() => { // or Background
224
- I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation');
225
- });
220
+ Before(() => {
221
+ // or Background
222
+ I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation')
223
+ })
226
224
 
227
225
  Scenario('test some forms', () => {
228
- I.click('Create User');
229
- I.see('User is valid');
230
- I.dontSeeInCurrentUrl('/documentation');
231
- });
226
+ I.click('Create User')
227
+ I.see('User is valid')
228
+ I.dontSeeInCurrentUrl('/documentation')
229
+ })
232
230
 
233
231
  Scenario('test title', () => {
234
- I.seeInTitle('Example application');
235
- });
232
+ I.seeInTitle('Example application')
233
+ })
236
234
  ```
237
235
 
238
236
  ## PageObjects
@@ -248,83 +246,55 @@ It will create a page object file for you and add it to the config.
248
246
  Let's assume we created one named `docsPage`:
249
247
 
250
248
  ```js
251
- const { I } = inject();
249
+ const { I } = inject()
252
250
 
253
251
  module.exports = {
254
252
  fields: {
255
253
  email: '#user_basic_email',
256
- password: '#user_basic_password'
254
+ password: '#user_basic_password',
257
255
  },
258
- submitButton: {css: '#new_user_basic input[type=submit]'},
256
+ submitButton: { css: '#new_user_basic input[type=submit]' },
259
257
 
260
258
  sendForm(email, password) {
261
- I.fillField(this.fields.email, email);
262
- I.fillField(this.fields.password, password);
263
- I.click(this.submitButton);
264
- }
259
+ I.fillField(this.fields.email, email)
260
+ I.fillField(this.fields.password, password)
261
+ I.click(this.submitButton)
262
+ },
265
263
  }
266
264
  ```
267
265
 
268
266
  You can easily inject it to test by providing its name in test arguments:
269
267
 
270
268
  ```js
271
- Feature('CodeceptJS Demonstration');
269
+ Feature('CodeceptJS Demonstration')
272
270
 
273
- Before(({ I }) => { // or Background
274
- I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation');
275
- });
271
+ Before(({ I }) => {
272
+ // or Background
273
+ I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation')
274
+ })
276
275
 
277
276
  Scenario('test some forms', ({ I, docsPage }) => {
278
- docsPage.sendForm('hello@world.com','123456');
279
- I.see('User is valid');
280
- I.dontSeeInCurrentUrl('/documentation');
281
- });
277
+ docsPage.sendForm('hello@world.com', '123456')
278
+ I.see('User is valid')
279
+ I.dontSeeInCurrentUrl('/documentation')
280
+ })
282
281
  ```
283
282
 
284
283
  When using Typescript, replace `module.exports` with `export` for autocompletion.
285
284
 
286
-
287
285
  ## Contributing
288
286
 
289
- - ### [Contributing Guide](https://github.com/codeceptjs/CodeceptJS/blob/master/.github/CONTRIBUTING.md)
290
- - ### [Code of conduct](https://github.com/codeceptjs/CodeceptJS/blob/master/.github/CODE_OF_CONDUCT.md)
291
-
287
+ - ### [Contributing Guide](https://github.com/codeceptjs/CodeceptJS/blob/master/.github/CONTRIBUTING.md)
288
+ - ### [Code of conduct](https://github.com/codeceptjs/CodeceptJS/blob/master/.github/CODE_OF_CONDUCT.md)
292
289
 
293
290
  ## Contributors
294
291
 
295
- Thanks all to those who are and will have contributing to this awesome project!
296
-
297
- [//]: contributor-faces
298
- <a href="https://github.com/DavertMik"><img src="https://avatars.githubusercontent.com/u/220264?v=4" title="DavertMik" width="80" height="80"></a>
299
- <a href="https://github.com/kobenguyent"><img src="https://avatars.githubusercontent.com/u/7845001?v=4" title="kobenguyent" width="80" height="80"></a>
300
- <a href="https://github.com/Vorobeyko"><img src="https://avatars.githubusercontent.com/u/11293201?v=4" title="Vorobeyko" width="80" height="80"></a>
301
- <a href="https://github.com/reubenmiller"><img src="https://avatars.githubusercontent.com/u/3029781?v=4" title="reubenmiller" width="80" height="80"></a>
302
- <a href="https://github.com/Arhell"><img src="https://avatars.githubusercontent.com/u/26163841?v=4" title="Arhell" width="80" height="80"></a>
303
- <a href="https://github.com/APshenkin"><img src="https://avatars.githubusercontent.com/u/14344430?v=4" title="APshenkin" width="80" height="80"></a>
304
- <a href="https://github.com/fabioel"><img src="https://avatars.githubusercontent.com/u/9824235?v=4" title="fabioel" width="80" height="80"></a>
305
- <a href="https://github.com/pablopaul"><img src="https://avatars.githubusercontent.com/u/635526?v=4" title="pablopaul" width="80" height="80"></a>
306
- <a href="https://github.com/mirao"><img src="https://avatars.githubusercontent.com/u/12584138?v=4" title="mirao" width="80" height="80"></a>
307
- <a href="https://github.com/Georgegriff"><img src="https://avatars.githubusercontent.com/u/9056958?v=4" title="Georgegriff" width="80" height="80"></a>
308
- <a href="https://github.com/KMKoushik"><img src="https://avatars.githubusercontent.com/u/24666922?v=4" title="KMKoushik" width="80" height="80"></a>
309
- <a href="https://github.com/nikocanvacom"><img src="https://avatars.githubusercontent.com/u/83254493?v=4" title="nikocanvacom" width="80" height="80"></a>
310
- <a href="https://github.com/elukoyanov"><img src="https://avatars.githubusercontent.com/u/11647141?v=4" title="elukoyanov" width="80" height="80"></a>
311
- <a href="https://github.com/gkushang"><img src="https://avatars.githubusercontent.com/u/3663389?v=4" title="gkushang" width="80" height="80"></a>
312
- <a href="https://github.com/tsuemura"><img src="https://avatars.githubusercontent.com/u/17092259?v=4" title="tsuemura" width="80" height="80"></a>
313
- <a href="https://github.com/EgorBodnar"><img src="https://avatars.githubusercontent.com/u/63167966?v=4" title="EgorBodnar" width="80" height="80"></a>
314
- <a href="https://github.com/VikalpP"><img src="https://avatars.githubusercontent.com/u/11846339?v=4" title="VikalpP" width="80" height="80"></a>
315
- <a href="https://github.com/thomashohn"><img src="https://avatars.githubusercontent.com/u/3414869?v=4" title="thomashohn" width="80" height="80"></a>
316
- <a href="https://github.com/elaichenkov"><img src="https://avatars.githubusercontent.com/u/29764053?v=4" title="elaichenkov" width="80" height="80"></a>
317
- <a href="https://github.com/BorisOsipov"><img src="https://avatars.githubusercontent.com/u/6514276?v=4" title="BorisOsipov" width="80" height="80"></a>
318
- <a href="https://github.com/ngraf"><img src="https://avatars.githubusercontent.com/u/7094389?v=4" title="ngraf" width="80" height="80"></a>
319
- <a href="https://github.com/nitschSB"><img src="https://avatars.githubusercontent.com/u/39341455?v=4" title="nitschSB" width="80" height="80"></a>
320
- <a href="https://github.com/hubidu"><img src="https://avatars.githubusercontent.com/u/13134082?v=4" title="hubidu" width="80" height="80"></a>
321
- <a href="https://github.com/jploskonka"><img src="https://avatars.githubusercontent.com/u/669483?v=4" title="jploskonka" width="80" height="80"></a>
322
- <a href="https://github.com/maojunxyz"><img src="https://avatars.githubusercontent.com/u/28778042?v=4" title="maojunxyz" width="80" height="80"></a>
323
- <a href="https://github.com/abhimanyupandian"><img src="https://avatars.githubusercontent.com/u/36107381?v=4" title="abhimanyupandian" width="80" height="80"></a>
324
- <a href="https://github.com/martomo"><img src="https://avatars.githubusercontent.com/u/1850135?v=4" title="martomo" width="80" height="80"></a>
325
- <a href="https://github.com/hatufacci"><img src="https://avatars.githubusercontent.com/u/4963181?v=4" title="hatufacci" width="80" height="80"></a>
326
-
327
- [//]: contributor-faces
292
+ Thanks to our awesome contributors! 🎉
293
+ <a href="https://github.com/codeceptjs/codeceptjs/graphs/contributors">
294
+ <img src="https://contrib.rocks/image?repo=codeceptjs/codeceptjs" />
295
+ </a>
296
+
297
+ Made with [contrib.rocks](https://contrib.rocks).
328
298
 
329
299
  ## License
330
300
 
package/bin/codecept.js CHANGED
@@ -32,7 +32,7 @@ const commandFlags = {
32
32
  }
33
33
 
34
34
  const errorHandler =
35
- (fn) =>
35
+ fn =>
36
36
  async (...args) => {
37
37
  try {
38
38
  await fn(...args)
@@ -58,6 +58,13 @@ program
58
58
  .description('Creates dummy config in current dir or [path]')
59
59
  .action(errorHandler(require('../lib/command/init')))
60
60
 
61
+ program
62
+ .command('check')
63
+ .option(commandFlags.config.flag, commandFlags.config.description)
64
+ .description('Checks configuration and environment before running tests')
65
+ .option('-t, --timeout [ms]', 'timeout for checks in ms, 20000 by default')
66
+ .action(errorHandler(require('../lib/command/check')))
67
+
61
68
  program
62
69
  .command('migrate [path]')
63
70
  .description('Migrate json config to js config in current dir or [path]')
@@ -286,7 +293,7 @@ program
286
293
 
287
294
  .action(require('../lib/command/run-rerun'))
288
295
 
289
- program.on('command:*', (cmd) => {
296
+ program.on('command:*', cmd => {
290
297
  console.log(`\nUnknown command ${cmd}\n`)
291
298
  program.outputHelp()
292
299
  })
@@ -3,7 +3,7 @@ if none provided clears all cookies.
3
3
 
4
4
  ```js
5
5
  I.clearCookie();
6
- I.clearCookie('test'); // Playwright currently doesn't support clear a particular cookie name
6
+ I.clearCookie('test');
7
7
  ```
8
8
 
9
9
  @param {?string} [cookie=null] (optional, `null` by default) cookie name
package/lib/actor.js CHANGED
@@ -1,11 +1,12 @@
1
- const Step = require('./step');
2
- const { MetaStep } = require('./step');
3
- const container = require('./container');
4
- const { methodsOfObject } = require('./utils');
5
- const recorder = require('./recorder');
6
- const event = require('./event');
7
- const store = require('./store');
8
- const output = require('./output');
1
+ const Step = require('./step')
2
+ const MetaStep = require('./step/meta')
3
+ const recordStep = require('./step/record')
4
+ const container = require('./container')
5
+ const { methodsOfObject } = require('./utils')
6
+ const { TIMEOUT_ORDER } = require('./timeout')
7
+ const event = require('./event')
8
+ const store = require('./store')
9
+ const output = require('./output')
9
10
 
10
11
  /**
11
12
  * @interface
@@ -21,13 +22,13 @@ class Actor {
21
22
  * ⚠️ returns a promise which is synchronized internally by recorder
22
23
  */
23
24
  async say(msg, color = 'cyan') {
24
- const step = new Step('say', 'say');
25
- step.status = 'passed';
25
+ const step = new Step('say', 'say')
26
+ step.status = 'passed'
26
27
  return recordStep(step, [msg]).then(() => {
27
28
  // this is backward compatibility as this event may be used somewhere
28
- event.emit(event.step.comment, msg);
29
- output.say(msg, `${color}`);
30
- });
29
+ event.emit(event.step.comment, msg)
30
+ output.say(msg, `${color}`)
31
+ })
31
32
  }
32
33
 
33
34
  /**
@@ -38,14 +39,16 @@ class Actor {
38
39
  * @inner
39
40
  */
40
41
  limitTime(timeout) {
41
- if (!store.timeouts) return this;
42
+ if (!store.timeouts) return this
42
43
 
43
- event.dispatcher.prependOnceListener(event.step.before, (step) => {
44
- output.log(`Timeout to ${step}: ${timeout}s`);
45
- step.setTimeout(timeout * 1000, Step.TIMEOUT_ORDER.codeLimitTime);
46
- });
44
+ console.log('I.limitTime() is deprecated, use step.timeout() instead')
47
45
 
48
- return this;
46
+ event.dispatcher.prependOnceListener(event.step.before, step => {
47
+ output.log(`Timeout to ${step}: ${timeout}s`)
48
+ step.setTimeout(timeout * 1000, TIMEOUT_ORDER.codeLimitTime)
49
+ })
50
+
51
+ return this
49
52
  }
50
53
 
51
54
  /**
@@ -55,11 +58,10 @@ class Actor {
55
58
  * @inner
56
59
  */
57
60
  retry(opts) {
58
- if (opts === undefined) opts = 1;
59
- recorder.retry(opts);
60
- // remove retry once the step passed
61
- recorder.add(() => event.dispatcher.once(event.step.finished, () => recorder.retries.pop()));
62
- return this;
61
+ console.log('I.retry() is deprecated, use step.retry() instead')
62
+ const retryStep = require('./step/retry')
63
+ retryStep(opts)
64
+ return this
63
65
  }
64
66
  }
65
67
 
@@ -70,92 +72,54 @@ class Actor {
70
72
  * @ignore
71
73
  */
72
74
  module.exports = function (obj = {}) {
73
- if (!store.actor) {
74
- store.actor = new Actor();
75
- }
76
- const actor = store.actor;
77
-
78
- const translation = container.translation();
79
-
80
- if (Object.keys(obj).length > 0) {
81
- Object.keys(obj)
82
- .forEach(action => {
83
- const actionAlias = translation.actionAliasFor(action);
75
+ const actor = container.actor() || new Actor()
84
76
 
85
- const currentMethod = obj[action];
86
- const ms = new MetaStep('I', action);
87
- if (translation.loaded) {
88
- ms.name = actionAlias;
89
- ms.actor = translation.I;
90
- }
91
- ms.setContext(actor);
92
- actor[action] = actor[actionAlias] = ms.run.bind(ms, currentMethod);
93
- });
94
- }
95
-
96
- const helpers = container.helpers();
77
+ // load all helpers once container initialized
78
+ container.started(() => {
79
+ const translation = container.translation()
80
+ const helpers = container.helpers()
97
81
 
98
- // add methods from enabled helpers
99
- Object.values(helpers)
100
- .forEach((helper) => {
82
+ // add methods from enabled helpers
83
+ Object.values(helpers).forEach(helper => {
101
84
  methodsOfObject(helper, 'Helper')
102
85
  .filter(method => method !== 'constructor' && method[0] !== '_')
103
- .forEach((action) => {
104
- const actionAlias = translation.actionAliasFor(action);
86
+ .forEach(action => {
87
+ const actionAlias = translation.actionAliasFor(action)
105
88
  if (!actor[action]) {
106
89
  actor[action] = actor[actionAlias] = function () {
107
- const step = new Step(helper, action);
90
+ const step = new Step(helper, action)
108
91
  if (translation.loaded) {
109
- step.name = actionAlias;
110
- step.actor = translation.I;
92
+ step.name = actionAlias
93
+ step.actor = translation.I
111
94
  }
112
95
  // add methods to promise chain
113
- return recordStep(step, Array.from(arguments));
114
- };
96
+ return recordStep(step, Array.from(arguments))
97
+ }
115
98
  }
116
- });
117
- });
118
-
119
- return actor;
120
- };
121
-
122
- function recordStep(step, args) {
123
- step.status = 'queued';
124
- step.setArguments(args);
125
-
126
- // run async before step hooks
127
- event.emit(event.step.before, step);
128
-
129
- const task = `${step.name}: ${step.humanizeArgs()}`;
130
- let val;
131
-
132
- // run step inside promise
133
- recorder.add(task, () => {
134
- if (!step.startTime) { // step can be retries
135
- event.emit(event.step.started, step);
136
- step.startTime = Date.now();
137
- }
138
- return val = step.run(...args);
139
- }, false, undefined, step.getTimeout());
140
-
141
- event.emit(event.step.after, step);
142
-
143
- recorder.add('step passed', () => {
144
- step.endTime = Date.now();
145
- event.emit(event.step.passed, step, val);
146
- event.emit(event.step.finished, step);
147
- });
148
-
149
- recorder.catchWithoutStop((err) => {
150
- step.status = 'failed';
151
- step.endTime = Date.now();
152
- event.emit(event.step.failed, step);
153
- event.emit(event.step.finished, step);
154
- throw err;
155
- });
156
-
157
- recorder.add('return result', () => val);
158
- // run async after step hooks
159
-
160
- return recorder.promise();
99
+ })
100
+ })
101
+
102
+ // add translated custom steps from actor
103
+ Object.keys(obj).forEach(key => {
104
+ const actionAlias = translation.actionAliasFor(key)
105
+ if (!actor[actionAlias]) {
106
+ actor[actionAlias] = actor[key]
107
+ }
108
+ })
109
+
110
+ container.append({
111
+ support: {
112
+ I: actor,
113
+ },
114
+ })
115
+ })
116
+ // store.actor = actor;
117
+ // add custom steps from actor
118
+ Object.keys(obj).forEach(key => {
119
+ const ms = new MetaStep('I', key)
120
+ ms.setContext(actor)
121
+ actor[key] = ms.run.bind(ms, obj[key])
122
+ })
123
+
124
+ return actor
161
125
  }