【问题标题】:allure.createAttachment exception error - Cannot read property 'currentStep' of undefinedallure.createAttachment 异常错误 - 无法读取未定义的属性“currentStep”
【发布时间】:2019-03-14 18:10:36
【问题描述】:

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

错误:

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));

【问题讨论】:

  • 您是遇到错误还是只有异常?你在你的项目中使用了currentStep 吗?
  • 只是例外。我似乎已经通过添加 try, catch 来解决它。这是正确的方法吗? try { await browser.takeScreenshot().then(function (png) { allure.createAttachment(title, new Buffer(png, 'base64')); }); } catch (e) { console.log('Error caught'); }
  • 我没有使用currentStep,它来自createAttachment吗?
  • @user 我猜您的脚本仍在从您发布的评论中的代码中打印出Error caught?您的 try/catch 将简单地隐藏异常,因为您不再打印它。如果你愿意,你可以用同样的方式构建你的 .then/.catch 。最好尝试找出发生该异常的原因。您是否在代码中的其他任何地方成功使用了任何其他 takeScreenshotallure.createAttachment
  • 这是我使用takeScreenshotallure.createAttachment的地方

标签: protractor mocha.js allure


【解决方案1】:
const allure = require('mocha-allure-reporter');

allure 是一个全局标识符,由记者注入到您的代码中。

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

declare const allure: any;

【讨论】:

    【解决方案2】:

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

    您可以尝试更改代码以反映以下内容吗

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      • 2020-10-15
      • 2021-12-31
      • 2022-10-05
      • 2020-03-26
      相关资源
      最近更新 更多