protractor - 无法使用 mocha-allure 访问全局“allure”对象
问题描述
根据 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
但是,我遵循了文档中的示例,但是Cannot find name 'allure'.
在 before 或 afterEach 中使用它时,我得到了。
测试文件:
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',
},
解决方案
试试下面的
const allure = require('mocha-allure-reporter');
allure 是一个全局标识符,由记者注入到您的代码中。
将以下行添加到文件顶部以告知 Typescript
declare const allure: any;
希望对你有帮助
推荐阅读
- python - pip安装后找不到python模块
- python-3.x - 如何修复烧瓶中的'TypeError:'module'对象不可调用'?
- hugo - 如何在 Hugo 的 [permalinks] 部分中使用自定义参数?
- c# - 通过使用代理 API 将多个文件上传到 Sharepoint 2013 以验证文件上传过程(使用 vti_bin/copy.asmx)
- c++ - 我找不到在同一编译屏幕上与线程同时运行此计数器 3 次的方法
- java - Tomcat 8 Docx4j 应用程序问题
- bash - 给定字符串:approximateLastUseTime:'2019-10-15T16:56:07.082500Z',我需要提取 T 之后和 Z 之前的所有内容(冒号之后)
- unity3d - Unity 服务器构建(无头)原生纹理指针返回 0
- java - Java replaceAll("\\s+", "") 不替换空格
- assembly - 在汇编语言中将数组旋转 1 索引