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
package/lib/plugin/selenoid.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
const util = require('util')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const axios = require('axios').default
|
|
5
|
-
const exec = util.promisify(require('child_process').exec)
|
|
6
|
-
const { clearString, deepMerge } = require('../utils')
|
|
7
|
-
const { container, event, recorder, output } = require('../index')
|
|
8
|
-
|
|
9
|
-
const defaultBrowserConfig = {
|
|
10
|
-
chrome: {
|
|
11
|
-
default: 'latest',
|
|
12
|
-
versions: {
|
|
13
|
-
latest: {
|
|
14
|
-
image: 'selenoid/chrome:latest',
|
|
15
|
-
port: '4444',
|
|
16
|
-
path: '/',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
firefox: {
|
|
21
|
-
default: 'latest',
|
|
22
|
-
versions: {
|
|
23
|
-
latest: {
|
|
24
|
-
image: 'selenoid/firefox:latest',
|
|
25
|
-
port: '4444',
|
|
26
|
-
path: '/wd/hub',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const dockerCreateScriptArr = [
|
|
33
|
-
'docker create --rm --name $name$',
|
|
34
|
-
'-p $port$:4444',
|
|
35
|
-
'-v /var/run/docker.sock:/var/run/docker.sock',
|
|
36
|
-
`-v ${global.codecept_dir}/:/etc/selenoid/:ro`,
|
|
37
|
-
`-v ${global.output_dir}/video/:/opt/selenoid/video/`,
|
|
38
|
-
`-v ${global.output_dir}/logs/:/opt/selenoid/logs/`,
|
|
39
|
-
`-e OVERRIDE_VIDEO_OUTPUT_DIR=${global.output_dir}/video/`,
|
|
40
|
-
'$additionalParams$',
|
|
41
|
-
'aerokube/selenoid:latest-release -log-output-dir /opt/selenoid/logs',
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
const dockerImageCheckScript = [
|
|
45
|
-
'docker images',
|
|
46
|
-
"--filter reference='selenoid/video-recorder'",
|
|
47
|
-
"--filter reference='selenoid/chrome:latest'",
|
|
48
|
-
"--filter reference='selenoid/firefox:latest'",
|
|
49
|
-
].join(' ')
|
|
50
|
-
|
|
51
|
-
let dockerCreateScript = dockerCreateScriptArr.join(' ')
|
|
52
|
-
let dockerStartScript = 'docker start $name$'
|
|
53
|
-
let dockerStopScript = 'docker stop $name$'
|
|
54
|
-
let seleniumUrl = 'http://localhost:$port$'
|
|
55
|
-
|
|
56
|
-
const supportedHelpers = ['WebDriver']
|
|
57
|
-
const SELENOID_START_TIMEOUT = 2000
|
|
58
|
-
const SELENOID_STOP_TIMEOUT = 10000
|
|
59
|
-
const wait = (time) =>
|
|
60
|
-
new Promise((res) => {
|
|
61
|
-
setTimeout(() => {
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
res()
|
|
64
|
-
}, time)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* [Selenoid](https://aerokube.com/selenoid/) plugin automatically starts browsers and video recording.
|
|
69
|
-
* Works with WebDriver helper.
|
|
70
|
-
*
|
|
71
|
-
* ### Prerequisite
|
|
72
|
-
*
|
|
73
|
-
* This plugin **requires Docker** to be installed.
|
|
74
|
-
*
|
|
75
|
-
* > If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager](https://aerokube.com/cm/latest/) tool from Selenoid
|
|
76
|
-
*
|
|
77
|
-
* ### Usage
|
|
78
|
-
*
|
|
79
|
-
* Selenoid plugin can be started in two ways:
|
|
80
|
-
*
|
|
81
|
-
* 1. **Automatic** - this plugin will create and manage selenoid container for you.
|
|
82
|
-
* 2. **Manual** - you create the conatainer and configure it with a plugin (recommended).
|
|
83
|
-
*
|
|
84
|
-
* #### Automatic
|
|
85
|
-
*
|
|
86
|
-
* If you are new to Selenoid and you want plug and play setup use automatic mode.
|
|
87
|
-
*
|
|
88
|
-
* Add plugin configuration in `codecept.conf.js`:
|
|
89
|
-
*
|
|
90
|
-
* ```js
|
|
91
|
-
* plugins: {
|
|
92
|
-
* selenoid: {
|
|
93
|
-
* enabled: true,
|
|
94
|
-
* deletePassed: true,
|
|
95
|
-
* autoCreate: true,
|
|
96
|
-
* autoStart: true,
|
|
97
|
-
* sessionTimeout: '30m',
|
|
98
|
-
* enableVideo: true,
|
|
99
|
-
* enableLog: true,
|
|
100
|
-
* },
|
|
101
|
-
* }
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub](https://hub.docker.com/u/selenoid) and start Selenoid automatically.
|
|
105
|
-
* It will also create `browsers.json` file required by Selenoid.
|
|
106
|
-
*
|
|
107
|
-
* In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
|
|
108
|
-
*
|
|
109
|
-
* > **If you are using Windows machine or if `autoCreate` does not work properly, create container manually**
|
|
110
|
-
*
|
|
111
|
-
* #### Manual
|
|
112
|
-
*
|
|
113
|
-
* While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
|
|
114
|
-
* This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
|
|
115
|
-
*
|
|
116
|
-
* > Use [Selenoid Configuration Manager](https://aerokube.com/cm/latest/) to create and start containers semi-automatically.
|
|
117
|
-
*
|
|
118
|
-
* 1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
|
|
119
|
-
* [Refer to Selenoid documentation](https://aerokube.com/selenoid/latest/#_prepare_configuration) to know more about browsers.json.
|
|
120
|
-
*
|
|
121
|
-
* *Sample browsers.json*
|
|
122
|
-
*
|
|
123
|
-
* ```js
|
|
124
|
-
* {
|
|
125
|
-
* "chrome": {
|
|
126
|
-
* "default": "latest",
|
|
127
|
-
* "versions": {
|
|
128
|
-
* "latest": {
|
|
129
|
-
* "image": "selenoid/chrome:latest",
|
|
130
|
-
* "port": "4444",
|
|
131
|
-
* "path": "/"
|
|
132
|
-
* }
|
|
133
|
-
* }
|
|
134
|
-
* }
|
|
135
|
-
* }
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* > It is recommended to use specific versions of browsers in `browsers.json` instead of latest. This will prevent tests fail when browsers will be updated.
|
|
139
|
-
*
|
|
140
|
-
* **⚠ At first launch selenoid plugin takes extra time to download all Docker images before tests starts**.
|
|
141
|
-
*
|
|
142
|
-
* 2. Create Selenoid container
|
|
143
|
-
*
|
|
144
|
-
* Run the following command to create a container. To know more [refer here](https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container)
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* ```bash
|
|
148
|
-
* docker create \
|
|
149
|
-
* --name selenoid \
|
|
150
|
-
* -p 4444:4444 \
|
|
151
|
-
* -v /var/run/docker.sock:/var/run/docker.sock \
|
|
152
|
-
* -v `pwd`/:/etc/selenoid/:ro \
|
|
153
|
-
* -v `pwd`/output/video/:/opt/selenoid/video/ \
|
|
154
|
-
* -e OVERRIDE_VIDEO_OUTPUT_DIR=`pwd`/output/video/ \
|
|
155
|
-
* aerokube/selenoid:latest-release
|
|
156
|
-
* ```
|
|
157
|
-
*
|
|
158
|
-
* ### Video Recording
|
|
159
|
-
*
|
|
160
|
-
* This plugin allows to record and save video per each executed tests.
|
|
161
|
-
*
|
|
162
|
-
* When `enableVideo` is `true` this plugin saves video in `output/videos` directory with each test by name
|
|
163
|
-
* To save space videos for all succesful tests are deleted. This can be changed by `deletePassed` option.
|
|
164
|
-
*
|
|
165
|
-
* When `allure` plugin is enabled a video is attached to report automatically.
|
|
166
|
-
*
|
|
167
|
-
* ### Options:
|
|
168
|
-
*
|
|
169
|
-
* | Param | Description |
|
|
170
|
-
* |--|--|
|
|
171
|
-
* | name | Name of the container (default : selenoid) |
|
|
172
|
-
* | port | Port of selenium server (default : 4444) |
|
|
173
|
-
* | autoCreate | Will automatically create container (Linux only) (default : true)|
|
|
174
|
-
* | autoStart | If disabled start the container manually before running tests (default : true)|
|
|
175
|
-
* | enableVideo | Enable video recording and use `video` folder of output (default: false) |
|
|
176
|
-
* | enableLog | Enable log recording and use `logs` folder of output (default: false) |
|
|
177
|
-
* | deletePassed | Delete video and logs of passed tests (default : true)|
|
|
178
|
-
* | additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here](https://docs.docker.com/engine/reference/commandline/create/) to know more |
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
const selenoid = (config) => {
|
|
183
|
-
const helpers = container.helpers()
|
|
184
|
-
let helperName
|
|
185
|
-
|
|
186
|
-
for (const name of supportedHelpers) {
|
|
187
|
-
if (Object.keys(helpers).indexOf(name) > -1) {
|
|
188
|
-
helperName = name
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (!helperName) {
|
|
193
|
-
output.print(`Selenoid plugin supported only for: ${supportedHelpers.toString()}`)
|
|
194
|
-
return // no helpers for Selenoid
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const {
|
|
198
|
-
autoStart,
|
|
199
|
-
name = 'selenoid',
|
|
200
|
-
deletePassed = true,
|
|
201
|
-
additionalParams = '',
|
|
202
|
-
autoCreate = true,
|
|
203
|
-
port = 4444,
|
|
204
|
-
} = config
|
|
205
|
-
const passedTests = []
|
|
206
|
-
|
|
207
|
-
recorder.startUnlessRunning()
|
|
208
|
-
replaceScriptConfig({ name, additionalParams, port })
|
|
209
|
-
|
|
210
|
-
if (autoStart) {
|
|
211
|
-
event.dispatcher.on(event.all.before, () => {
|
|
212
|
-
recorder.add('Starting selenoid', () => {
|
|
213
|
-
output.debug('Staring Selenoid... ')
|
|
214
|
-
return createAndStart(autoCreate)
|
|
215
|
-
.then(() => output.debug('Selenoid started'))
|
|
216
|
-
.catch((err) => {
|
|
217
|
-
throw new Error(err.stack)
|
|
218
|
-
})
|
|
219
|
-
})
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
event.dispatcher.on(event.all.after, () => {
|
|
223
|
-
recorder.add('Stopping selenoid', () => {
|
|
224
|
-
output.debug('Stopping Selenoid...')
|
|
225
|
-
return wait(SELENOID_STOP_TIMEOUT)
|
|
226
|
-
.then(() => deletePassedTests(passedTests))
|
|
227
|
-
.then(stopSelenoid)
|
|
228
|
-
.then(() => output.debug('Selenoid stopped'))
|
|
229
|
-
.catch((err) => {
|
|
230
|
-
throw new Error(err.stack)
|
|
231
|
-
})
|
|
232
|
-
})
|
|
233
|
-
})
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
event.dispatcher.on(event.all.before, () => {
|
|
237
|
-
switch (helperName) {
|
|
238
|
-
case 'WebDriver':
|
|
239
|
-
setOptionsForWebdriver(config)
|
|
240
|
-
break
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
event.dispatcher.on(event.test.before, (test) => {
|
|
245
|
-
switch (helperName) {
|
|
246
|
-
case 'WebDriver':
|
|
247
|
-
setTestConfigForWebdriver(test)
|
|
248
|
-
break
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
if (config.enableVideo) {
|
|
253
|
-
event.dispatcher.on(event.test.passed, (test) => {
|
|
254
|
-
if (deletePassed) {
|
|
255
|
-
passedTests.push(test.title)
|
|
256
|
-
} else {
|
|
257
|
-
test.artifacts.video = videoSaved(test)
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
event.dispatcher.on(event.test.failed, (test) => {
|
|
262
|
-
test.artifacts.video = videoSaved(test)
|
|
263
|
-
})
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
module.exports = selenoid
|
|
268
|
-
|
|
269
|
-
function videoSaved(test) {
|
|
270
|
-
const fileName = `${clearString(test.title)}.mp4`
|
|
271
|
-
const videoFile = path.join(global.output_dir, 'video', fileName)
|
|
272
|
-
output.debug(`Video has been saved to file://${videoFile}`)
|
|
273
|
-
const allureReporter = container.plugins('allure')
|
|
274
|
-
if (allureReporter) {
|
|
275
|
-
allureReporter.addAttachment('Video', fs.readFileSync(videoFile), 'video/mp4')
|
|
276
|
-
}
|
|
277
|
-
return videoFile
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const createSelenoidConfig = () => {
|
|
281
|
-
const configPath = path.join(global.codecept_dir, 'browsers.json')
|
|
282
|
-
return new Promise((res, rej) => {
|
|
283
|
-
try {
|
|
284
|
-
if (fs.existsSync(configPath)) {
|
|
285
|
-
res(true)
|
|
286
|
-
} else {
|
|
287
|
-
const data = new Uint8Array(Buffer.from(JSON.stringify(defaultBrowserConfig)))
|
|
288
|
-
fs.writeFileSync(configPath, data)
|
|
289
|
-
res(true)
|
|
290
|
-
}
|
|
291
|
-
} catch (err) {
|
|
292
|
-
rej(err.stack)
|
|
293
|
-
}
|
|
294
|
-
})
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const createSelenoid = () => exec(dockerCreateScript)
|
|
298
|
-
|
|
299
|
-
const startSelenoid = () => exec(dockerStartScript)
|
|
300
|
-
|
|
301
|
-
const stopSelenoid = () => exec(dockerStopScript)
|
|
302
|
-
|
|
303
|
-
const checkDockerImage = () => exec(dockerImageCheckScript)
|
|
304
|
-
|
|
305
|
-
const pullImage = async () => {
|
|
306
|
-
const { stdout } = await checkDockerImage()
|
|
307
|
-
const pulls = []
|
|
308
|
-
let resultPromise
|
|
309
|
-
|
|
310
|
-
output.print('Pulling in Selenoid containers. This may take a while when running the first time...')
|
|
311
|
-
|
|
312
|
-
console.time('Pulled containers')
|
|
313
|
-
if (!stdout.includes('selenoid/video-recorder')) {
|
|
314
|
-
output.debug('Pulling selenoid/video-recorder...')
|
|
315
|
-
resultPromise = exec('docker pull selenoid/video-recorder:latest-release').then(() =>
|
|
316
|
-
output.debug('Pulled in selenoid/video-recorder'),
|
|
317
|
-
)
|
|
318
|
-
pulls.push(resultPromise)
|
|
319
|
-
}
|
|
320
|
-
if (!stdout.includes('selenoid/chrome')) {
|
|
321
|
-
output.debug('Pulling selenoid/chrome...')
|
|
322
|
-
resultPromise = exec('docker pull selenoid/chrome:latest').then(() =>
|
|
323
|
-
output.debug('Pulled in selenoid/video-recorder'),
|
|
324
|
-
)
|
|
325
|
-
pulls.push(resultPromise)
|
|
326
|
-
}
|
|
327
|
-
if (!stdout.includes('selenoid/firefox')) {
|
|
328
|
-
output.debug('Pulling selenoid/firefox...')
|
|
329
|
-
resultPromise = exec('docker pull selenoid/firefox:latest').then(() => output.debug('Pulled in selenoid/chrome'))
|
|
330
|
-
pulls.push(resultPromise)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return Promise.all(pulls).then(() => {
|
|
334
|
-
console.timeEnd('Pulled containers')
|
|
335
|
-
})
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function createAndStart(autoCreate) {
|
|
339
|
-
const selenoidCreated = autoCreate ? createSelenoidConfig().then(createSelenoid).then(pullImage) : Promise.resolve()
|
|
340
|
-
return selenoidCreated.then(startSelenoid).then(() => wait(SELENOID_START_TIMEOUT))
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function deletePassedTests(passedTests) {
|
|
344
|
-
const deleteVideoPromiseList = passedTests
|
|
345
|
-
.map(clearString)
|
|
346
|
-
.map((test) => axios.delete(`${seleniumUrl}/video/${test}.mp4`))
|
|
347
|
-
const deleteLogPromiseList = passedTests
|
|
348
|
-
.map(clearString)
|
|
349
|
-
.map((test) => axios.delete(`${seleniumUrl}/logs/${test}.log`))
|
|
350
|
-
|
|
351
|
-
return Promise.all(deleteVideoPromiseList.concat(deleteLogPromiseList))
|
|
352
|
-
.then(() => output.debug('Deleted videos and logs for all passed tests'))
|
|
353
|
-
.catch((err) => output.error(`Error while deleting video and log files ${err.stack}`))
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function setOptionsForWebdriver(config) {
|
|
357
|
-
const WebDriver = container.helpers('WebDriver')
|
|
358
|
-
WebDriver._setConfig(
|
|
359
|
-
deepMerge(WebDriver.options, {
|
|
360
|
-
capabilities: { 'selenoid:options': config },
|
|
361
|
-
}),
|
|
362
|
-
)
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function setTestConfigForWebdriver(test) {
|
|
366
|
-
const WebDriver = container.helpers('WebDriver')
|
|
367
|
-
const fileName = clearString(test.title)
|
|
368
|
-
const { options } = WebDriver
|
|
369
|
-
recorder.add('setting selenoid capabilities', () => {
|
|
370
|
-
options.capabilities['selenoid:options'].name = test.title
|
|
371
|
-
options.capabilities['selenoid:options'].videoName = `${fileName}.mp4`
|
|
372
|
-
options.capabilities['selenoid:options'].logName = `${fileName}.log`
|
|
373
|
-
WebDriver._setConfig(options)
|
|
374
|
-
})
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function replaceScriptConfig(config) {
|
|
378
|
-
for (const key of Object.keys(config)) {
|
|
379
|
-
dockerCreateScript = dockerCreateScript.replace(new RegExp(`\\$${key}\\$`, 'g'), config[key])
|
|
380
|
-
}
|
|
381
|
-
dockerStartScript = dockerStartScript.replace('$name$', config.name)
|
|
382
|
-
dockerStopScript = dockerStopScript.replace('$name$', config.name)
|
|
383
|
-
seleniumUrl = seleniumUrl.replace('$port$', config.port)
|
|
384
|
-
}
|
package/lib/plugin/tryTo.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
const recorder = require('../recorder')
|
|
2
|
-
const { debug } = require('../output')
|
|
3
|
-
|
|
4
|
-
const defaultConfig = {
|
|
5
|
-
registerGlobal: true,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
|
|
12
|
-
*
|
|
13
|
-
* Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
|
|
14
|
-
*
|
|
15
|
-
* ```js
|
|
16
|
-
* plugins: {
|
|
17
|
-
* tryTo: {
|
|
18
|
-
* enabled: true
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
* Use it in your tests:
|
|
23
|
-
*
|
|
24
|
-
* ```js
|
|
25
|
-
* const result = await tryTo(() => I.see('Welcome'));
|
|
26
|
-
*
|
|
27
|
-
* // if text "Welcome" is on page, result => true
|
|
28
|
-
* // if text "Welcome" is not on page, result => false
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* Disables retryFailedStep plugin for steps inside a block;
|
|
32
|
-
*
|
|
33
|
-
* Use this plugin if:
|
|
34
|
-
*
|
|
35
|
-
* * you need to perform multiple assertions inside a test
|
|
36
|
-
* * there is A/B testing on a website you test
|
|
37
|
-
* * there is "Accept Cookie" banner which may surprisingly appear on a page.
|
|
38
|
-
*
|
|
39
|
-
* #### Usage
|
|
40
|
-
*
|
|
41
|
-
* #### Multiple Conditional Assertions
|
|
42
|
-
*
|
|
43
|
-
* ```js
|
|
44
|
-
*
|
|
45
|
-
* Add assert requires first:
|
|
46
|
-
* ```js
|
|
47
|
-
* const assert = require('assert');
|
|
48
|
-
* ```
|
|
49
|
-
* Then use the assertion:
|
|
50
|
-
* const result1 = await tryTo(() => I.see('Hello, user'));
|
|
51
|
-
* const result2 = await tryTo(() => I.seeElement('.welcome'));
|
|
52
|
-
* assert.ok(result1 && result2, 'Assertions were not succesful');
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* ##### Optional click
|
|
56
|
-
*
|
|
57
|
-
* ```js
|
|
58
|
-
* I.amOnPage('/');
|
|
59
|
-
* tryTo(() => I.click('Agree', '.cookies'));
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* #### Configuration
|
|
63
|
-
*
|
|
64
|
-
* * `registerGlobal` - to register `tryTo` function globally, true by default
|
|
65
|
-
*
|
|
66
|
-
* If `registerGlobal` is false you can use tryTo from the plugin:
|
|
67
|
-
*
|
|
68
|
-
* ```js
|
|
69
|
-
* const tryTo = codeceptjs.container.plugins('tryTo');
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
*/
|
|
73
|
-
module.exports = function (config) {
|
|
74
|
-
config = Object.assign(defaultConfig, config)
|
|
75
|
-
|
|
76
|
-
if (config.registerGlobal) {
|
|
77
|
-
global.tryTo = tryTo
|
|
78
|
-
}
|
|
79
|
-
return tryTo
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function tryTo(callback) {
|
|
83
|
-
let result = false
|
|
84
|
-
return recorder.add(
|
|
85
|
-
'tryTo',
|
|
86
|
-
() => {
|
|
87
|
-
recorder.session.start('tryTo')
|
|
88
|
-
process.env.TRY_TO = 'true'
|
|
89
|
-
callback()
|
|
90
|
-
recorder.add(() => {
|
|
91
|
-
result = true
|
|
92
|
-
recorder.session.restore('tryTo')
|
|
93
|
-
return result
|
|
94
|
-
})
|
|
95
|
-
recorder.session.catch((err) => {
|
|
96
|
-
result = false
|
|
97
|
-
const msg = err.inspect ? err.inspect() : err.toString()
|
|
98
|
-
debug(`Unsuccessful try > ${msg}`)
|
|
99
|
-
recorder.session.restore('tryTo')
|
|
100
|
-
return result
|
|
101
|
-
})
|
|
102
|
-
return recorder.add(
|
|
103
|
-
'result',
|
|
104
|
-
() => {
|
|
105
|
-
process.env.TRY_TO = undefined
|
|
106
|
-
return result
|
|
107
|
-
},
|
|
108
|
-
true,
|
|
109
|
-
false,
|
|
110
|
-
)
|
|
111
|
-
},
|
|
112
|
-
false,
|
|
113
|
-
false,
|
|
114
|
-
)
|
|
115
|
-
}
|