找不到Cucumber-HTML-Report的模板错误

时间:2017-07-01 08:04:51

标签: typescript protractor cucumber

我试图在执行后尝试生成cucumber-html-report,但收到错误 - "模板文件../node_modules/cucumber-html-report/不存在!中止" 谁能在这里帮忙。 npmjs.com说报告应该选择默认模板,但它不适合我。 如果需要,我可以在这里发布我的挂钩

const Cucumber = require('cucumber');
let report = require('cucumber-html-report');
import { browser } from 'protractor';
import * as fs from 'fs';
import { config } from '../config/config';
import { defineSupportCode } from "cucumber";
import * as reporter from 'cucumber-html-reporter';
import { mkdirp } from 'mkdirp';

defineSupportCode(function ({ registerHandler, registerListener, After,         setDefaultTimeout }) {
setDefaultTimeout(10 * 1000);
let jsonReports = process.cwd() + "/reports/json";
let htmlReports = process.cwd() + "/reports/html";
let targetJson = jsonReports + "/cucumber_report.json";

registerHandler('BeforeFeature', async function () {
    await browser.get(config.baseUrl);
});

After(async function (scenarioResult) {
    let world = this;
    if (scenarioResult.isFailed()) {
        let screenShot = await browser.takeScreenshot();
        world.attach(screenShot, 'image/png');
    }
})

let cucumberReporterOptions = {
    theme: "bootstrap",
    jsonFile: targetJson,
    output: htmlReports + "/cucumber_reporter.html",
    reportSuiteAsScenarios: true
};

let logFn = string => {
    if (!fs.existsSync(jsonReports)) {
        mkdirp.sync(jsonReports);
    }
    try {
        fs.writeFileSync(targetJson, string);
        reporter.generate(cucumberReporterOptions); 
        report.create({
            source:       targetJson,      
            dest:         htmlReports,                   
            name:         'MyReport.html',                 
            title:        'Cucumber Report',            
        })
    } catch (err) {
        if (err) {
            console.log(`Failed to save cucumber test results to json file. 
                         Failed to create html report.
                         `);
            console.log(err);
        }
    }
};
let jsonformatter = new Cucumber.JsonFormatter({
    log: logFn
});
registerListener(jsonformatter);

})

0 个答案:

没有答案