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/data/context.js
CHANGED
|
@@ -1,128 +1,127 @@
|
|
|
1
|
-
import { isGenerator } from '../utils.js'
|
|
2
|
-
import DataTable from './table.js'
|
|
3
|
-
import DataScenarioConfig from './dataScenarioConfig.js'
|
|
1
|
+
import { isGenerator } from '../utils.js'
|
|
2
|
+
import DataTable from './table.js'
|
|
3
|
+
import DataScenarioConfig from './dataScenarioConfig.js'
|
|
4
|
+
import secretModule from '../secret.js'
|
|
5
|
+
const Secret = secretModule.default || secretModule
|
|
4
6
|
|
|
5
7
|
export default function (context) {
|
|
6
8
|
context.Data = function (dataTable) {
|
|
7
|
-
const data = detectDataType(dataTable)
|
|
9
|
+
const data = detectDataType(dataTable)
|
|
8
10
|
return {
|
|
9
11
|
Scenario(title, opts, fn) {
|
|
10
|
-
const scenarios = []
|
|
12
|
+
const scenarios = []
|
|
11
13
|
if (typeof opts === 'function' && !fn) {
|
|
12
|
-
fn = opts
|
|
13
|
-
opts = {}
|
|
14
|
+
fn = opts
|
|
15
|
+
opts = {}
|
|
14
16
|
}
|
|
15
|
-
opts.data = data.map(dataRow => dataRow.data)
|
|
16
|
-
data.forEach(
|
|
17
|
-
const dataTitle = replaceTitle(title, dataRow)
|
|
17
|
+
opts.data = data.map(dataRow => dataRow.data)
|
|
18
|
+
data.forEach(dataRow => {
|
|
19
|
+
const dataTitle = replaceTitle(title, dataRow)
|
|
18
20
|
if (dataRow.skip) {
|
|
19
|
-
context.xScenario(dataTitle)
|
|
21
|
+
context.xScenario(dataTitle)
|
|
20
22
|
} else {
|
|
21
|
-
scenarios.push(context.Scenario(dataTitle, opts, fn)
|
|
22
|
-
.inject({ current: dataRow.data }));
|
|
23
|
+
scenarios.push(context.Scenario(dataTitle, opts, fn).inject({ current: dataRow.data }))
|
|
23
24
|
}
|
|
24
|
-
})
|
|
25
|
-
maskSecretInTitle(scenarios)
|
|
26
|
-
return new DataScenarioConfig(scenarios)
|
|
25
|
+
})
|
|
26
|
+
maskSecretInTitle(scenarios)
|
|
27
|
+
return new DataScenarioConfig(scenarios)
|
|
27
28
|
},
|
|
28
29
|
only: {
|
|
29
30
|
Scenario(title, opts, fn) {
|
|
30
|
-
const scenarios = []
|
|
31
|
+
const scenarios = []
|
|
31
32
|
if (typeof opts === 'function' && !fn) {
|
|
32
|
-
fn = opts
|
|
33
|
-
opts = {}
|
|
33
|
+
fn = opts
|
|
34
|
+
opts = {}
|
|
34
35
|
}
|
|
35
|
-
opts.data = data.map(dataRow => dataRow.data)
|
|
36
|
-
data.forEach(
|
|
37
|
-
const dataTitle = replaceTitle(title, dataRow)
|
|
36
|
+
opts.data = data.map(dataRow => dataRow.data)
|
|
37
|
+
data.forEach(dataRow => {
|
|
38
|
+
const dataTitle = replaceTitle(title, dataRow)
|
|
38
39
|
if (dataRow.skip) {
|
|
39
|
-
context.xScenario(dataTitle)
|
|
40
|
+
context.xScenario(dataTitle)
|
|
40
41
|
} else {
|
|
41
|
-
scenarios.push(context.Scenario.only(dataTitle, opts, fn)
|
|
42
|
-
.inject({ current: dataRow.data }));
|
|
42
|
+
scenarios.push(context.Scenario.only(dataTitle, opts, fn).inject({ current: dataRow.data }))
|
|
43
43
|
}
|
|
44
|
-
})
|
|
45
|
-
maskSecretInTitle(scenarios)
|
|
46
|
-
return new DataScenarioConfig(scenarios)
|
|
44
|
+
})
|
|
45
|
+
maskSecretInTitle(scenarios)
|
|
46
|
+
return new DataScenarioConfig(scenarios)
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
|
-
}
|
|
50
|
-
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
51
|
|
|
52
52
|
context.xData = function (dataTable) {
|
|
53
|
-
const data = detectDataType(dataTable)
|
|
53
|
+
const data = detectDataType(dataTable)
|
|
54
54
|
return {
|
|
55
|
-
Scenario:
|
|
56
|
-
data.forEach(
|
|
57
|
-
const dataTitle = replaceTitle(title, dataRow)
|
|
58
|
-
context.xScenario(dataTitle)
|
|
59
|
-
})
|
|
60
|
-
return new DataScenarioConfig([])
|
|
55
|
+
Scenario: title => {
|
|
56
|
+
data.forEach(dataRow => {
|
|
57
|
+
const dataTitle = replaceTitle(title, dataRow)
|
|
58
|
+
context.xScenario(dataTitle)
|
|
59
|
+
})
|
|
60
|
+
return new DataScenarioConfig([])
|
|
61
61
|
},
|
|
62
|
-
}
|
|
63
|
-
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function replaceTitle(title, dataRow) {
|
|
67
67
|
if (typeof dataRow.data !== 'object') {
|
|
68
|
-
return `${title} | {${JSON.stringify(dataRow.data)}}
|
|
68
|
+
return `${title} | {${JSON.stringify(dataRow.data)}}`
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
// if `dataRow` is object and has own `toString()` method,
|
|
72
72
|
// it should be printed
|
|
73
|
-
if (Object.prototype.toString.call(dataRow.data) ===
|
|
74
|
-
|
|
75
|
-
return `${title} | ${dataRow.data}`;
|
|
73
|
+
if (Object.prototype.toString.call(dataRow.data) === Object().toString() && dataRow.data.toString() !== Object().toString()) {
|
|
74
|
+
return `${title} | ${dataRow.data}`
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
return `${title} | ${JSON.stringify(dataRow.data)}
|
|
77
|
+
return `${title} | ${JSON.stringify(dataRow.data)}`
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
function isTableDataRow(row) {
|
|
82
|
-
const has = Object.prototype.hasOwnProperty
|
|
83
|
-
return has.call(row, 'data') && has.call(row, 'skip')
|
|
81
|
+
const has = Object.prototype.hasOwnProperty
|
|
82
|
+
return has.call(row, 'data') && has.call(row, 'skip')
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
function detectDataType(dataTable) {
|
|
87
86
|
if (dataTable instanceof DataTable) {
|
|
88
|
-
return dataTable.rows
|
|
87
|
+
return dataTable.rows
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
if (isGenerator(dataTable)) {
|
|
92
|
-
const data = []
|
|
91
|
+
const data = []
|
|
93
92
|
for (const dataRow of dataTable()) {
|
|
94
93
|
data.push({
|
|
95
94
|
data: dataRow,
|
|
96
|
-
})
|
|
95
|
+
})
|
|
97
96
|
}
|
|
98
|
-
return data
|
|
97
|
+
return data
|
|
99
98
|
}
|
|
100
99
|
if (typeof dataTable === 'function') {
|
|
101
|
-
return dataTable()
|
|
100
|
+
return dataTable()
|
|
102
101
|
}
|
|
103
102
|
if (Array.isArray(dataTable)) {
|
|
104
|
-
return dataTable.map(
|
|
103
|
+
return dataTable.map(item => {
|
|
105
104
|
if (isTableDataRow(item)) {
|
|
106
|
-
return item
|
|
105
|
+
return item
|
|
107
106
|
}
|
|
108
107
|
return {
|
|
109
108
|
data: item,
|
|
110
109
|
skip: false,
|
|
111
|
-
}
|
|
112
|
-
})
|
|
110
|
+
}
|
|
111
|
+
})
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
throw new Error('Invalid data type. Data accepts either: DataTable || generator || Array || function')
|
|
114
|
+
throw new Error('Invalid data type. Data accepts either: DataTable || generator || Array || function')
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
function maskSecretInTitle(scenarios) {
|
|
119
118
|
scenarios.forEach(scenario => {
|
|
120
|
-
const res = []
|
|
119
|
+
const res = []
|
|
121
120
|
|
|
122
121
|
scenario.test.title.split(',').forEach(item => {
|
|
123
|
-
res.push(item.replace(/{"_secret":"(.*)"}/, '"*****"'))
|
|
124
|
-
})
|
|
122
|
+
res.push(item.replace(/{"_secret":"(.*)"}/, '"*****"'))
|
|
123
|
+
})
|
|
125
124
|
|
|
126
|
-
scenario.test.title = res.join(',')
|
|
127
|
-
})
|
|
125
|
+
scenario.test.title = res.join(',')
|
|
126
|
+
})
|
|
128
127
|
}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
1
|
class DataScenarioConfig {
|
|
2
2
|
constructor(scenarios) {
|
|
3
|
-
this.scenarios = scenarios
|
|
3
|
+
this.scenarios = scenarios
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
* Declares that test throws error.
|
|
8
|
+
* Can pass an Error object or regex matching expected message.
|
|
9
|
+
*
|
|
10
|
+
* @param {*} err
|
|
11
|
+
*/
|
|
12
12
|
throws(err) {
|
|
13
|
-
this.scenarios.forEach(scenario => scenario.throws(err))
|
|
14
|
-
return this
|
|
13
|
+
this.scenarios.forEach(scenario => scenario.throws(err))
|
|
14
|
+
return this
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
* Declares that test should fail.
|
|
19
|
+
* If test passes - throws an error.
|
|
20
|
+
* Can pass an Error object or regex matching expected message.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
23
|
fails() {
|
|
24
|
-
this.scenarios.forEach(scenario => scenario.fails())
|
|
25
|
-
return this
|
|
24
|
+
this.scenarios.forEach(scenario => scenario.fails())
|
|
25
|
+
return this
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
* Retry this test for x times
|
|
30
|
+
*
|
|
31
|
+
* @param {*} retries
|
|
32
|
+
*/
|
|
33
33
|
retry(retries) {
|
|
34
|
-
this.scenarios.forEach(scenario => scenario.retry(retries))
|
|
35
|
-
return this
|
|
34
|
+
this.scenarios.forEach(scenario => scenario.retry(retries))
|
|
35
|
+
return this
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
* Set timeout for this test
|
|
40
|
+
* @param {*} timeout
|
|
41
|
+
*/
|
|
42
42
|
timeout(timeout) {
|
|
43
|
-
this.scenarios.forEach(scenario => scenario.timeout(timeout))
|
|
44
|
-
return this
|
|
43
|
+
this.scenarios.forEach(scenario => scenario.timeout(timeout))
|
|
44
|
+
return this
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
* Configures a helper.
|
|
49
|
+
* Helper name can be omitted and values will be applied to first helper.
|
|
50
|
+
*/
|
|
51
51
|
config(helper, obj) {
|
|
52
|
-
this.scenarios.forEach(scenario => scenario.config(helper, obj))
|
|
53
|
-
return this
|
|
52
|
+
this.scenarios.forEach(scenario => scenario.config(helper, obj))
|
|
53
|
+
return this
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
* Append a tag name to scenario title
|
|
58
|
+
* @param {*} tagName
|
|
59
|
+
*/
|
|
60
60
|
tag(tagName) {
|
|
61
|
-
this.scenarios.forEach(scenario => scenario.tag(tagName))
|
|
62
|
-
return this
|
|
61
|
+
this.scenarios.forEach(scenario => scenario.tag(tagName))
|
|
62
|
+
return this
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
* Pass in additional objects to inject into test
|
|
67
|
+
* @param {*} obj
|
|
68
|
+
*/
|
|
69
69
|
inject(obj) {
|
|
70
|
-
this.scenarios.forEach(scenario => scenario.inject(obj))
|
|
71
|
-
return this
|
|
70
|
+
this.scenarios.forEach(scenario => scenario.inject(obj))
|
|
71
|
+
return this
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
* Dynamically injects dependencies, see https://codecept.io/pageobjects/#dynamic-injection
|
|
76
|
+
* @param {*} dependencies
|
|
77
|
+
*/
|
|
78
78
|
injectDependencies(dependencies) {
|
|
79
|
-
this.scenarios.forEach(scenario => scenario.injectDependencies(dependencies))
|
|
80
|
-
return this
|
|
79
|
+
this.scenarios.forEach(scenario => scenario.injectDependencies(dependencies))
|
|
80
|
+
return this
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export default DataScenarioConfig
|
|
84
|
+
export default DataScenarioConfig
|
|
@@ -5,62 +5,62 @@
|
|
|
5
5
|
class DataTableArgument {
|
|
6
6
|
/** @param {*} gherkinDataTable */
|
|
7
7
|
constructor(gherkinDataTable) {
|
|
8
|
-
this.rawData = gherkinDataTable.rows.map(
|
|
9
|
-
return row.cells.map(
|
|
10
|
-
return cell.value
|
|
11
|
-
})
|
|
12
|
-
})
|
|
8
|
+
this.rawData = gherkinDataTable.rows.map(row => {
|
|
9
|
+
return row.cells.map(cell => {
|
|
10
|
+
return cell.value
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** Returns the table as a 2-D array
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
* @returns {string[][]}
|
|
17
|
+
*/
|
|
18
18
|
raw() {
|
|
19
|
-
return this.rawData.slice(0)
|
|
19
|
+
return this.rawData.slice(0)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/** Returns the table as a 2-D array, without the first row
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
* @returns {string[][]}
|
|
24
|
+
*/
|
|
25
25
|
rows() {
|
|
26
|
-
const copy = this.raw()
|
|
27
|
-
copy.shift()
|
|
28
|
-
return copy
|
|
26
|
+
const copy = this.raw()
|
|
27
|
+
copy.shift()
|
|
28
|
+
return copy
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Returns an array of objects where each row is converted to an object (column header is the key)
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
* @returns {any[]}
|
|
33
|
+
*/
|
|
34
34
|
hashes() {
|
|
35
|
-
const copy = this.raw()
|
|
36
|
-
const header = copy.shift()
|
|
37
|
-
return copy.map(
|
|
38
|
-
const r = {}
|
|
39
|
-
row.forEach((cell, index) => r[header[index]] = cell)
|
|
40
|
-
return r
|
|
41
|
-
})
|
|
35
|
+
const copy = this.raw()
|
|
36
|
+
const header = copy.shift()
|
|
37
|
+
return copy.map(row => {
|
|
38
|
+
const r = {}
|
|
39
|
+
row.forEach((cell, index) => (r[header[index]] = cell))
|
|
40
|
+
return r
|
|
41
|
+
})
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** Returns an object where each row corresponds to an entry
|
|
45
45
|
* (first column is the key, second column is the value)
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
* @returns {Record<string, string>}
|
|
47
|
+
*/
|
|
48
48
|
rowsHash() {
|
|
49
|
-
const rows = this.raw()
|
|
50
|
-
const everyRowHasTwoColumns = rows.every(
|
|
49
|
+
const rows = this.raw()
|
|
50
|
+
const everyRowHasTwoColumns = rows.every(row => row.length === 2)
|
|
51
51
|
if (!everyRowHasTwoColumns) {
|
|
52
|
-
throw new Error('rowsHash can only be called on a data table where all rows have exactly two columns')
|
|
52
|
+
throw new Error('rowsHash can only be called on a data table where all rows have exactly two columns')
|
|
53
53
|
}
|
|
54
54
|
/** @type {Record<string, string>} */
|
|
55
|
-
const result = {}
|
|
56
|
-
rows.forEach(
|
|
57
|
-
return result
|
|
55
|
+
const result = {}
|
|
56
|
+
rows.forEach(x => (result[x[0]] = x[1]))
|
|
57
|
+
return result
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/** Transposed the data */
|
|
61
61
|
transpose() {
|
|
62
|
-
this.rawData = this.rawData[0].map((x, i) => this.rawData.map(
|
|
62
|
+
this.rawData = this.rawData[0].map((x, i) => this.rawData.map(y => y[i]))
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export default DataTableArgument
|
|
66
|
+
export default DataTableArgument
|
package/lib/data/table.js
CHANGED
|
@@ -4,40 +4,40 @@
|
|
|
4
4
|
class DataTable {
|
|
5
5
|
/** @param {Array<*>} array */
|
|
6
6
|
constructor(array) {
|
|
7
|
-
this.array = array
|
|
8
|
-
this.rows = new Array(0)
|
|
7
|
+
this.array = array
|
|
8
|
+
this.rows = new Array(0)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** @param {Array<*>} array */
|
|
12
12
|
add(array) {
|
|
13
|
-
if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`)
|
|
14
|
-
const tempObj = {}
|
|
15
|
-
let arrayCounter = 0
|
|
16
|
-
this.array.forEach(
|
|
17
|
-
tempObj[elem] = array[arrayCounter]
|
|
18
|
-
tempObj.toString = () => JSON.stringify(tempObj)
|
|
19
|
-
arrayCounter
|
|
20
|
-
})
|
|
21
|
-
this.rows.push({ skip: false, data: tempObj })
|
|
13
|
+
if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`)
|
|
14
|
+
const tempObj = {}
|
|
15
|
+
let arrayCounter = 0
|
|
16
|
+
this.array.forEach(elem => {
|
|
17
|
+
tempObj[elem] = array[arrayCounter]
|
|
18
|
+
tempObj.toString = () => JSON.stringify(tempObj)
|
|
19
|
+
arrayCounter++
|
|
20
|
+
})
|
|
21
|
+
this.rows.push({ skip: false, data: tempObj })
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** @param {Array<*>} array */
|
|
25
25
|
xadd(array) {
|
|
26
|
-
if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`)
|
|
27
|
-
const tempObj = {}
|
|
28
|
-
let arrayCounter = 0
|
|
29
|
-
this.array.forEach(
|
|
30
|
-
tempObj[elem] = array[arrayCounter]
|
|
31
|
-
tempObj.toString = () => JSON.stringify(tempObj)
|
|
32
|
-
arrayCounter
|
|
33
|
-
})
|
|
34
|
-
this.rows.push({ skip: true, data: tempObj })
|
|
26
|
+
if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`)
|
|
27
|
+
const tempObj = {}
|
|
28
|
+
let arrayCounter = 0
|
|
29
|
+
this.array.forEach(elem => {
|
|
30
|
+
tempObj[elem] = array[arrayCounter]
|
|
31
|
+
tempObj.toString = () => JSON.stringify(tempObj)
|
|
32
|
+
arrayCounter++
|
|
33
|
+
})
|
|
34
|
+
this.rows.push({ skip: true, data: tempObj })
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/** @param {Function} func */
|
|
38
38
|
filter(func) {
|
|
39
|
-
return this.rows.filter(row => func(row.data))
|
|
39
|
+
return this.rows.filter(row => func(row.data))
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export default DataTable
|
|
43
|
+
export default DataTable
|