为 cucumber-html-reporter 截屏的函数生成“函数在 5000 之后超时.."错误 [英] function to take screenshots for cucumber-html-reporter generates "function timed out after 5000.." error

查看:9
本文介绍了为 cucumber-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 step 时我也收到了一条错误消息(所以当有一些失败时):

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

这篇关于为 cucumber-html-reporter 截屏的函数生成“函数在 5000 之后超时.."错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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