Automation 如何将屏幕截图附加到量角器';什么是HTML报告?
在我的Automation 如何将屏幕截图附加到量角器';什么是HTML报告?,automation,protractor,reporting,Automation,Protractor,Reporting,在我的量角器项目中,我试图截图,并将其附加到我的html报告中。截图过程发生在钩子后的,如下所示: import { Status,After, HookScenarioResult} from 'cucumber'; import {browser} from 'protractor'; import { async } from 'q'; After(async (scenario:HookScenarioResult)=> { if(scenario.result.s
量角器
项目中,我试图截图,并将其附加到我的html
报告中。截图过程发生在钩子后的,如下所示:
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(截图,“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",
通过将脂肪功能更改为正常功能,问题得以解决。我仍然不明白它为什么会影响我的代码,但现在工作得很好,我的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");
}
});
通过将脂肪功能更改为正常功能,问题得以解决。我仍然不明白它为什么会影响我的代码,但现在工作得很好,我的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');
});
}
});
请尝试以下适合我的代码:
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');
});
}
});
此问题
。此外,您还应删除异步的导入。此问题
。此外,您还应该删除异步导入。您好,您的代码适合我。但图像未加载到报告中。。它显示出破损的样子。。你们有什么想法吗?嗨,你们的代码对我来说很有用。但图像并没有被载入到报告中。。它显示出破损的样子。。你有什么想法吗?