函数获取屏幕快照以获取cumul-html-reporter生成“函数在5000之后超时”。错误 [英] function to take screenshots for cucumber-html-reporter generates "function timed out after 5000.." error

查看:80
本文介绍了函数获取屏幕快照以获取cumul-html-reporter生成“函数在5000之后超时”。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用量角器-黄瓜框架,我想为我编写的测试生成html报告。我决定使用Cucumber-html-reporter来实现它。在我的hooks.js中,我编写了this.After对象以对测试失败进行截图:

I am using protractor-cucumber-framework and I wanted to generate html report for the tests I wrote. I decided to use cucumber-html-reporter to achieve it. In my hooks.js I wrote a this.After object to take screenshot on test failure:

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

一切正常,仅在测试失败时才生成报告并截图并附加。但是,在执行After步骤(因此出现某些故障)时,我也收到一条错误消息:

Everything works just fine, the report is generated and the screenshots are taken and attached only on test failure. But I also got an error message when After step is proceeded (so when there is some failure):


函数在5000毫秒后超时

function timed out after 5000 milliseconds

我想摆脱此消息,因为它也出现在我的html报告中。有人可以为我提供解决方案吗?

I would like to get rid of this message as it also appears on my html report. Can anyone provide me solution to do that?

推荐答案

以下代码对我有用。我已经在步骤定义js文件中添加了它。在报告的方案末尾,它将添加屏幕截图。

Below code is working for me. I have added this in step definition js file. At the end of scenario in the report, it adds the screenshot.

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

这篇关于函数获取屏幕快照以获取cumul-html-reporter生成“函数在5000之后超时”。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆