codeceptjs 4.0.0-beta.2 → 4.0.0-beta.20
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 +133 -120
- package/bin/codecept.js +107 -96
- package/bin/test-server.js +64 -0
- package/docs/webapi/clearCookie.mustache +1 -1
- package/docs/webapi/click.mustache +5 -1
- package/lib/actor.js +71 -103
- package/lib/ai.js +159 -188
- package/lib/assert/empty.js +22 -24
- package/lib/assert/equal.js +30 -37
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +43 -48
- package/lib/assert/throws.js +11 -11
- package/lib/assert/truth.js +22 -22
- package/lib/assert.js +20 -18
- package/lib/codecept.js +262 -162
- package/lib/colorUtils.js +50 -52
- package/lib/command/check.js +206 -0
- package/lib/command/configMigrate.js +56 -51
- package/lib/command/definitions.js +96 -109
- package/lib/command/dryRun.js +77 -79
- package/lib/command/generate.js +234 -194
- package/lib/command/gherkin/init.js +42 -33
- package/lib/command/gherkin/snippets.js +76 -74
- package/lib/command/gherkin/steps.js +20 -17
- package/lib/command/info.js +74 -38
- package/lib/command/init.js +301 -290
- package/lib/command/interactive.js +41 -32
- package/lib/command/list.js +28 -27
- package/lib/command/run-multiple/chunk.js +51 -48
- package/lib/command/run-multiple/collection.js +5 -5
- package/lib/command/run-multiple/run.js +5 -1
- package/lib/command/run-multiple.js +97 -97
- package/lib/command/run-rerun.js +19 -25
- package/lib/command/run-workers.js +68 -92
- package/lib/command/run.js +39 -27
- package/lib/command/utils.js +80 -64
- package/lib/command/workers/runTests.js +388 -226
- package/lib/config.js +109 -50
- package/lib/container.js +641 -261
- package/lib/data/context.js +60 -61
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +32 -32
- package/lib/data/table.js +22 -22
- package/lib/effects.js +307 -0
- package/lib/element/WebElement.js +327 -0
- package/lib/els.js +160 -0
- package/lib/event.js +173 -163
- package/lib/globals.js +141 -0
- package/lib/heal.js +89 -85
- package/lib/helper/AI.js +131 -41
- package/lib/helper/ApiDataFactory.js +107 -75
- package/lib/helper/Appium.js +542 -404
- package/lib/helper/FileSystem.js +100 -79
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +52 -52
- package/lib/helper/JSONResponse.js +126 -88
- package/lib/helper/Mochawesome.js +54 -29
- package/lib/helper/Playwright.js +2547 -1316
- package/lib/helper/Puppeteer.js +1578 -1181
- package/lib/helper/REST.js +209 -68
- package/lib/helper/WebDriver.js +1482 -1342
- 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/PlaywrightReactVueLocator.js +17 -8
- package/lib/helper/extras/PlaywrightRestartOpts.js +25 -11
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/extras/React.js +27 -28
- package/lib/helper/network/actions.js +36 -42
- package/lib/helper/network/utils.js +78 -84
- package/lib/helper/scripts/blurElement.js +5 -5
- package/lib/helper/scripts/focusElement.js +5 -5
- package/lib/helper/scripts/highlightElement.js +8 -8
- package/lib/helper/scripts/isElementClickable.js +34 -34
- package/lib/helper.js +2 -3
- package/lib/history.js +23 -19
- package/lib/hooks.js +8 -8
- package/lib/html.js +94 -104
- package/lib/index.js +38 -27
- package/lib/listener/config.js +30 -23
- package/lib/listener/emptyRun.js +54 -0
- package/lib/listener/enhancedGlobalRetry.js +110 -0
- package/lib/listener/exit.js +16 -18
- package/lib/listener/globalRetry.js +70 -0
- package/lib/listener/globalTimeout.js +181 -0
- package/lib/listener/helpers.js +76 -51
- package/lib/listener/mocha.js +10 -11
- package/lib/listener/result.js +11 -0
- package/lib/listener/retryEnhancer.js +85 -0
- package/lib/listener/steps.js +71 -59
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +214 -197
- package/lib/mocha/asyncWrapper.js +274 -0
- package/lib/mocha/bdd.js +167 -0
- package/lib/mocha/cli.js +341 -0
- package/lib/mocha/factory.js +163 -0
- package/lib/mocha/featureConfig.js +89 -0
- package/lib/mocha/gherkin.js +231 -0
- 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 +58 -34
- package/lib/mocha/suite.js +89 -0
- package/lib/mocha/test.js +184 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +242 -0
- package/lib/output.js +141 -71
- package/lib/parser.js +47 -44
- package/lib/pause.js +173 -145
- package/lib/plugin/analyze.js +403 -0
- package/lib/plugin/{autoLogin.js → auth.js} +178 -79
- package/lib/plugin/autoDelay.js +36 -40
- package/lib/plugin/coverage.js +131 -78
- package/lib/plugin/customLocator.js +22 -21
- package/lib/plugin/customReporter.js +53 -0
- package/lib/plugin/enhancedRetryFailedStep.js +99 -0
- package/lib/plugin/heal.js +101 -110
- package/lib/plugin/htmlReporter.js +3648 -0
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/pauseOnFail.js +12 -11
- package/lib/plugin/retryFailedStep.js +82 -47
- package/lib/plugin/screenshotOnFail.js +111 -92
- package/lib/plugin/stepByStepReport.js +159 -101
- package/lib/plugin/stepTimeout.js +20 -25
- package/lib/plugin/subtitles.js +38 -38
- package/lib/recorder.js +193 -130
- package/lib/rerun.js +94 -49
- package/lib/result.js +238 -0
- package/lib/retryCoordinator.js +207 -0
- package/lib/secret.js +20 -18
- 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 -329
- package/lib/steps.js +54 -0
- package/lib/store.js +38 -7
- package/lib/template/heal.js +3 -12
- package/lib/template/prompts/generatePageObject.js +31 -0
- package/lib/template/prompts/healStep.js +13 -0
- package/lib/template/prompts/writeStep.js +9 -0
- package/lib/test-server.js +334 -0
- package/lib/timeout.js +60 -0
- package/lib/transform.js +8 -8
- package/lib/translation.js +34 -21
- package/lib/utils/loaderCheck.js +124 -0
- package/lib/utils/mask_data.js +47 -0
- package/lib/utils/typescript.js +237 -0
- package/lib/utils.js +411 -228
- package/lib/workerStorage.js +37 -34
- package/lib/workers.js +532 -296
- package/package.json +124 -95
- package/translations/de-DE.js +5 -3
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +22 -12
- package/translations/it-IT.js +4 -3
- package/translations/ja-JP.js +4 -3
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +4 -3
- package/translations/pt-BR.js +4 -3
- package/translations/ru-RU.js +4 -3
- package/translations/utils.js +10 -0
- package/translations/zh-CN.js +4 -3
- package/translations/zh-TW.js +4 -3
- package/typings/index.d.ts +546 -185
- package/typings/promiseBasedTypes.d.ts +150 -875
- package/typings/types.d.ts +547 -992
- package/lib/cli.js +0 -249
- package/lib/dirname.js +0 -5
- package/lib/helper/Expect.js +0 -425
- package/lib/helper/ExpectHelper.js +0 -399
- package/lib/helper/MockServer.js +0 -223
- package/lib/helper/Nightmare.js +0 -1411
- package/lib/helper/Protractor.js +0 -1835
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/helper/TestCafe.js +0 -1410
- package/lib/helper/clientscripts/nightmare.js +0 -213
- package/lib/helper/testcafe/testControllerHolder.js +0 -42
- package/lib/helper/testcafe/testcafe-utils.js +0 -63
- package/lib/interfaces/bdd.js +0 -98
- package/lib/interfaces/featureConfig.js +0 -69
- package/lib/interfaces/gherkin.js +0 -195
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/retry.js +0 -68
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -110
- 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 -121
- package/lib/plugin/selenoid.js +0 -371
- package/lib/plugin/standardActingHelpers.js +0 -9
- package/lib/plugin/tryTo.js +0 -105
- package/lib/plugin/wdio.js +0 -246
- package/lib/scenario.js +0 -222
- package/lib/ui.js +0 -238
- package/lib/within.js +0 -70
package/lib/plugin/heal.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const heal =
|
|
12
|
-
|
|
1
|
+
import debugFactory from 'debug'
|
|
2
|
+
const debug = debugFactory('codeceptjs:heal')
|
|
3
|
+
import colors from 'chalk'
|
|
4
|
+
import recorder from '../recorder.js'
|
|
5
|
+
|
|
6
|
+
import event from '../event.js'
|
|
7
|
+
|
|
8
|
+
import output from '../output.js'
|
|
9
|
+
|
|
10
|
+
import healModule from '../heal.js'
|
|
11
|
+
const heal = healModule.default || healModule
|
|
12
|
+
import store from '../store.js'
|
|
13
|
+
|
|
13
14
|
|
|
14
15
|
const defaultConfig = {
|
|
15
16
|
healLimit: 2,
|
|
16
|
-
}
|
|
17
|
+
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Self-healing tests with AI.
|
|
@@ -33,130 +34,120 @@ const defaultConfig = {
|
|
|
33
34
|
* * `healLimit` - how many steps can be healed in a single test (default: 2)
|
|
34
35
|
*
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
37
|
export default function (config = {}) {
|
|
38
|
-
if (store.
|
|
38
|
+
if (store.debugMode && !process.env.DEBUG) {
|
|
39
39
|
event.dispatcher.on(event.test.failed, () => {
|
|
40
|
-
output.
|
|
41
|
-
})
|
|
42
|
-
return
|
|
40
|
+
output.plugin('heal', 'Healing is disabled in --debug mode, use DEBUG="codeceptjs:heal" to enable it in debug mode')
|
|
41
|
+
})
|
|
42
|
+
return
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
let currentTest = null
|
|
46
|
-
let currentStep = null
|
|
47
|
-
let healedSteps = 0
|
|
48
|
-
let caughtError
|
|
49
|
-
let healTries = 0
|
|
50
|
-
let isHealing = false
|
|
45
|
+
let currentTest = null
|
|
46
|
+
let currentStep = null
|
|
47
|
+
let healedSteps = 0
|
|
48
|
+
let caughtError
|
|
49
|
+
let healTries = 0
|
|
50
|
+
let isHealing = false
|
|
51
51
|
|
|
52
|
-
config = Object.assign(defaultConfig, config)
|
|
52
|
+
config = Object.assign(defaultConfig, config)
|
|
53
53
|
|
|
54
|
-
event.dispatcher.on(event.test.before,
|
|
55
|
-
currentTest = test
|
|
56
|
-
healedSteps = 0
|
|
57
|
-
caughtError = null
|
|
58
|
-
})
|
|
54
|
+
event.dispatcher.on(event.test.before, test => {
|
|
55
|
+
currentTest = test
|
|
56
|
+
healedSteps = 0
|
|
57
|
+
caughtError = null
|
|
58
|
+
})
|
|
59
59
|
|
|
60
|
-
event.dispatcher.on(event.step.started, step => currentStep = step)
|
|
60
|
+
event.dispatcher.on(event.step.started, step => (currentStep = step))
|
|
61
61
|
|
|
62
|
-
event.dispatcher.on(event.step.after,
|
|
63
|
-
if (isHealing) return
|
|
64
|
-
if (
|
|
65
|
-
if (healTries >= config.healLimit) return; // out of limit
|
|
62
|
+
event.dispatcher.on(event.step.after, step => {
|
|
63
|
+
if (isHealing) return
|
|
64
|
+
if (healTries >= config.healLimit) return // out of limit
|
|
66
65
|
|
|
67
|
-
if (!heal.hasCorrespondingRecipes(step)) return
|
|
66
|
+
if (!heal.hasCorrespondingRecipes(step)) return
|
|
68
67
|
|
|
69
|
-
recorder.catchWithoutStop(async
|
|
70
|
-
isHealing = true
|
|
71
|
-
if (caughtError === err) throw err
|
|
72
|
-
caughtError = err
|
|
68
|
+
recorder.catchWithoutStop(async err => {
|
|
69
|
+
isHealing = true
|
|
70
|
+
if (caughtError === err) throw err // avoid double handling
|
|
71
|
+
caughtError = err
|
|
73
72
|
|
|
74
|
-
const test = currentTest
|
|
73
|
+
const test = currentTest
|
|
75
74
|
|
|
76
|
-
recorder.session.start('heal')
|
|
75
|
+
recorder.session.start('heal')
|
|
77
76
|
|
|
78
|
-
debug('Self-healing started', step.toCode())
|
|
77
|
+
debug('Self-healing started', step.toCode())
|
|
79
78
|
|
|
80
|
-
await heal.healStep(step, err, { test })
|
|
79
|
+
await heal.healStep(step, err, { test })
|
|
81
80
|
|
|
82
|
-
healTries
|
|
81
|
+
healTries++
|
|
83
82
|
|
|
84
83
|
recorder.add('close healing session', () => {
|
|
85
|
-
recorder.reset()
|
|
86
|
-
recorder.session.restore('heal')
|
|
87
|
-
recorder.ignoreErr(err)
|
|
88
|
-
})
|
|
89
|
-
await recorder.promise()
|
|
84
|
+
recorder.reset()
|
|
85
|
+
recorder.session.restore('heal')
|
|
86
|
+
recorder.ignoreErr(err)
|
|
87
|
+
})
|
|
88
|
+
await recorder.promise()
|
|
90
89
|
|
|
91
|
-
isHealing = false
|
|
92
|
-
})
|
|
93
|
-
})
|
|
90
|
+
isHealing = false
|
|
91
|
+
})
|
|
92
|
+
})
|
|
94
93
|
|
|
95
94
|
event.dispatcher.on(event.all.result, () => {
|
|
96
|
-
if (!heal.fixes?.length) return
|
|
95
|
+
if (!heal.fixes?.length) return
|
|
97
96
|
|
|
98
|
-
const { print } = output
|
|
97
|
+
const { print } = output
|
|
99
98
|
|
|
100
|
-
print('')
|
|
101
|
-
print('===================')
|
|
102
|
-
print(colors.bold.green('Self-Healing Report:'))
|
|
99
|
+
print('')
|
|
100
|
+
print('===================')
|
|
101
|
+
print(colors.bold.green('Self-Healing Report:'))
|
|
103
102
|
|
|
104
|
-
print(`${colors.bold(heal.fixes.length)} ${heal.fixes.length === 1 ? 'step was' : 'steps were'} healed`)
|
|
103
|
+
print(`${colors.bold(heal.fixes.length)} ${heal.fixes.length === 1 ? 'step was' : 'steps were'} healed`)
|
|
105
104
|
|
|
106
|
-
const suggestions = heal.fixes.filter(fix => fix.recipe && heal.recipes[fix.recipe].suggest)
|
|
105
|
+
const suggestions = heal.fixes.filter(fix => fix.recipe && heal.recipes[fix.recipe].suggest)
|
|
107
106
|
|
|
108
|
-
if (!suggestions.length) return
|
|
107
|
+
if (!suggestions.length) return
|
|
109
108
|
|
|
110
|
-
let i = 1
|
|
111
|
-
print('')
|
|
112
|
-
print('Suggested changes:')
|
|
113
|
-
print('')
|
|
109
|
+
let i = 1
|
|
110
|
+
print('')
|
|
111
|
+
print('Suggested changes:')
|
|
112
|
+
print('')
|
|
114
113
|
|
|
115
114
|
for (const suggestion of suggestions) {
|
|
116
|
-
print(`${i}. To fix ${colors.bold.magenta(suggestion.test?.title)}`)
|
|
117
|
-
print(' Replace the failed code:', colors.gray(`(suggested by ${colors.bold(suggestion.recipe)})`))
|
|
118
|
-
print(colors.red(`- ${suggestion.step.toCode()}`))
|
|
119
|
-
print(colors.green(`+ ${suggestion.snippet}`))
|
|
120
|
-
print(suggestion.step.line())
|
|
121
|
-
print('')
|
|
122
|
-
i
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
async function tryToHeal(failedStep, err) {
|
|
127
|
-
output.output.debug(`Running OpenAI to heal ${failedStep.toCode()} step`);
|
|
128
|
-
|
|
129
|
-
const codeSnippets = await AiAssistant.healFailedStep(failedStep, err, currentTest);
|
|
130
|
-
|
|
131
|
-
output.output.debug(`Received ${codeSnippets.length} suggestions from OpenAI`);
|
|
132
|
-
const I = Container.support('I'); // eslint-disable-line
|
|
133
|
-
|
|
134
|
-
for (const codeSnippet of codeSnippets) {
|
|
135
|
-
try {
|
|
136
|
-
debug('Executing', codeSnippet);
|
|
137
|
-
recorder.catch((e) => {
|
|
138
|
-
console.log(e);
|
|
139
|
-
});
|
|
140
|
-
await eval(codeSnippet); // eslint-disable-line
|
|
141
|
-
|
|
142
|
-
let healSuggestions = [];
|
|
143
|
-
healSuggestions.push({
|
|
144
|
-
test: currentTest,
|
|
145
|
-
step: failedStep,
|
|
146
|
-
snippet: codeSnippet,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
recorder.add('healed', () => output.print(colors.bold.green(' Code healed successfully')));
|
|
150
|
-
healedSteps++;
|
|
151
|
-
return;
|
|
152
|
-
} catch (err) {
|
|
153
|
-
debug('Failed to execute code', err);
|
|
154
|
-
recorder.ignoreErr(err); // healing ded not help
|
|
155
|
-
// recorder.catch(() => output.print(colors.bold.red(' Failed healing code')));
|
|
156
|
-
}
|
|
115
|
+
print(`${i}. To fix ${colors.bold.magenta(suggestion.test?.title)}`)
|
|
116
|
+
print(' Replace the failed code:', colors.gray(`(suggested by ${colors.bold(suggestion.recipe)})`))
|
|
117
|
+
print(colors.red(`- ${suggestion.step.toCode()}`))
|
|
118
|
+
print(colors.green(`+ ${suggestion.snippet}`))
|
|
119
|
+
print(suggestion.step.line())
|
|
120
|
+
print('')
|
|
121
|
+
i++
|
|
157
122
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
event.dispatcher.on(event.workers.result, result => {
|
|
126
|
+
const { print } = output
|
|
127
|
+
|
|
128
|
+
const healedTests = Object.values(result.tests)
|
|
129
|
+
.flat()
|
|
130
|
+
.filter(test => test.notes.some(note => note.type === 'heal'))
|
|
131
|
+
if (!healedTests.length) return
|
|
132
|
+
|
|
133
|
+
setTimeout(() => {
|
|
134
|
+
print('')
|
|
135
|
+
print('===================')
|
|
136
|
+
print(colors.bold.green('Self-Healing Report:'))
|
|
137
|
+
|
|
138
|
+
print('')
|
|
139
|
+
print('Suggested changes:')
|
|
140
|
+
print('')
|
|
141
|
+
|
|
142
|
+
healedTests.forEach(test => {
|
|
143
|
+
print(`${colors.bold.magenta(test.title)}`)
|
|
144
|
+
test.notes
|
|
145
|
+
.filter(note => note.type === 'heal')
|
|
146
|
+
.forEach(note => {
|
|
147
|
+
print(note.text)
|
|
148
|
+
print('')
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
}, 0)
|
|
152
|
+
})
|
|
162
153
|
}
|