Javascript模块包含在量角器配置js文件中

时间:2019-01-08 12:49:19

标签: javascript protractor allure

我创建了一个定制的Jasmin-allure-reporter.js类,在其中编写了类似于jasime2Allure报告程序模块之类的报告配置方法,除了一些小的更改。现在,我想将此文件包含到量角器configuration.js文件中,在该文件中我想使用此文件生成自定义吸引力报告。但不幸的是,我一直都发现错误错误:错误:找不到模块“ customized-jasmin-allure-reporter”。

MyCustomized类是

 var Allure = require('allure-js-commons');
 var path = require('path');
 var allure = new Allure();


  function CustomizedJasminAllureReporter(userDefinedConfig, allureReporter) {
var Status = {PASSED: 'passed', FAILED: 'failed', BROKEN: 'broken', PENDING: 'pending'};
this.allure = allureReporter || allure;

..................

     }

     exports.allureReporter = allure;
    exports.CustomizedJasminAllureReporter =CustomizedJasminAllureReporter;

我的量角器配置文件是

    exports.config = {

troubleshoot: true, // for protractor
allScriptsTimeout: 1500000,
restartBrowserBetweenTests: false,

specs: [
    './e2e/tests/**/*.e2e-spec.ts',
],

capabilities:
    {
        'browserName' : 'chrome',
        'chromeOptions': { 'args' : ['--disable-extensions']},
        'shardTestFiles': true,
        'maxInstances': 1,
        'unexpectedAlertBehaviour' : 'dismiss'
    },
    ..............
onPrepare: function() {

    var AllureReporter = require('customized-jasmin-allure-reporter');

    // get the browser name
    var capsPromise = browser.getCapabilities();
    capsPromise.then(function(caps) {
        console.log(caps);
        var browserName = caps.get('browserName');
        var browserVersion = caps.get('version');
        browser.browserNameforSpec = browserName + "-" + browserVersion + "-";
        console.log(browser.browserNameforSpec);
    });

    browser.manage().window().maximize();
    require('ts-node').register({
        project: 'e2e/tsconfig.json'
    });

    jasmine.getEnv().addReporter(new AllureReporter({
        resultsDir: 'allure-results'

    }));
    jasmine.getEnv().addReporter(reporter);

    jasmine.getEnv().afterEach(function (done) {
            browser.takeScreenshot().then(function (png) {
                allure.createAttachment('Screenshot', function () {
                    return new Buffer(png, 'base64')
                },'image/png')();
                done();
            })
    });
 }
  }; 

1 个答案:

答案 0 :(得分:0)

您的自定义报告程序未正确导入。

`var AllureReporter = require('./src/...');` //Provide relative or absolute path of your report file.