Bug Report: stepByStepReport not capturing screenshots in CodeceptJS 3.6+
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, playwright
- 领域
- testing
调研方向
从 lib/plugin/stepByStepReport.js 开始,在 3.7.5 版本上使用提供的最小 CodeceptJS 配置重现该问题。检查 event.step.after 处理程序和 recorder 的使用情况,然后验证失败的测试是否会在普通运行和并行运行中都在 output/record*/ 生成预期的 PNG 屏幕截图。
由索引模型根据 Issue 内容生成。
描述
Hello,
The stepByStepReport plugin does not capture screenshots after each step in CodeceptJS versions 3.6.0 through 3.7.5. The record_*/ directory is created but only contains an empty index.html file with no screenshots (PNG files).
Affected Versions
- Broken: CodeceptJS 3.6.0, 3.6.1, 3.6.2, 3.6.3, 3.6.4, 3.7.0, 3.7.1, 3.7.2, 3.7.3, 3.7.4, 3.7.5
- Working: CodeceptJS 3.5.0 and earlier
Root Cause
The bug was introduced in commit 1040494 (Jun 8, 2024) titled "fix: screenshot error in beforeSuite/AfterSuite (#4385)".
The Change
In lib/plugin/stepByStepReport.js, the event.step.after handler was changed:
Before (working - v3.5.0):
event.dispatcher.on(event.step.after, (step) => {
recorder.add('screenshot of failed test', async () => persistStep(step), true);
});
After (broken - v3.6+):
event.dispatcher.on(event.step.after, persistStep);
Why This Breaks
The persistStep function is an async function that calls helper.saveScreenshot(). In the original implementation, this was wrapped in recorder.add(), which properly queues the async operation and waits for completion.
In the new implementation, persistStep is called directly as an event handler callback. Since it's an async function, the event dispatcher doesn't wait for it to complete. The screenshots are never captured because:
- The async function starts executing
- The event dispatcher immediately moves on to the next event
- The screenshot operation may be cancelled or never completes
Reproduction Steps
- Create a minimal CodeceptJS config with only
stepByStepReportenabled - Run any test that fails (to keep the report)
- Check the
_output/record_*/directory - The directory contains only
index.htmlwith no PNG files
Minimal Reproduction
// codecept.minimal.conf.js
const path = require('path');
exports.config = {
output: path.resolve(__dirname, '_output'),
helpers: {
Playwright: {
browser: 'chromium',
url: 'https://www.google.com',
show: true
}
},
plugins: {
stepByStepReport: {
enabled: true
}
},
tests: './test_minimal.js',
name: 'minimal-test'
};
// test_minimal.js
Feature('Minimal Test');
Scenario('Test stepByStepReport', ({ I }) => {
I.amOnPage('https://www.google.com');
I.wait(2);
I.see('Google');
I.see('TEXT THAT DOES NOT EXIST'); // Force failure to keep report
});
Run with:
npx codeceptjs@3.7.5 run --config codecept.minimal.conf.js
Expected: _output/record_*/ contains 0000.png, 0001.png, etc.
Actual: _output/record_*/ contains only index.html with no PNGs
Suggested Fix
Restore the original behavior by wrapping persistStep in recorder.add():
event.dispatcher.on(event.step.after, step => {
recorder.add('screenshot of step of test', async () => persistStep(step), true);
});
This ensures the async screenshot operation is properly queued and executed.
Additional Context
- This issue has been reported before as #4856 (Feb 2025) and is a follow-up of #4637
- The original fix was intended to prevent errors in BeforeSuite/AfterSuite hooks, but it inadvertently broke the core screenshot functionality
- The issue affects both single-run and parallel execution modes
Environment
- CodeceptJS: 3.7.5
- Node.js: 20.x
- Playwright: 1.57.0
- OS: Linux (Ubuntu 22.04)
Written with help from Claude 4.5 Opus.
- 主要语言
- JavaScript
- 星标
- 4.2k
- 派生
- 756
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 16
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
codeceptjs/CodeceptJS 的其他 Issue
-
stale
难度 2/5 1-3 小时 新手友好度 72/100
codeceptjs/CodeceptJS#5420 · 1 条评论 ·
-
stale
难度 2/5 1-3 小时 新手友好度 76/100
codeceptjs/CodeceptJS#5358 · 1 条评论 ·
-
stale
难度 2/5 1-3 小时 新手友好度 78/100
codeceptjs/CodeceptJS#4958 · 10 条评论 · 2 个 reaction ·
-
stale
难度 1/5 1 小时以内 新手友好度 72/100
codeceptjs/CodeceptJS#4778 · 3 条评论 ·
-
stale
难度 4/5 3-5 天 新手友好度 38/100
codeceptjs/CodeceptJS#5618 · 1 条评论 ·
查看 codeceptjs/CodeceptJS 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
avniproject/avni-client#2135 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
babalae/bettergi-scripts-list#3674 ·
-
A-Release-Notes C-Editing D-Modest S-Ready-For-Implementation
难度 2/5 1-3 小时 新手友好度 72/100
bevyengine/bevy-website#2595 ·
-
ecosystem wording
难度 1/5 1 小时以内 新手友好度 90/100
matrix-org/matrix.org#3649 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
vadimdemedes/ink#1029 ·