codeceptjs / codeceptjs/CodeceptJS

Event listener event.dispatcher.on(event.test.failed) doesn't work with Before and Background sections

オープン
#2,962 コメント 0 件 リアクション 3 件 担当者 0 名 GitHub で見る
bug
主要言語
JavaScript
スター
4.2k
フォーク
757
平均マージ
2日 9時間
マージ済み PR(30日)
16

説明

#### What are you trying to achieve?
The goal - to create custom hook with event listener to perform retry of scenarios in case of getting failed tests due to certain network issues.

Custom hook has the following code:

`const event = require('codeceptjs').event;

module.exports = function () {

event.dispatcher.on(event.test.failed, function (test, err) {

switch (true) {
case err.message.includes(`browserContext.addCookies: Browser has been closed`):
case err.message.includes(`Cannot read property 'addCookies' of undefined`):
case err.message.includes(`Cannot read property 'waitForSelector' of null`):
case err.message.includes(`Cannot read property 'waitForSelector' of undefined`):
case err.message.includes(`Cannot read property 'goto' of undefined`):
case err.message.includes(`Cannot read property 'goto' of null`):
case err.message.includes(`page.goto: net::ERR_NETWORK_CHANGED`):
case err.message.includes(`page.goto: net::ERR_NAME_NOT_RESOLVED`):
case err.message.includes(`page.goto: net::ERR_TIMED_OUT`):
test._retries = 5;
break;
default:
return;
}

});

}`

#### What do you get instead?
It works when the scenarios are written without Before or Background section (for BDD tests), but since our test failure occurs in Before and Background sections (above issues usually happen exactly there), custom hook/event listener won't work.

Obviously, that in this case we have to duplicate a lot of steps in our project

### Details

* CodeceptJS version: 3.0.7
* NodeJS Version: 14.15.1
* Operating System: Mac OS, Linux
* playwright: 1.12.0

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。