Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#2,962 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, node.js, playwright
Domain
testing

Research direction

Start at the event.dispatcher.on(event.test.failed) hook and trace how failures from BDD Before and Background sections are dispatched. Reproduce the behavior with a failing setup step, then verify that the listener receives the failure and can set test._retries for those scenarios.

Written by the indexing model from the issue text.

Description

bug
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
Dominant language
JavaScript
Stars
4.2k
Forks
756
Avg merge
2d 9h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from codeceptjs/CodeceptJS

All issues in codeceptjs/CodeceptJS

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.