如何将截图附加到量角器的HTML报告?

问题描述 投票:0回答:2

在我的protractor项目中,我试图截取屏幕截图,并将其附加到我的html报告中。截屏的过程发生在After钩子中,如下所示:

import {  Status,After, HookScenarioResult} from 'cucumber';
import {browser} from 'protractor';
import { async } from 'q';

After(async  (scenario:HookScenarioResult)=> {

    if(scenario.result.status===Status.FAILED){
        const screenshot = await browser.takeScreenshot();
        this.attach(screenshot,"image/png");
    }
});

但在this.attach(screenshot,"image/png");线上,它抱怨:

TypeError: this.attach is not a function

问题是什么?

我的配置是:

   "cucumber": "^5.1.0",
    "cucumber-html-reporter": "^4.0.4",
    "protractor": "^5.4.2",
    "protractor-cucumber-framework": "^6.1.1",
automation protractor reporting
2个回答
0
投票

通过将脂肪功能改为正常功能,问题得以解决。我仍然,不明白为什么它会影响我的代码,但现在运行良好,我的html报告上有截图。

After(async function(scenario) {
    if (scenario.result.status === Status.FAILED) {
        // screenShot is a base-64 encoded PNG
            const screenShot = await browser.takeScreenshot();
            this.attach(screenShot, "image/png");
    }
});

0
投票

尝试以下代码为我工作:

  After(function(scenarioResult) {
    let self = this;
    if (scenarioResult.result.status === Status.FAILED) {
    return browser.takeScreenshot()
    .then(function (screenshot) {
        const decodedImage = new Buffer(screenshot.replace(/^data:image\/png;base64,/, ''), 'base64');
        self.attach(decodedImage, 'image/png');
    });
}
});
© www.soinside.com 2019 - 2024. All rights reserved.