Skip to content Skip to sidebar Skip to footer

Is There A Configuration In Cucumberjs To Take Screenshot On Error?

using CucumberJS Is there an option or configuration to capture screenshot on error after the execution of test?

Solution 1:

You can take screenshot through cucumber After hook as following:

// supports/take-screenshot.jsvar { 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");
        });
    }
});

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"
    ]
 }

Post a Comment for "Is There A Configuration In Cucumberjs To Take Screenshot On Error?"