本文介绍了CucumberJS 中是否有配置可以对错误进行截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 CucumberJS是否有选项或配置在执行测试后捕获错误屏幕截图?
using CucumberJSIs there an option or configuration to capture screenshot on error after the execution of test?
推荐答案
可以通过cucumber的After
钩子截图如下:
You can take screenshot through cucumber After
hook as following:
// supports/take-screenshot.js
var { After, Status } = require("cucumber");
After(function(testCase) {
var me = this;
if (testCase.result.status === Status.FAILED) {
return browser.takeScreenshot().then(function(screenshot) {
return me.attach(screenshot, "image/png");
});
}
});
然后将上述钩子文件包含到量角器 conf.js 中的 cucumberOpts.requires
中,如下所示:
Then include above hook file into cucumberOpts.requires
in protractor conf.js as below:
// cucumberOpts in protractor conf.js
cucumberOpts: {
require: [
"supports/cucumber-screenshot.js",
"steps/**/*step.js"
]
}
这篇关于CucumberJS 中是否有配置可以对错误进行截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!