Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#2,962 0 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, node.js, playwright
领域
testing

调研方向

从 event.dispatcher.on(event.test.failed) hook 开始,跟踪 BDD Before 和 Background 部分的失败是如何被分发的。使用一个失败的设置步骤重现该行为,然后验证 listener 能够接收到失败,并能为这些场景设置 test._retries。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
JavaScript
星标
4.2k
派生
756
平均合并
2 天 9 小时
30 天内合并 PR
16

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codeceptjs/CodeceptJS 的其他 Issue

查看 codeceptjs/CodeceptJS 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。