Protractor allure.createAttachment异常错误-无法读取未定义的属性“currentStep”

Protractor allure.createAttachment异常错误-无法读取未定义的属性“currentStep”,protractor,mocha.js,allure,Protractor,Mocha.js,Allure,我可以成功地将屏幕截图添加到诱惑报告中,但出现以下异常错误: 错误: TypeError: Cannot read property 'currentStep' of undefined at Allure.addAttachment (/Users//xxx/xxx/xxx/node_modules/allure-js-commons/index.js:86:45) at Allure.createAttachment (/Users/xxx/xxx/xxx/node_modu

我可以成功地将屏幕截图添加到诱惑报告中,但出现以下异常错误:

错误:

TypeError: Cannot read property 'currentStep' of undefined
    at Allure.addAttachment (/Users//xxx/xxx/xxx/node_modules/allure-js-commons/index.js:86:45)
    at Allure.createAttachment (/Users/xxx/xxx/xxx/node_modules/allure-js-commons/runtime.js:48:29)
    at /Users/xxx/xxx/xxx/lib/class/class-name.js:30:20
    at process._tickCallback (internal/process/next_tick.js:68:7)
类别:

 browser.takeScreenshot().then(function (png) {
            allure.createAttachment(title, new Buffer(png, 'base64'));
        }).catch((error: any) => console.log(error));
allure是一个全局标识符,由reporter注入到您的代码中

在文件顶部添加以下行以告知Typescript

declare const allure: any;

我认为createAttachment需要回调函数,而不是直接传递缓冲区

您能否尝试更改代码以反映以下内容

browser.takeScreenshot().then(function (png) {
    allure.createAttachment('Screenshot', function () {
        return new Buffer(png, 'base64')
    }, 'image/png')()
}).catch((error: any) => console.log(error));

您得到的是错误还是唯一的异常?。您是否在项目中使用currentStep?只是个例外。我似乎通过添加一个try,catch来解决这个问题。这是正确的方法吗?尝试{await browser.takeScreenshot.thenfunction png{allure.createAttachmenttitle,new Bufferpng'base64';};}捕获e{console.log'Error catched';}并且我不使用currentStep,是否来自createAttachment?@user我猜您的脚本仍在打印您发布的评论中代码捕获的错误?您的try/catch将简单地隐藏异常,因为您不再打印它。如果愿意,您可以用同样的方法构造.then/.catch。最好试着找出发生异常的原因。您是否在代码的其他地方成功使用了其他任何takeScreenshot或allure.createAttachment?这就是我使用takeScreenshot和allure.createAttachment的地方
browser.takeScreenshot().then(function (png) {
    allure.createAttachment('Screenshot', function () {
        return new Buffer(png, 'base64')
    }, 'image/png')()
}).catch((error: any) => console.log(error));