1

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

Ry-ry
  • 210
  • 1
  • 4
  • 15
  • Possible duplicate of [function to take screenshots for cucumber-html-reporter generates "function timed out after 5000.." error](https://stackoverflow.com/questions/40423453/function-to-take-screenshots-for-cucumber-html-reporter-generates-function-time) – Infern0 Jan 25 '19 at 11:08

1 Answers1

5

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");
        });
    }
});

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"
    ]
 }
yong
  • 13,357
  • 1
  • 16
  • 27