我在TypeScript中有一些(实际上很多)量角器测试,我需要在失败的情况下截屏 - 从expect
或超时 - 我想在我的Allure Report上使用图像。
我最初尝试了Protractor 的常见问题解答中提出的解决方案,创建自定义报告或在其中截取屏幕截图,jasmine. getEnv().afterAll
但没有奏效 - 图像附加到错误的规范。
所以我试图覆盖jasmine.Spec.prototype.addExpectationResult
,但我收到错误:“类型'typeof jasmine'.ts(2339)上不存在属性'Spec'”。
我使用了一种解决方法来完成这项工作(并且它确实有效),如下所示:
const jasmine2 = jasmine as any; // <--- HERE !!!
const addExpectationResult = jasmine2.Spec.prototype.addExpectationResult;
jasmine2.Spec.prototype.addExpectationResult = function() {
if (!arguments[0]) {
// Takes screenshot
allure.createAttachment('screenshot', Buffer.from(base64, 'base64'), 'image/png');
}
return addExpectationResult.apply(this, arguments);
};
但是有什么方法可以在TypeScriptaddExpectationResult
中以“更好”的方式覆盖?
我的package.json
文件中有以下内容@types
:
"devDependencies": {
"@types/jasmine": "^3.4.4",
"@types/jasminewd2": "^2.0.8"
}
提前致谢。