【问题标题】:Is there a configuration in CucumberJS to take screenshot on Error?CucumberJS 中是否有配置来截取错误截图?
【发布时间】:2019-01-25 07:09:37
【问题描述】:

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

【问题讨论】:

标签: javascript protractor cucumberjs


【解决方案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"
    ]
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    • 2011-02-19
    • 1970-01-01
    • 2018-02-13
    相关资源
    最近更新 更多