cucumber - 当步骤失败时,如何将屏幕截图附加到柏树中的黄瓜报告?
解决方案
看起来您正在使用 cypress-cucumber-preprocessor
我正在考虑使用钩子来执行此操作,但据我所知,您也无权访问场景对象(如在 cucumber.js 中)以附加屏幕截图。
但是我确实找到了这个脚本https://github.com/jcundill/cypress-cucumber-preprocessor/blob/master/fixJson.js它将通过并将赛普拉斯拍摄的屏幕截图(和视频)附加/嵌入到cypress-cucumber-preprocessor 生成的 cucumber.json 文件
然后,当您生成报告时,您将看到失败测试的屏幕截图和视频
请注意,我不得不稍微摆弄一下才能让它为我工作
首先,从屏幕截图中确定场景名称的正则表达式确实对我有用,我用一个函数替换了它
function getScenarioNameFromScreenshot(screenshot) {
const index1 = screenshot.indexOf('--');
let index2;
if (screenshot.indexOf('(example') === -1) {
// Normal end index of scenario in screenshot filename
index2 = screenshot.indexOf('(failed)');
} else {
// End index of scenario if its from a failed BDD example
index2 = screenshot.indexOf('(example');
}
return screenshot
.substring(index1 + 2, index2)
.trim();
}
其次,我必须在 cucumber.json 中创建 .embeddings 数组(否则当你尝试推送它时它会失败,如果它不存在,它不适合我)
myStep.embeddings = [];
前
myStep.embeddings.push({ data: base64Image, mime_type: "image/png" });
虽然,看着它,最好先检查它的存在,并在需要时创建它,但是嘿它对我有用
但除此之外,它就像一个魅力
推荐阅读
- html - 固定背景和可滚动的文本滑块
- javascript - 如何在调用 .html() 替换内容后重新初始化我的 jQuery 调用
- c - 如何在带有指针的函数中传递多个参数?
- java - AsyncTask 替代背景图像下载?(AsyncTask ---------已弃用)
- python - Python3、Pygame Sprite.Group 更新方法参数不同
- azure-data-explorer - 在 Azure 数据资源管理器中计算具有每周条目的表中 X 周的平均值 - 除了自联接之外的任何选项?
- java - 2048 kb 的光标窗口分配失败经常出现
- css - 尝试运行 create-react-app build 时出现非描述性 CSS 解析错误
- rust - 对于单链表,这两个 drop 实现之间是否有任何区别
- javascript - for-if 嵌套在 for-if 中