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/els.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import output from './output.js'
|
|
2
|
+
import store from './store.js'
|
|
3
|
+
import container from './container.js'
|
|
4
|
+
import StepConfig from './step/config.js'
|
|
5
|
+
import recordStep from './step/record.js'
|
|
6
|
+
import FuncStep from './step/func.js'
|
|
7
|
+
import { truth } from './assert/truth.js'
|
|
8
|
+
import { isAsyncFunction, humanizeFunction } from './utils.js'
|
|
9
|
+
|
|
10
|
+
function element(purpose, locator, fn) {
|
|
11
|
+
let stepConfig
|
|
12
|
+
if (arguments[arguments.length - 1] instanceof StepConfig) {
|
|
13
|
+
stepConfig = arguments[arguments.length - 1]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!fn || fn === stepConfig) {
|
|
17
|
+
fn = locator
|
|
18
|
+
locator = purpose
|
|
19
|
+
purpose = 'first element'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const step = prepareStep(purpose, locator, fn)
|
|
23
|
+
if (!step) return
|
|
24
|
+
|
|
25
|
+
return executeStep(
|
|
26
|
+
step,
|
|
27
|
+
async () => {
|
|
28
|
+
const els = await step.helper._locate(locator)
|
|
29
|
+
output.debug(`Found ${els.length} elements, using first element`)
|
|
30
|
+
|
|
31
|
+
return fn(els[0])
|
|
32
|
+
},
|
|
33
|
+
stepConfig,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function eachElement(purpose, locator, fn) {
|
|
38
|
+
if (!fn) {
|
|
39
|
+
fn = locator
|
|
40
|
+
locator = purpose
|
|
41
|
+
purpose = 'for each element'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const step = prepareStep(purpose, locator, fn)
|
|
45
|
+
if (!step) return
|
|
46
|
+
|
|
47
|
+
return executeStep(step, async () => {
|
|
48
|
+
const els = await step.helper._locate(locator)
|
|
49
|
+
output.debug(`Found ${els.length} elements for each elements to iterate`)
|
|
50
|
+
|
|
51
|
+
const errs = []
|
|
52
|
+
let i = 0
|
|
53
|
+
for (const el of els) {
|
|
54
|
+
try {
|
|
55
|
+
await fn(el, i)
|
|
56
|
+
} catch (err) {
|
|
57
|
+
output.error(`eachElement: failed operation on element #${i} ${el}`)
|
|
58
|
+
errs.push(err)
|
|
59
|
+
}
|
|
60
|
+
i++
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (errs.length) {
|
|
64
|
+
throw errs[0]
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function expectElement(locator, fn) {
|
|
70
|
+
const step = prepareStep('expect element to be', locator, fn)
|
|
71
|
+
if (!step) return
|
|
72
|
+
|
|
73
|
+
return executeStep(step, async () => {
|
|
74
|
+
const els = await step.helper._locate(locator)
|
|
75
|
+
output.debug(`Found ${els.length} elements, first will be used for assertion`)
|
|
76
|
+
|
|
77
|
+
const result = await fn(els[0])
|
|
78
|
+
const assertion = truth(`element (${locator})`, fn.toString())
|
|
79
|
+
assertion.assert(result)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function expectAnyElement(locator, fn) {
|
|
84
|
+
const step = prepareStep('expect any element to be', locator, fn)
|
|
85
|
+
if (!step) return
|
|
86
|
+
|
|
87
|
+
return executeStep(step, async () => {
|
|
88
|
+
const els = await step.helper._locate(locator)
|
|
89
|
+
output.debug(`Found ${els.length} elements, at least one should pass the assertion`)
|
|
90
|
+
|
|
91
|
+
const assertion = truth(`any element of (${locator})`, fn.toString())
|
|
92
|
+
|
|
93
|
+
let found = false
|
|
94
|
+
for (const el of els) {
|
|
95
|
+
const result = await fn(el)
|
|
96
|
+
if (result) {
|
|
97
|
+
found = true
|
|
98
|
+
break
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!found) throw assertion.getException()
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function expectAllElements(locator, fn) {
|
|
106
|
+
const step = prepareStep('expect all elements', locator, fn)
|
|
107
|
+
if (!step) return
|
|
108
|
+
|
|
109
|
+
return executeStep(step, async () => {
|
|
110
|
+
const els = await step.helper._locate(locator)
|
|
111
|
+
output.debug(`Found ${els.length} elements, all should pass the assertion`)
|
|
112
|
+
|
|
113
|
+
let i = 1
|
|
114
|
+
for (const el of els) {
|
|
115
|
+
output.debug(`checking element #${i}: ${el}`)
|
|
116
|
+
const result = await fn(el)
|
|
117
|
+
const assertion = truth(`element #${i} of (${locator})`, humanizeFunction(fn))
|
|
118
|
+
assertion.assert(result)
|
|
119
|
+
i++
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { element, eachElement, expectElement, expectAnyElement, expectAllElements }
|
|
125
|
+
|
|
126
|
+
export default {
|
|
127
|
+
element,
|
|
128
|
+
eachElement,
|
|
129
|
+
expectElement,
|
|
130
|
+
expectAnyElement,
|
|
131
|
+
expectAllElements,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function prepareStep(purpose, locator, fn) {
|
|
135
|
+
if (store.dryRun) return
|
|
136
|
+
const helpers = Object.values(container.helpers())
|
|
137
|
+
|
|
138
|
+
const helper = helpers.filter(h => !!h._locate)[0]
|
|
139
|
+
|
|
140
|
+
if (!helper) {
|
|
141
|
+
throw new Error('No helper enabled with _locate method with returns a list of elements.')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!isAsyncFunction(fn)) {
|
|
145
|
+
throw new Error('Async function should be passed into each element')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const isAssertion = purpose.startsWith('expect')
|
|
149
|
+
|
|
150
|
+
const step = new FuncStep(`${purpose} within "${locator}" ${isAssertion ? 'to be' : 'to'}`)
|
|
151
|
+
step.setHelper(helper)
|
|
152
|
+
step.setArguments([humanizeFunction(fn)]) // user defined function is a passed argument
|
|
153
|
+
|
|
154
|
+
return step
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function executeStep(step, action, stepConfig = {}) {
|
|
158
|
+
step.setCallable(action)
|
|
159
|
+
return recordStep(step, [stepConfig])
|
|
160
|
+
}
|
package/lib/event.js
CHANGED
|
@@ -1,176 +1,186 @@
|
|
|
1
|
-
import
|
|
1
|
+
import debugModule from 'debug'
|
|
2
|
+
const debug = debugModule('codeceptjs:event')
|
|
3
|
+
import events from 'events'
|
|
4
|
+
import output from './output.js'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
import * as output from './output.js';
|
|
6
|
+
const MAX_LISTENERS = 200
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const dispatcher = new events.EventEmitter()
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
dispatcher.setMaxListeners(MAX_LISTENERS)
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
// Increase process max listeners to prevent warnings for beforeExit and other events
|
|
13
|
+
if (typeof process.setMaxListeners === 'function') {
|
|
14
|
+
process.setMaxListeners(MAX_LISTENERS)
|
|
15
|
+
}
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @inner
|
|
16
|
-
* @property {'test.start'} started
|
|
17
|
-
* @property {'test.before'} before
|
|
18
|
-
* @property {'test.after'} after
|
|
19
|
-
* @property {'test.passed'} passed
|
|
20
|
-
* @property {'test.failed'} failed
|
|
21
|
-
* @property {'test.finish'} finished
|
|
22
|
-
* @property {'test.skipped'} skipped
|
|
18
|
+
* @namespace
|
|
19
|
+
* @alias event
|
|
23
20
|
*/
|
|
24
|
-
export const test = {
|
|
25
|
-
started: 'test.start', // sync
|
|
26
|
-
before: 'test.before', // async
|
|
27
|
-
after: 'test.after', // async
|
|
28
|
-
passed: 'test.passed', // sync
|
|
29
|
-
failed: 'test.failed', // sync
|
|
30
|
-
finished: 'test.finish', // sync
|
|
31
|
-
skipped: 'test.skipped', // sync
|
|
32
|
-
};
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
started: 'bddStep.started',
|
|
89
|
-
finished: 'bddStep.finished',
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* @type {object}
|
|
93
|
-
* @constant
|
|
94
|
-
* @inner
|
|
95
|
-
* @property {'global.before'} before
|
|
96
|
-
* @property {'global.after'} after
|
|
97
|
-
* @property {'global.result'} result
|
|
98
|
-
* @property {'global.failures'} failures
|
|
99
|
-
*/
|
|
100
|
-
export const all = {
|
|
101
|
-
before: 'global.before',
|
|
102
|
-
after: 'global.after',
|
|
103
|
-
result: 'global.result',
|
|
104
|
-
failures: 'global.failures',
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* @type {object}
|
|
108
|
-
* @constant
|
|
109
|
-
* @inner
|
|
110
|
-
* @property {'multiple.before'} before
|
|
111
|
-
* @property {'multiple.after'} after
|
|
112
|
-
*/
|
|
113
|
-
export const multiple = {
|
|
114
|
-
before: 'multiple.before',
|
|
115
|
-
after: 'multiple.after',
|
|
116
|
-
};
|
|
22
|
+
export default {
|
|
23
|
+
/**
|
|
24
|
+
* @type {NodeJS.EventEmitter}
|
|
25
|
+
* @constant
|
|
26
|
+
* @inner
|
|
27
|
+
*/
|
|
28
|
+
dispatcher,
|
|
29
|
+
/**
|
|
30
|
+
* @type {object}
|
|
31
|
+
* @constant
|
|
32
|
+
* @inner
|
|
33
|
+
* @property {'test.start'} started
|
|
34
|
+
* @property {'test.before'} before
|
|
35
|
+
* @property {'test.after'} after
|
|
36
|
+
* @property {'test.passed'} passed
|
|
37
|
+
* @property {'test.failed'} failed
|
|
38
|
+
* @property {'test.finish'} finished
|
|
39
|
+
* @property {'test.skipped'} skipped
|
|
40
|
+
*/
|
|
41
|
+
test: {
|
|
42
|
+
started: 'test.start', // sync
|
|
43
|
+
before: 'test.before', // async
|
|
44
|
+
after: 'test.after', // async
|
|
45
|
+
passed: 'test.passed', // sync
|
|
46
|
+
failed: 'test.failed', // sync
|
|
47
|
+
finished: 'test.finish', // sync
|
|
48
|
+
skipped: 'test.skipped', // sync
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* @type {object}
|
|
52
|
+
* @constant
|
|
53
|
+
* @inner
|
|
54
|
+
* @property {'suite.before'} before
|
|
55
|
+
* @property {'suite.after'} after
|
|
56
|
+
*/
|
|
57
|
+
suite: {
|
|
58
|
+
before: 'suite.before',
|
|
59
|
+
after: 'suite.after',
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* @type {object}
|
|
63
|
+
* @constant
|
|
64
|
+
* @inner
|
|
65
|
+
* @property {'hook.start'} started
|
|
66
|
+
* @property {'hook.passed'} passed
|
|
67
|
+
* @property {'hook.failed'} failed
|
|
68
|
+
* @property {'hook.finished'} finished
|
|
69
|
+
*/
|
|
70
|
+
hook: {
|
|
71
|
+
started: 'hook.start',
|
|
72
|
+
passed: 'hook.passed',
|
|
73
|
+
failed: 'hook.failed',
|
|
74
|
+
finished: 'hook.finished',
|
|
75
|
+
},
|
|
117
76
|
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @type {object}
|
|
79
|
+
* @constant
|
|
80
|
+
* @inner
|
|
81
|
+
* @property {'step.start'} started
|
|
82
|
+
* @property {'step.before'} before
|
|
83
|
+
* @property {'step.after'} after
|
|
84
|
+
* @property {'step.passed'} passed
|
|
85
|
+
* @property {'step.failed'} failed
|
|
86
|
+
* @property {'step.finish'} finished
|
|
87
|
+
* @property {'step.comment'} comment
|
|
88
|
+
*/
|
|
89
|
+
step: {
|
|
90
|
+
before: 'step.before', // async
|
|
91
|
+
after: 'step.after', // async
|
|
92
|
+
started: 'step.start', // sync
|
|
93
|
+
passed: 'step.passed', // sync
|
|
94
|
+
failed: 'step.failed', // sync
|
|
95
|
+
finished: 'step.finish', // sync
|
|
96
|
+
comment: 'step.comment',
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* @type {object}
|
|
100
|
+
* @constant
|
|
101
|
+
* @inner
|
|
102
|
+
* @property {'suite.before'} before
|
|
103
|
+
* @property {'suite.after'} after
|
|
104
|
+
*/
|
|
105
|
+
bddStep: {
|
|
106
|
+
before: 'bddStep.before',
|
|
107
|
+
after: 'bddStep.after',
|
|
108
|
+
started: 'bddStep.started',
|
|
109
|
+
finished: 'bddStep.finished',
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* @type {object}
|
|
113
|
+
* @constant
|
|
114
|
+
* @inner
|
|
115
|
+
* @property {'global.before'} before
|
|
116
|
+
* @property {'global.after'} after
|
|
117
|
+
* @property {'global.result'} result
|
|
118
|
+
* @property {'global.failures'} failures
|
|
119
|
+
*/
|
|
120
|
+
all: {
|
|
121
|
+
before: 'global.before',
|
|
122
|
+
after: 'global.after',
|
|
123
|
+
result: 'global.result',
|
|
124
|
+
failures: 'global.failures',
|
|
125
|
+
},
|
|
126
|
+
/**
|
|
127
|
+
* @type {object}
|
|
128
|
+
* @constant
|
|
129
|
+
* @inner
|
|
130
|
+
* @property {'multiple.before'} before
|
|
131
|
+
* @property {'multiple.after'} after
|
|
132
|
+
*/
|
|
133
|
+
multiple: {
|
|
134
|
+
before: 'multiple.before',
|
|
135
|
+
after: 'multiple.after',
|
|
136
|
+
},
|
|
131
137
|
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
dispatcher.removeAllListeners(test[event]);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
138
|
+
/**
|
|
139
|
+
* @type {object}
|
|
140
|
+
* @constant
|
|
141
|
+
* @inner
|
|
142
|
+
* @property {'workers.before'} before
|
|
143
|
+
* @property {'workers.after'} after
|
|
144
|
+
* @property {'workers.result'} result
|
|
145
|
+
*/
|
|
146
|
+
workers: {
|
|
147
|
+
before: 'workers.before',
|
|
148
|
+
after: 'workers.after',
|
|
149
|
+
result: 'workers.result',
|
|
150
|
+
},
|
|
148
151
|
|
|
149
|
-
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
152
|
+
/**
|
|
153
|
+
* @param {string} event
|
|
154
|
+
* @param {*} [param]
|
|
155
|
+
*/
|
|
156
|
+
emit(event, param) {
|
|
157
|
+
let msg = `Emitted | ${event}`
|
|
158
|
+
if (param && param.toString()) {
|
|
159
|
+
msg += ` (${param.toString()})`
|
|
160
|
+
}
|
|
161
|
+
debug(msg)
|
|
162
|
+
try {
|
|
163
|
+
this.dispatcher.emit.apply(this.dispatcher, arguments)
|
|
164
|
+
} catch (err) {
|
|
165
|
+
output.error(`Error processing ${event} event:`)
|
|
166
|
+
output.error(err.stack)
|
|
167
|
+
}
|
|
168
|
+
},
|
|
159
169
|
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
170
|
+
/** for testing only! */
|
|
171
|
+
cleanDispatcher() {
|
|
172
|
+
let event
|
|
173
|
+
for (event in this.test) {
|
|
174
|
+
this.dispatcher.removeAllListeners(this.test[event])
|
|
175
|
+
}
|
|
176
|
+
for (event in this.suite) {
|
|
177
|
+
this.dispatcher.removeAllListeners(this.suite[event])
|
|
178
|
+
}
|
|
179
|
+
for (event in this.step) {
|
|
180
|
+
this.dispatcher.removeAllListeners(this.step[event])
|
|
181
|
+
}
|
|
182
|
+
for (event in this.all) {
|
|
183
|
+
this.dispatcher.removeAllListeners(this.all[event])
|
|
184
|
+
}
|
|
185
|
+
},
|
|
176
186
|
}
|
package/lib/globals.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global variables initialization module
|
|
3
|
+
*
|
|
4
|
+
* Centralizes all global variable setup for CodeceptJS from codecept.js and mocha/ui.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fsPath from 'path'
|
|
8
|
+
import ActorFactory from './actor.js'
|
|
9
|
+
import output from './output.js'
|
|
10
|
+
import locator from './locator.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Initialize CodeceptJS core globals
|
|
14
|
+
* Called from Codecept.initGlobals()
|
|
15
|
+
*/
|
|
16
|
+
export async function initCodeceptGlobals(dir, config, container) {
|
|
17
|
+
global.codecept_dir = dir
|
|
18
|
+
global.output_dir = fsPath.resolve(dir, config.output)
|
|
19
|
+
|
|
20
|
+
if (config.noGlobals) return;
|
|
21
|
+
// Set up actor global - will use container when available
|
|
22
|
+
global.actor = global.codecept_actor = (obj) => {
|
|
23
|
+
return ActorFactory(obj, global.container || container)
|
|
24
|
+
}
|
|
25
|
+
global.Actor = global.actor
|
|
26
|
+
|
|
27
|
+
// Use dynamic imports for modules to avoid circular dependencies
|
|
28
|
+
global.pause = async (...args) => {
|
|
29
|
+
const pauseModule = await import('./pause.js')
|
|
30
|
+
return (pauseModule.default || pauseModule)(...args)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
global.within = async (...args) => {
|
|
34
|
+
return (await import('./effects.js')).within(...args)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
global.session = async (...args) => {
|
|
38
|
+
const sessionModule = await import('./session.js')
|
|
39
|
+
return (sessionModule.default || sessionModule)(...args)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const dataTableModule = await import('./data/table.js')
|
|
43
|
+
global.DataTable = dataTableModule.default || dataTableModule
|
|
44
|
+
|
|
45
|
+
global.locate = locatorQuery => {
|
|
46
|
+
return locator.build(locatorQuery)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
global.inject = () => container.support()
|
|
50
|
+
global.share = container.share
|
|
51
|
+
|
|
52
|
+
const secretModule = await import('./secret.js')
|
|
53
|
+
global.secret = secretModule.secret || (secretModule.default && secretModule.default.secret)
|
|
54
|
+
|
|
55
|
+
global.codecept_debug = output.debug
|
|
56
|
+
|
|
57
|
+
const codeceptjsModule = await import('./index.js') // load all objects
|
|
58
|
+
global.codeceptjs = codeceptjsModule.default || codeceptjsModule
|
|
59
|
+
|
|
60
|
+
// BDD step definitions
|
|
61
|
+
const stepDefinitionsModule = await import('./mocha/bdd.js')
|
|
62
|
+
const stepDefinitions = stepDefinitionsModule.default || stepDefinitionsModule
|
|
63
|
+
global.Given = stepDefinitions.Given
|
|
64
|
+
global.When = stepDefinitions.When
|
|
65
|
+
global.Then = stepDefinitions.Then
|
|
66
|
+
global.DefineParameterType = stepDefinitions.defineParameterType
|
|
67
|
+
|
|
68
|
+
// debug mode
|
|
69
|
+
global.debugMode = false
|
|
70
|
+
|
|
71
|
+
// mask sensitive data
|
|
72
|
+
global.maskSensitiveData = config.maskSensitiveData || false
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Initialize Mocha test framework globals (Feature, Scenario, etc.)
|
|
78
|
+
* Called from mocha/ui.js pre-require event
|
|
79
|
+
*/
|
|
80
|
+
export function initMochaGlobals(context) {
|
|
81
|
+
// Mocha test framework globals
|
|
82
|
+
global.BeforeAll = context.BeforeAll
|
|
83
|
+
global.AfterAll = context.AfterAll
|
|
84
|
+
global.Feature = context.Feature
|
|
85
|
+
global.xFeature = context.xFeature
|
|
86
|
+
global.BeforeSuite = context.BeforeSuite
|
|
87
|
+
global.AfterSuite = context.AfterSuite
|
|
88
|
+
global.Background = context.Background
|
|
89
|
+
global.Before = context.Before
|
|
90
|
+
global.After = context.After
|
|
91
|
+
global.Scenario = context.Scenario
|
|
92
|
+
global.xScenario = context.xScenario
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Clear all CodeceptJS globals (useful for testing/cleanup)
|
|
97
|
+
*/
|
|
98
|
+
export function clearGlobals() {
|
|
99
|
+
getGlobalNames().forEach(name => delete global[name]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get list of all CodeceptJS global variable names
|
|
104
|
+
*/
|
|
105
|
+
export function getGlobalNames() {
|
|
106
|
+
return [
|
|
107
|
+
'codecept_dir',
|
|
108
|
+
'output_dir',
|
|
109
|
+
'actor',
|
|
110
|
+
'codecept_actor',
|
|
111
|
+
'Actor',
|
|
112
|
+
'pause',
|
|
113
|
+
'within',
|
|
114
|
+
'session',
|
|
115
|
+
'DataTable',
|
|
116
|
+
'locate',
|
|
117
|
+
'inject',
|
|
118
|
+
'share',
|
|
119
|
+
'secret',
|
|
120
|
+
'codecept_debug',
|
|
121
|
+
'codeceptjs',
|
|
122
|
+
'Given',
|
|
123
|
+
'When',
|
|
124
|
+
'Then',
|
|
125
|
+
'DefineParameterType',
|
|
126
|
+
'debugMode',
|
|
127
|
+
'maskSensitiveData',
|
|
128
|
+
'BeforeAll',
|
|
129
|
+
'AfterAll',
|
|
130
|
+
'Feature',
|
|
131
|
+
'xFeature',
|
|
132
|
+
'BeforeSuite',
|
|
133
|
+
'AfterSuite',
|
|
134
|
+
'Background',
|
|
135
|
+
'Before',
|
|
136
|
+
'After',
|
|
137
|
+
'Scenario',
|
|
138
|
+
'xScenario',
|
|
139
|
+
'container'
|
|
140
|
+
]
|
|
141
|
+
}
|