【发布时间】:2019-08-01 22:53:30
【问题描述】:
根据 mocha-allure 文档,如果你想在 before/beforeEach 之外使用 allure,你应该直接导入记者。或者一旦添加 mocha-allure-reporter 将使用以下 API 创建全局 allure 对象:
https://github.com/allure-framework/allure-mocha
https://github.com/allure-examples/mocha-allure-example/blob/master/test/simple.spec.js
但是我遵循了文档中的示例,但是在 before 或 afterEach 中使用它时,我得到了 Cannot find name 'allure'. 。
测试文件:
require('mocha-allure-reporter');
// const allure = require('mocha-allure-reporter'); // also tried this
describe( 'test', () => {
// code
before(async () => {
// code here
});
afterEach('first step', function () {
const testStep = allure.createStep('initial', () => {
console.log('create step');
});
});
配置:
mochaOpts: {
reporterOptions: {
reporterEnabled:
mocha-allure-reporter,
mochaAllureReporterReporterOptions: {
targetDir: './reports/allure-results',
},
【问题讨论】:
-
您能在您的
node_modules中找到mocha-allure-reporter。如果不使用项目文件夹中的npm i mocha-allure-reporter。 -
是的
mocha-allure-reporter已经在node_modules -
您收到来自
config或test文件的错误。因为你在两个地方都使用mocha-allure-reporter -
来自测试文件
-
如果在您的
config中导入不会引发任何错误,请在您的规范中导入类似的方式
标签: protractor mocha.js allure