The function for taking screenshots for cucumber-html-reporter generates the error "timeout after 5000 .."

I am using protractor-cucumber-framework and I wanted to create an html report for the tests I wrote. I decided to use the cucumber-html reporter to achieve this. In my hooks.js, I wrote this.After object to take a screenshot of a testing error:

   this.After(function(scenario, callback) {
     if (scenario.isFailed()) {
        browser.takeScreenshot().then(function(buffer) {
            return scenario.attach(new Buffer(buffer, 'base64'), function(err) {
                callback(err);
            });
        });
     }
     else {
        callback();
     }
   });

Everything works very well, a report is created and screenshots are taken and attached only with a testing error. But I also got an error message when after the step continues (therefore, when there are some glitches):

function expires in 5000 milliseconds

I would like to get rid of this post as it also appears in my html report. Can someone provide me a solution for this?

+4
3

. js . .

defineSupportCode(({After}) => {
    After(function(scenario) {
        if (scenario.isFailed()) {
            var attach = this.attach; 
                return browser.takeScreenshot().then(function(png) {
            var decodedImage = new Buffer(png, "base64");
                return attach(decodedImage, "image/png");
            });
            }
        });
    });
+1

. , ?

- :

this.After({ timeout: 20 * 1000 }, function (scenario, callback) {
  if (scenario.isFailed()) {
    browser.takeScreenshot().then(function(buffer) {
        return scenario.attach(new Buffer(buffer, 'base64'), function(err) {
            callback(err);
        });
    });
  }
  else {
    callback();
  }
});
0

, 60 . , .

The following code worked for me. (I am new to JavaScript and therefore my callback call may be the right way. Please feel free to train me if there is a better way to do this.))

After(function(scenario,done)
{
    const world = this;
    if (scenario.result.status === 'failed') {
        browser.takeScreenshot().then(function (stream) {
            let decodedImage = new Buffer(stream.replace(/^data:image\/(png|gif|jpeg);base64,/, ''), 'base64');
            world.attach(decodedImage, 'image/png');
        }).then(function () {
            done();
        });
    }else {
        done();
    }
});
0
source

Source: https://habr.com/ru/post/1659823/


All Articles