CucumberJS中是否有配置可以对错误进行截图?

时间:2019-01-25 07:09:38

标签: javascript protractor cucumberjs

使用CucumberJS 执行测试后,是否有选项或配置可以捕获有关错误的屏幕截图?

1 个答案:

答案 0 :(得分:1)

您可以通过黄瓜After钩进行截图,如下所示:

// 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中,如下所示:

// cucumberOpts in protractor conf.js
cucumberOpts: {

    require: [
       "supports/cucumber-screenshot.js", 
       "steps/**/*step.js"
    ]
 }