Skip to content

Commit 82075c8

Browse files
author
DavertMik
committed
fixed def & failing tests
1 parent e583cda commit 82075c8

File tree

16 files changed

+200
-222
lines changed

16 files changed

+200
-222
lines changed

docs/plugins.md

Lines changed: 35 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ title: Plugins
77

88
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
99

10+
## analyze
11+
12+
### Parameters
13+
14+
- `config` **any** (optional, default `{}`)
15+
1016
## autoDelay
1117

1218
Sometimes it takes some time for a page to respond to user's actions.
@@ -521,29 +527,13 @@ I.click('=sign-up') // matches => [data-qa=sign-up],[data-test=sign-up]
521527
522528
- `config` &#x20;
523529
524-
## debugErrors
525-
526-
Prints errors found in HTML code after each failed test.
527-
528-
It scans HTML and searches for elements with error classes.
529-
If an element found prints a text from it to console and adds as artifact to the test.
530-
531-
Enable this plugin in config:
532-
533-
```js
534-
plugins: {
535-
debugErrors: {
536-
enabled: true,
537-
}
538-
```
539-
540-
Additional config options:
530+
## customReporter
541531
542-
- `errorClasses` - list of classes to search for errors (default: `['error', 'warning', 'alert', 'danger']`)
532+
Sample custom reporter for CodeceptJS.
543533
544534
### Parameters
545535
546-
- `config` (optional, default `{}`)
536+
- `config` &#x20;
547537
548538
## eachElement
549539
@@ -672,6 +662,32 @@ More config options are available:
672662
673663
- `config` (optional, default `{}`)
674664
665+
## pageInfo
666+
667+
Collects information from web page after each failed test and adds it to the test as an artifact.
668+
It is suggested to enable this plugin if you run tests on CI and you need to debug failed tests.
669+
This plugin can be paired with `analyze` plugin to provide more context.
670+
671+
It collects URL, HTML errors (by classes), and browser logs.
672+
673+
Enable this plugin in config:
674+
675+
```js
676+
plugins: {
677+
pageInfo: {
678+
enabled: true,
679+
}
680+
```
681+
682+
Additional config options:
683+
684+
- `errorClasses` - list of classes to search for errors (default: `['error', 'warning', 'alert', 'danger']`)
685+
- `browserLogs` - list of types of errors to search for in browser logs (default: `['error']`)
686+
687+
### Parameters
688+
689+
- `config` (optional, default `{}`)
690+
675691
## pauseOnFail
676692
677693
Automatically launches [interactive pause][11] when a test fails.
@@ -757,79 +773,6 @@ Scenario('scenario tite', () => {
757773
758774
- `config` &#x20;
759775
760-
## retryTo
761-
762-
Adds global `retryTo` which retries steps a few times before failing.
763-
764-
Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
765-
766-
```js
767-
plugins: {
768-
retryTo: {
769-
enabled: true
770-
}
771-
}
772-
```
773-
774-
Use it in your tests:
775-
776-
```js
777-
// retry these steps 5 times before failing
778-
await retryTo(tryNum => {
779-
I.switchTo('#editor frame')
780-
I.click('Open')
781-
I.see('Opened')
782-
}, 5)
783-
```
784-
785-
Set polling interval as 3rd argument (200ms by default):
786-
787-
```js
788-
// retry these steps 5 times before failing
789-
await retryTo(
790-
tryNum => {
791-
I.switchTo('#editor frame')
792-
I.click('Open')
793-
I.see('Opened')
794-
},
795-
5,
796-
100,
797-
)
798-
```
799-
800-
Default polling interval can be changed in a config:
801-
802-
```js
803-
plugins: {
804-
retryTo: {
805-
enabled: true,
806-
pollInterval: 500,
807-
}
808-
}
809-
```
810-
811-
Disables retryFailedStep plugin for steps inside a block;
812-
813-
Use this plugin if:
814-
815-
- you need repeat a set of actions in flaky tests
816-
- iframe was not rendered and you need to retry switching to it
817-
818-
#### Configuration
819-
820-
- `pollInterval` - default interval between retries in ms. 200 by default.
821-
- `registerGlobal` - to register `retryTo` function globally, true by default
822-
823-
If `registerGlobal` is false you can use retryTo from the plugin:
824-
825-
```js
826-
const retryTo = codeceptjs.container.plugins('retryTo')
827-
```
828-
829-
### Parameters
830-
831-
- `config` &#x20;
832-
833776
## screenshotOnFail
834777
835778
Creates screenshot on failure. Screenshot is saved into `output` directory.
@@ -1083,76 +1026,6 @@ plugins: {
10831026
}
10841027
```
10851028
1086-
## tryTo
1087-
1088-
Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
1089-
1090-
Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
1091-
1092-
```js
1093-
plugins: {
1094-
tryTo: {
1095-
enabled: true
1096-
}
1097-
}
1098-
```
1099-
1100-
Use it in your tests:
1101-
1102-
```js
1103-
const result = await tryTo(() => I.see('Welcome'))
1104-
1105-
// if text "Welcome" is on page, result => true
1106-
// if text "Welcome" is not on page, result => false
1107-
```
1108-
1109-
Disables retryFailedStep plugin for steps inside a block;
1110-
1111-
Use this plugin if:
1112-
1113-
- you need to perform multiple assertions inside a test
1114-
- there is A/B testing on a website you test
1115-
- there is "Accept Cookie" banner which may surprisingly appear on a page.
1116-
1117-
#### Usage
1118-
1119-
#### Multiple Conditional Assertions
1120-
1121-
````js
1122-
1123-
Add assert requires first:
1124-
```js
1125-
const assert = require('assert');
1126-
````
1127-
1128-
Then use the assertion:
1129-
const result1 = await tryTo(() => I.see('Hello, user'));
1130-
const result2 = await tryTo(() => I.seeElement('.welcome'));
1131-
assert.ok(result1 && result2, 'Assertions were not succesful');
1132-
1133-
````
1134-
1135-
##### Optional click
1136-
1137-
```js
1138-
I.amOnPage('/');
1139-
tryTo(() => I.click('Agree', '.cookies'));
1140-
````
1141-
1142-
#### Configuration
1143-
1144-
- `registerGlobal` - to register `tryTo` function globally, true by default
1145-
1146-
If `registerGlobal` is false you can use tryTo from the plugin:
1147-
1148-
```js
1149-
const tryTo = codeceptjs.container.plugins('tryTo')
1150-
```
1151-
1152-
### Parameters
1153-
1154-
- `config` &#x20;
1155-
11561029
## wdio
11571030
11581031
Webdriverio services runner.

lib/codecept.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const event = require('./event')
99
const runHook = require('./hooks')
1010
const output = require('./output')
1111
const { emptyFolder } = require('./utils')
12-
const Result = require('./result')
1312

1413
/**
1514
* CodeceptJS runner
@@ -201,7 +200,7 @@ class Codecept {
201200
}
202201
const done = () => {
203202
event.emit(event.all.result, container.result())
204-
event.emit(event.all.after, container.result())
203+
event.emit(event.all.after)
205204
resolve()
206205
}
207206

lib/command/check.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = async function (options) {
2222
config: false,
2323
container: false,
2424
pageObjects: false,
25+
plugins: false,
2526
helpers: false,
2627
setup: false,
2728
tests: false,
@@ -115,6 +116,9 @@ module.exports = async function (options) {
115116
}
116117
printCheck('page objects', checks['pageObjects'], `Total: ${Object.keys(pageObjects).length} support objects`)
117118

119+
checks.plugins = true // how to check plugins?
120+
printCheck('plugins', checks['plugins'], Object.keys(container.plugins()).join(', '))
121+
118122
if (Object.keys(helpers).length) {
119123
const suite = container.mocha().suite
120124
const test = createTest('test', () => {})

lib/listener/globalTimeout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ module.exports = function () {
133133
debug(`Failing test ${currentTest.title} with timeout ${currentTimeout}s`)
134134
recorder.reset()
135135
// replace mocha timeout with custom timeout
136-
currentTest.timeout(0)
136+
// currentTest.timeout(0.1)
137137
currentTest.callback(new Error(`Timeout ${currentTimeout}s exceeded (with Before hook)`))
138138
currentTest.timedOut = true
139139
}

lib/listener/steps.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ let currentHook
1313
module.exports = function () {
1414
event.dispatcher.on(event.test.before, test => {
1515
test.startedAt = +new Date()
16-
test.artifacts = {}
1716
})
1817

1918
event.dispatcher.on(event.test.started, test => {

lib/listener/store.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ const event = require('../event')
22
const store = require('../store')
33

44
module.exports = function () {
5-
event.dispatcher.on(event.all.before, result => {
6-
store.result = result
7-
})
8-
95
event.dispatcher.on(event.test.before, test => {
106
store.currentTest = test
117
})

lib/mocha/cli.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ class Cli extends Base {
155155

156156
result() {
157157
const container = require('../container')
158-
const stats = this.stats
159-
container.result().addStats(stats)
158+
container.result().addStats(this.stats)
160159
container.result().finish()
160+
161+
const stats = container.result().stats
161162
console.log()
162163

163164
// passes
@@ -181,8 +182,15 @@ class Cli extends Base {
181182
err.message = err.inspect()
182183
}
183184

184-
// multi-line error messages
185-
err.message = '\n ' + (err.message || '').replace(/^/gm, ' ').trim()
185+
// multi-line error messages (for Playwright)
186+
if (err.message && err.message.includes('\n')) {
187+
const lines = err.message.split('\n')
188+
const truncatedLines = lines.slice(0, 5)
189+
if (lines.length > 5) {
190+
truncatedLines.push('...')
191+
}
192+
err.message = '\n ' + truncatedLines.join('\n').replace(/^/gm, ' ').trim()
193+
}
186194

187195
const steps = test.steps || (test.ctx && test.ctx.test.steps)
188196

@@ -249,7 +257,7 @@ class Cli extends Base {
249257

250258
container.result().addFailures(failuresLog)
251259

252-
output.result(stats.passes, stats.failures, stats.pending, ms(stats.duration))
260+
output.result(stats.passes, stats.failures, stats.pending, ms(stats.duration), stats.failedHooks)
253261

254262
if (stats.failures && output.level() < 3) {
255263
output.print(output.styles.debug('Run with --verbose flag to see complete NodeJS stacktrace'))

lib/mocha/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function deserializeTest(test) {
7171
createTest(test.title || '', () => {}),
7272
test,
7373
)
74-
test.parent = Object.assign(new Suite(test.parent.title), test.parent)
74+
test.parent = Object.assign(new Suite(test.parent?.title || 'Suite'), test.parent)
7575
enhanceMochaSuite(test.parent)
7676
test.steps = test.steps.map(step => Object.assign(new Step(step.title), step))
7777
return test

0 commit comments

Comments
 (0)