如何将屏幕截图附加到量角器的 HTML 报告?
How to attach screenshot to protractor's HTML report?
在我的 protractor
项目中,我正在尝试截取屏幕截图,并将其附加到我的 html
报告中。截图的过程发生在After
hook中,如下:
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",
问题已解决,将 fat 功能更改为普通功能。我仍然不明白为什么它会影响我的代码,但现在运行良好,并且我的 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");
}
});
尝试以下适合我的代码:
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');
});
}
});
在我的 protractor
项目中,我正在尝试截取屏幕截图,并将其附加到我的 html
报告中。截图的过程发生在After
hook中,如下:
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",
问题已解决,将 fat 功能更改为普通功能。我仍然不明白为什么它会影响我的代码,但现在运行良好,并且我的 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");
}
});
尝试以下适合我的代码:
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');
});
}
});