在我的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",
答案 0 :(得分: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");
}
});
答案 1 :(得分: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');
});
}
});