codeceptjs 4.0.0-beta.4 → 4.0.0-beta.6.esm-aria
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.
- package/README.md +89 -119
- package/bin/codecept.js +53 -54
- package/docs/webapi/clearCookie.mustache +1 -1
- package/lib/actor.js +70 -102
- package/lib/ai.js +131 -121
- package/lib/assert/empty.js +11 -12
- package/lib/assert/equal.js +16 -21
- package/lib/assert/error.js +2 -2
- package/lib/assert/include.js +11 -15
- package/lib/assert/throws.js +3 -5
- package/lib/assert/truth.js +10 -7
- package/lib/assert.js +18 -18
- package/lib/codecept.js +112 -101
- package/lib/colorUtils.js +48 -50
- package/lib/command/check.js +206 -0
- package/lib/command/configMigrate.js +13 -14
- package/lib/command/definitions.js +24 -36
- package/lib/command/dryRun.js +16 -16
- package/lib/command/generate.js +38 -39
- package/lib/command/gherkin/init.js +36 -38
- package/lib/command/gherkin/snippets.js +76 -74
- package/lib/command/gherkin/steps.js +21 -18
- package/lib/command/info.js +49 -15
- package/lib/command/init.js +41 -37
- package/lib/command/interactive.js +22 -13
- package/lib/command/list.js +11 -10
- package/lib/command/run-multiple/chunk.js +50 -47
- package/lib/command/run-multiple/collection.js +5 -5
- package/lib/command/run-multiple/run.js +3 -3
- package/lib/command/run-multiple.js +27 -47
- package/lib/command/run-rerun.js +6 -7
- package/lib/command/run-workers.js +15 -66
- package/lib/command/run.js +8 -8
- package/lib/command/utils.js +22 -21
- package/lib/command/workers/runTests.js +131 -241
- package/lib/config.js +111 -49
- package/lib/container.js +589 -244
- package/lib/data/context.js +16 -18
- package/lib/data/dataScenarioConfig.js +9 -9
- package/lib/data/dataTableArgument.js +7 -7
- package/lib/data/table.js +6 -12
- package/lib/effects.js +307 -0
- package/lib/els.js +160 -0
- package/lib/event.js +24 -19
- package/lib/globals.js +141 -0
- package/lib/heal.js +89 -81
- package/lib/helper/AI.js +3 -2
- package/lib/helper/ApiDataFactory.js +19 -19
- package/lib/helper/Appium.js +47 -51
- package/lib/helper/FileSystem.js +35 -15
- package/lib/helper/GraphQL.js +1 -1
- package/lib/helper/GraphQLDataFactory.js +4 -4
- package/lib/helper/JSONResponse.js +72 -45
- package/lib/helper/Mochawesome.js +14 -11
- package/lib/helper/Playwright.js +832 -434
- package/lib/helper/Puppeteer.js +393 -292
- package/lib/helper/REST.js +32 -27
- package/lib/helper/WebDriver.js +320 -219
- package/lib/helper/errors/ConnectionRefused.js +6 -6
- package/lib/helper/errors/ElementAssertion.js +11 -16
- package/lib/helper/errors/ElementNotFound.js +5 -9
- package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
- package/lib/helper/extras/Console.js +11 -11
- package/lib/helper/extras/PlaywrightLocator.js +110 -0
- package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
- package/lib/helper/extras/PlaywrightRestartOpts.js +23 -23
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/extras/React.js +29 -30
- package/lib/helper/network/actions.js +33 -48
- package/lib/helper/network/utils.js +76 -83
- package/lib/helper/scripts/blurElement.js +6 -6
- package/lib/helper/scripts/focusElement.js +6 -6
- package/lib/helper/scripts/highlightElement.js +9 -9
- package/lib/helper/scripts/isElementClickable.js +34 -34
- package/lib/helper.js +2 -1
- package/lib/history.js +23 -20
- package/lib/hooks.js +10 -10
- package/lib/html.js +90 -100
- package/lib/index.js +48 -21
- package/lib/listener/config.js +8 -9
- package/lib/listener/emptyRun.js +54 -0
- package/lib/listener/exit.js +10 -12
- package/lib/listener/{retry.js → globalRetry.js} +10 -10
- package/lib/listener/globalTimeout.js +166 -0
- package/lib/listener/helpers.js +43 -24
- package/lib/listener/mocha.js +4 -5
- package/lib/listener/result.js +11 -0
- package/lib/listener/steps.js +26 -23
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +213 -192
- package/lib/mocha/asyncWrapper.js +264 -0
- package/lib/mocha/bdd.js +167 -0
- package/lib/mocha/cli.js +341 -0
- package/lib/mocha/factory.js +160 -0
- package/lib/{interfaces → mocha}/featureConfig.js +33 -13
- package/lib/{interfaces → mocha}/gherkin.js +75 -45
- package/lib/mocha/hooks.js +121 -0
- package/lib/mocha/index.js +21 -0
- package/lib/mocha/inject.js +46 -0
- package/lib/{interfaces → mocha}/scenarioConfig.js +32 -8
- package/lib/mocha/suite.js +89 -0
- package/lib/mocha/test.js +178 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +229 -0
- package/lib/output.js +86 -64
- package/lib/parser.js +44 -44
- package/lib/pause.js +160 -139
- package/lib/plugin/analyze.js +403 -0
- package/lib/plugin/{autoLogin.js → auth.js} +137 -43
- package/lib/plugin/autoDelay.js +19 -15
- package/lib/plugin/coverage.js +22 -27
- package/lib/plugin/customLocator.js +5 -5
- package/lib/plugin/customReporter.js +53 -0
- package/lib/plugin/heal.js +49 -17
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/pauseOnFail.js +4 -3
- package/lib/plugin/retryFailedStep.js +60 -19
- package/lib/plugin/screenshotOnFail.js +80 -83
- package/lib/plugin/stepByStepReport.js +70 -31
- package/lib/plugin/stepTimeout.js +7 -13
- package/lib/plugin/subtitles.js +10 -9
- package/lib/recorder.js +167 -126
- package/lib/rerun.js +94 -50
- package/lib/result.js +161 -0
- package/lib/secret.js +18 -17
- package/lib/session.js +95 -89
- package/lib/step/base.js +239 -0
- package/lib/step/comment.js +10 -0
- package/lib/step/config.js +50 -0
- package/lib/step/func.js +46 -0
- package/lib/step/helper.js +50 -0
- package/lib/step/meta.js +99 -0
- package/lib/step/record.js +74 -0
- package/lib/step/retry.js +11 -0
- package/lib/step/section.js +55 -0
- package/lib/step.js +18 -332
- package/lib/steps.js +54 -0
- package/lib/store.js +37 -5
- package/lib/template/heal.js +2 -11
- package/lib/timeout.js +60 -0
- package/lib/transform.js +8 -8
- package/lib/translation.js +32 -18
- package/lib/utils.js +354 -250
- package/lib/workerStorage.js +16 -16
- package/lib/workers.js +366 -282
- package/package.json +107 -95
- package/translations/de-DE.js +5 -4
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +23 -9
- package/translations/it-IT.js +5 -4
- package/translations/ja-JP.js +5 -4
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +5 -4
- package/translations/pt-BR.js +5 -4
- package/translations/ru-RU.js +5 -4
- package/translations/utils.js +18 -0
- package/translations/zh-CN.js +5 -4
- package/translations/zh-TW.js +5 -4
- package/typings/index.d.ts +177 -186
- package/typings/promiseBasedTypes.d.ts +3573 -5941
- package/typings/types.d.ts +4042 -6370
- package/lib/cli.js +0 -256
- package/lib/helper/ExpectHelper.js +0 -391
- package/lib/helper/Nightmare.js +0 -1504
- package/lib/helper/Protractor.js +0 -1863
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/helper/TestCafe.js +0 -1414
- package/lib/helper/clientscripts/nightmare.js +0 -213
- package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -43
- package/lib/helper/testcafe/testControllerHolder.js +0 -42
- package/lib/helper/testcafe/testcafe-utils.js +0 -62
- package/lib/interfaces/bdd.js +0 -81
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -113
- package/lib/plugin/allure.js +0 -15
- package/lib/plugin/commentStep.js +0 -136
- package/lib/plugin/debugErrors.js +0 -67
- package/lib/plugin/eachElement.js +0 -127
- package/lib/plugin/fakerTransform.js +0 -49
- package/lib/plugin/retryTo.js +0 -127
- package/lib/plugin/selenoid.js +0 -384
- package/lib/plugin/standardActingHelpers.js +0 -3
- package/lib/plugin/tryTo.js +0 -115
- package/lib/plugin/wdio.js +0 -249
- package/lib/scenario.js +0 -224
- package/lib/ui.js +0 -236
- package/lib/within.js +0 -70
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
const event = require('../event')
|
|
2
|
-
const recorder = require('../recorder')
|
|
3
|
-
const { MetaStep } = require('../step')
|
|
4
|
-
|
|
5
|
-
let currentCommentStep
|
|
6
|
-
|
|
7
|
-
const defaultGlobalName = '__'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Add descriptive nested steps for your tests:
|
|
11
|
-
*
|
|
12
|
-
* ```js
|
|
13
|
-
* Scenario('project update test', async (I) => {
|
|
14
|
-
* __`Given`;
|
|
15
|
-
* const projectId = await I.have('project');
|
|
16
|
-
*
|
|
17
|
-
* __`When`;
|
|
18
|
-
* projectPage.update(projectId, { title: 'new title' });
|
|
19
|
-
*
|
|
20
|
-
* __`Then`;
|
|
21
|
-
* projectPage.open(projectId);
|
|
22
|
-
* I.see('new title', 'h1');
|
|
23
|
-
* })
|
|
24
|
-
* ```
|
|
25
|
-
* Steps prefixed with `__` will be printed as nested steps in `--steps` output:
|
|
26
|
-
*
|
|
27
|
-
* ```
|
|
28
|
-
* Given
|
|
29
|
-
* I have "project"
|
|
30
|
-
* When
|
|
31
|
-
* projectPage update
|
|
32
|
-
* Then
|
|
33
|
-
* projectPage open
|
|
34
|
-
* I see "new title", "h1"
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* Also those steps will be exported to allure reports.
|
|
38
|
-
*
|
|
39
|
-
* This plugin can be used
|
|
40
|
-
*
|
|
41
|
-
* ### Config
|
|
42
|
-
*
|
|
43
|
-
* * `enabled` - (default: false) enable a plugin
|
|
44
|
-
* * `registerGlobal` - (default: false) register `__` template literal function globally. You can override function global name by providing a name as a value.
|
|
45
|
-
*
|
|
46
|
-
* ### Examples
|
|
47
|
-
*
|
|
48
|
-
* Registering `__` globally:
|
|
49
|
-
*
|
|
50
|
-
* ```js
|
|
51
|
-
* plugins: {
|
|
52
|
-
* commentStep: {
|
|
53
|
-
* enabled: true,
|
|
54
|
-
* registerGlobal: true
|
|
55
|
-
* }
|
|
56
|
-
* }
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* Registering `Step` globally:
|
|
60
|
-
* ```js
|
|
61
|
-
* plugins: {
|
|
62
|
-
* commentStep: {
|
|
63
|
-
* enabled: true,
|
|
64
|
-
* registerGlobal: 'Step'
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* Using only local function names:
|
|
70
|
-
* ```js
|
|
71
|
-
* plugins: {
|
|
72
|
-
* commentStep: {
|
|
73
|
-
* enabled: true
|
|
74
|
-
* }
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
* Then inside a test import a comment function from a plugin.
|
|
78
|
-
* For instance, you can prepare Given/When/Then functions to use them inside tests:
|
|
79
|
-
*
|
|
80
|
-
* ```js
|
|
81
|
-
* // inside a test
|
|
82
|
-
* const step = codeceptjs.container.plugins('commentStep');
|
|
83
|
-
*
|
|
84
|
-
* const Given = () => step`Given`;
|
|
85
|
-
* const When = () => step`When`;
|
|
86
|
-
* const Then = () => step`Then`;
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* Scenario('project update test', async (I) => {
|
|
90
|
-
* Given();
|
|
91
|
-
* const projectId = await I.have('project');
|
|
92
|
-
*
|
|
93
|
-
* When();
|
|
94
|
-
* projectPage.update(projectId, { title: 'new title' });
|
|
95
|
-
*
|
|
96
|
-
* Then();
|
|
97
|
-
* projectPage.open(projectId);
|
|
98
|
-
* I.see('new title', 'h1');
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
module.exports = function (config) {
|
|
103
|
-
event.dispatcher.on(event.test.started, () => {
|
|
104
|
-
currentCommentStep = null
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
event.dispatcher.on(event.step.started, (step) => {
|
|
108
|
-
if (currentCommentStep) {
|
|
109
|
-
const metaStep = getRootMetaStep(step)
|
|
110
|
-
|
|
111
|
-
if (metaStep !== currentCommentStep) {
|
|
112
|
-
metaStep.metaStep = currentCommentStep
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
if (config.registerGlobal) {
|
|
118
|
-
if (config.registerGlobal === true) {
|
|
119
|
-
config.registerGlobal = defaultGlobalName
|
|
120
|
-
}
|
|
121
|
-
global[config.registerGlobal] = setCommentString
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return setCommentString
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function getRootMetaStep(step) {
|
|
128
|
-
if (step.metaStep) return getRootMetaStep(step.metaStep)
|
|
129
|
-
return step
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function setCommentString(string) {
|
|
133
|
-
recorder.add('set comment metastep', () => {
|
|
134
|
-
currentCommentStep = new MetaStep(String.raw(string), '')
|
|
135
|
-
})
|
|
136
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const Container = require('../container')
|
|
2
|
-
const recorder = require('../recorder')
|
|
3
|
-
const event = require('../event')
|
|
4
|
-
const supportedHelpers = require('./standardActingHelpers')
|
|
5
|
-
const { scanForErrorMessages } = require('../html')
|
|
6
|
-
const { output } = require('..')
|
|
7
|
-
|
|
8
|
-
const defaultConfig = {
|
|
9
|
-
errorClasses: ['error', 'warning', 'alert', 'danger'],
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Prints errors found in HTML code after each failed test.
|
|
14
|
-
*
|
|
15
|
-
* It scans HTML and searches for elements with error classes.
|
|
16
|
-
* If an element found prints a text from it to console and adds as artifact to the test.
|
|
17
|
-
*
|
|
18
|
-
* Enable this plugin in config:
|
|
19
|
-
*
|
|
20
|
-
* ```js
|
|
21
|
-
* plugins: {
|
|
22
|
-
* debugErrors: {
|
|
23
|
-
* enabled: true,
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* Additional config options:
|
|
28
|
-
*
|
|
29
|
-
* * `errorClasses` - list of classes to search for errors (default: `['error', 'warning', 'alert', 'danger']`)
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
module.exports = function (config = {}) {
|
|
33
|
-
const helpers = Container.helpers()
|
|
34
|
-
let helper
|
|
35
|
-
|
|
36
|
-
config = Object.assign(defaultConfig, config)
|
|
37
|
-
|
|
38
|
-
for (const helperName of supportedHelpers) {
|
|
39
|
-
if (Object.keys(helpers).indexOf(helperName) > -1) {
|
|
40
|
-
helper = helpers[helperName]
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!helper) return // no helpers for screenshot
|
|
45
|
-
|
|
46
|
-
event.dispatcher.on(event.test.failed, (test) => {
|
|
47
|
-
recorder.add('HTML snapshot failed test', async () => {
|
|
48
|
-
try {
|
|
49
|
-
const currentOutputLevel = output.level()
|
|
50
|
-
output.level(0)
|
|
51
|
-
const html = await helper.grabHTMLFrom('body')
|
|
52
|
-
output.level(currentOutputLevel)
|
|
53
|
-
|
|
54
|
-
if (!html) return
|
|
55
|
-
|
|
56
|
-
const errors = scanForErrorMessages(html, config.errorClasses)
|
|
57
|
-
if (errors.length) {
|
|
58
|
-
output.debug('Detected errors in HTML code')
|
|
59
|
-
errors.forEach((error) => output.debug(error))
|
|
60
|
-
test.artifacts.errors = errors
|
|
61
|
-
}
|
|
62
|
-
} catch (err) {
|
|
63
|
-
// not really needed
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const output = require('../output')
|
|
2
|
-
const store = require('../store')
|
|
3
|
-
const recorder = require('../recorder')
|
|
4
|
-
const container = require('../container')
|
|
5
|
-
const event = require('../event')
|
|
6
|
-
const Step = require('../step')
|
|
7
|
-
const { isAsyncFunction } = require('../utils')
|
|
8
|
-
|
|
9
|
-
const defaultConfig = {
|
|
10
|
-
registerGlobal: true,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Provides `eachElement` global function to iterate over found elements to perform actions on them.
|
|
15
|
-
*
|
|
16
|
-
* `eachElement` takes following args:
|
|
17
|
-
* * `purpose` - the goal of an action. A comment text that will be displayed in output.
|
|
18
|
-
* * `locator` - a CSS/XPath locator to match elements
|
|
19
|
-
* * `fn(element, index)` - **asynchronous** function which will be executed for each matched element.
|
|
20
|
-
*
|
|
21
|
-
* Example of usage:
|
|
22
|
-
*
|
|
23
|
-
* ```js
|
|
24
|
-
* // this example works with Playwright and Puppeteer helper
|
|
25
|
-
* await eachElement('click all checkboxes', 'form input[type=checkbox]', async (el) => {
|
|
26
|
-
* await el.click();
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
* Click odd elements:
|
|
30
|
-
*
|
|
31
|
-
* ```js
|
|
32
|
-
* // this example works with Playwright and Puppeteer helper
|
|
33
|
-
* await eachElement('click odd buttons', '.button-select', async (el, index) => {
|
|
34
|
-
* if (index % 2) await el.click();
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* Check all elements for visibility:
|
|
39
|
-
*
|
|
40
|
-
* ```js
|
|
41
|
-
* // this example works with Playwright and Puppeteer helper
|
|
42
|
-
* const assert = require('assert');
|
|
43
|
-
* await eachElement('check all items are visible', '.item', async (el) => {
|
|
44
|
-
* assert(await el.isVisible());
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
47
|
-
* This method works with WebDriver, Playwright, Puppeteer, Appium helpers.
|
|
48
|
-
*
|
|
49
|
-
* Function parameter `el` represents a matched element.
|
|
50
|
-
* Depending on a helper API of `el` can be different. Refer to API of corresponding browser testing engine for a complete API list:
|
|
51
|
-
*
|
|
52
|
-
* * [Playwright ElementHandle](https://playwright.dev/docs/api/class-elementhandle)
|
|
53
|
-
* * [Puppeteer](https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle)
|
|
54
|
-
* * [webdriverio element](https://webdriver.io/docs/api)
|
|
55
|
-
*
|
|
56
|
-
* #### Configuration
|
|
57
|
-
*
|
|
58
|
-
* * `registerGlobal` - to register `eachElement` function globally, true by default
|
|
59
|
-
*
|
|
60
|
-
* If `registerGlobal` is false you can use eachElement from the plugin:
|
|
61
|
-
*
|
|
62
|
-
* ```js
|
|
63
|
-
* const eachElement = codeceptjs.container.plugins('eachElement');
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param {string} purpose
|
|
67
|
-
* @param {CodeceptJS.LocatorOrString} locator
|
|
68
|
-
* @param {Function} fn
|
|
69
|
-
* @return {Promise<*> | undefined}
|
|
70
|
-
*/
|
|
71
|
-
function eachElement(purpose, locator, fn) {
|
|
72
|
-
if (store.dryRun) return
|
|
73
|
-
const helpers = Object.values(container.helpers())
|
|
74
|
-
|
|
75
|
-
const helper = helpers.filter((h) => !!h._locate)[0]
|
|
76
|
-
|
|
77
|
-
if (!helper) {
|
|
78
|
-
throw new Error('No helper enabled with _locate method with returns a list of elements.')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (!isAsyncFunction(fn)) {
|
|
82
|
-
throw new Error('Async function should be passed into each element')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const step = new Step(helper, `${purpose || 'each element'} within "${locator}"`)
|
|
86
|
-
step.helperMethod = '_locate'
|
|
87
|
-
// eachElement('select all users', 'locator', async (el) => {
|
|
88
|
-
event.dispatcher.emit(event.step.before, step)
|
|
89
|
-
|
|
90
|
-
return recorder.add('register each element wrapper', async () => {
|
|
91
|
-
event.emit(event.step.started, step)
|
|
92
|
-
const els = await helper._locate(locator)
|
|
93
|
-
output.debug(`Found ${els.length} elements for each elements to iterate`)
|
|
94
|
-
|
|
95
|
-
const errs = []
|
|
96
|
-
let i = 0
|
|
97
|
-
for (const el of els) {
|
|
98
|
-
try {
|
|
99
|
-
await fn(el, i)
|
|
100
|
-
} catch (err) {
|
|
101
|
-
output.error(`eachElement: failed operation on element #${i} ${el}`)
|
|
102
|
-
errs.push(err)
|
|
103
|
-
}
|
|
104
|
-
i++
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (errs.length) {
|
|
108
|
-
event.dispatcher.emit(event.step.after, step)
|
|
109
|
-
event.emit(event.step.failed, step, errs[0])
|
|
110
|
-
event.emit(event.step.finished, step)
|
|
111
|
-
throw errs[0]
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
event.dispatcher.emit(event.step.after, step)
|
|
115
|
-
event.emit(event.step.passed, step, null)
|
|
116
|
-
event.emit(event.step.finished, step)
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
module.exports = function (config) {
|
|
121
|
-
config = Object.assign(defaultConfig, config)
|
|
122
|
-
|
|
123
|
-
if (config.registerGlobal) {
|
|
124
|
-
global.eachElement = eachElement
|
|
125
|
-
}
|
|
126
|
-
return eachElement
|
|
127
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const { faker } = require('@faker-js/faker')
|
|
2
|
-
const transform = require('../transform')
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use the `@faker-js/faker` package to generate fake data inside examples on your gherkin tests
|
|
6
|
-
*
|
|
7
|
-
* #### Usage
|
|
8
|
-
*
|
|
9
|
-
* To start please install `@faker-js/faker` package
|
|
10
|
-
*
|
|
11
|
-
* ```
|
|
12
|
-
* npm install -D @faker-js/faker
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* ```
|
|
16
|
-
* yarn add -D @faker-js/faker
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Add this plugin to config file:
|
|
20
|
-
*
|
|
21
|
-
* ```js
|
|
22
|
-
* plugins: {
|
|
23
|
-
* fakerTransform: {
|
|
24
|
-
* enabled: true
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* Add the faker API using a mustache string format inside examples tables in your gherkin scenario outline
|
|
30
|
-
*
|
|
31
|
-
* ```feature
|
|
32
|
-
* Scenario Outline: ...
|
|
33
|
-
* Given ...
|
|
34
|
-
* When ...
|
|
35
|
-
* Then ...
|
|
36
|
-
* Examples:
|
|
37
|
-
* | productName | customer | email | anythingMore |
|
|
38
|
-
* | {{commerce.product}} | Dr. {{name.findName}} | {{internet.email}} | staticData |
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
module.exports = function (config) {
|
|
43
|
-
transform.addTransformerBeforeAll('gherkin.examples', (value) => {
|
|
44
|
-
if (typeof value === 'string' && value.length > 0) {
|
|
45
|
-
return faker.helpers.fake(value)
|
|
46
|
-
}
|
|
47
|
-
return value
|
|
48
|
-
})
|
|
49
|
-
}
|
package/lib/plugin/retryTo.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const recorder = require('../recorder')
|
|
2
|
-
const { debug } = require('../output')
|
|
3
|
-
|
|
4
|
-
const defaultConfig = {
|
|
5
|
-
registerGlobal: true,
|
|
6
|
-
pollInterval: 200,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Adds global `retryTo` which retries steps a few times before failing.
|
|
13
|
-
*
|
|
14
|
-
* Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
|
|
15
|
-
*
|
|
16
|
-
* ```js
|
|
17
|
-
* plugins: {
|
|
18
|
-
* retryTo: {
|
|
19
|
-
* enabled: true
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* Use it in your tests:
|
|
25
|
-
*
|
|
26
|
-
* ```js
|
|
27
|
-
* // retry these steps 5 times before failing
|
|
28
|
-
* await retryTo((tryNum) => {
|
|
29
|
-
* I.switchTo('#editor frame');
|
|
30
|
-
* I.click('Open');
|
|
31
|
-
* I.see('Opened')
|
|
32
|
-
* }, 5);
|
|
33
|
-
* ```
|
|
34
|
-
* Set polling interval as 3rd argument (200ms by default):
|
|
35
|
-
*
|
|
36
|
-
* ```js
|
|
37
|
-
* // retry these steps 5 times before failing
|
|
38
|
-
* await retryTo((tryNum) => {
|
|
39
|
-
* I.switchTo('#editor frame');
|
|
40
|
-
* I.click('Open');
|
|
41
|
-
* I.see('Opened')
|
|
42
|
-
* }, 5, 100);
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* Default polling interval can be changed in a config:
|
|
46
|
-
*
|
|
47
|
-
* ```js
|
|
48
|
-
* plugins: {
|
|
49
|
-
* retryTo: {
|
|
50
|
-
* enabled: true,
|
|
51
|
-
* pollInterval: 500,
|
|
52
|
-
* }
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* Disables retryFailedStep plugin for steps inside a block;
|
|
57
|
-
*
|
|
58
|
-
* Use this plugin if:
|
|
59
|
-
*
|
|
60
|
-
* * you need repeat a set of actions in flaky tests
|
|
61
|
-
* * iframe was not rendered and you need to retry switching to it
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* #### Configuration
|
|
65
|
-
*
|
|
66
|
-
* * `pollInterval` - default interval between retries in ms. 200 by default.
|
|
67
|
-
* * `registerGlobal` - to register `retryTo` function globally, true by default
|
|
68
|
-
*
|
|
69
|
-
* If `registerGlobal` is false you can use retryTo from the plugin:
|
|
70
|
-
*
|
|
71
|
-
* ```js
|
|
72
|
-
* const retryTo = codeceptjs.container.plugins('retryTo');
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
*/
|
|
76
|
-
module.exports = function (config) {
|
|
77
|
-
config = Object.assign(defaultConfig, config)
|
|
78
|
-
function retryTo(callback, maxTries, pollInterval = config.pollInterval) {
|
|
79
|
-
return new Promise((done, reject) => {
|
|
80
|
-
let tries = 1
|
|
81
|
-
|
|
82
|
-
function handleRetryException(err) {
|
|
83
|
-
recorder.throw(err)
|
|
84
|
-
reject(err)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const tryBlock = async () => {
|
|
88
|
-
tries++
|
|
89
|
-
recorder.session.start(`retryTo ${tries}`)
|
|
90
|
-
try {
|
|
91
|
-
await callback(tries)
|
|
92
|
-
} catch (err) {
|
|
93
|
-
handleRetryException(err)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Call done if no errors
|
|
97
|
-
recorder.add(() => {
|
|
98
|
-
recorder.session.restore(`retryTo ${tries}`)
|
|
99
|
-
done(null)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
// Catch errors and retry
|
|
103
|
-
recorder.session.catch((err) => {
|
|
104
|
-
recorder.session.restore(`retryTo ${tries}`)
|
|
105
|
-
if (tries <= maxTries) {
|
|
106
|
-
debug(`Error ${err}... Retrying`)
|
|
107
|
-
recorder.add(`retryTo ${tries}`, () => setTimeout(tryBlock, pollInterval))
|
|
108
|
-
} else {
|
|
109
|
-
// if maxTries reached
|
|
110
|
-
handleRetryException(err)
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
recorder.add('retryTo', tryBlock).catch((err) => {
|
|
116
|
-
console.error('An error occurred:', err)
|
|
117
|
-
done(null)
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (config.registerGlobal) {
|
|
123
|
-
global.retryTo = retryTo
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return retryTo
|
|
127
|
-
}
|