以下是包含“量角器-jasmine2-screenshot-reporter”和“ jasmine-reporter”的配置文件

它单独可以正常工作,但是如果我同时结合了protractor-jasmine2-screenshot-reporter'不起作用,是因为我有两个'onPrepare'功能

 var HtmlScreenshotReporter = require('C:/Protractor_Scripts/node_modules/protractor-jasmine2-screenshot-reporter');

        var reporter = new HtmlScreenshotReporter({
          dest: 'C:/Protractor_Scripts/Screenshots',
          filename: 'Report.html'
        });

        exports.config = {

        directConnect: false,

        multiCapabilities: [


            {'browserName': 'chrome'},
            {'browserName': 'firefox'}

        ],

        allScriptsTimeout: 1200000,

        framework: 'jasmine2',

        specs: ['C:/Protractor_Scripts/Protractor/Driver/Driver.js'],

           // Setup the report before any tests start
           beforeLaunch: function() {
              return new Promise(function(resolve){
                reporter.beforeLaunch(resolve);
              });
           },


        onPrepare: function() {
              jasmine.getEnv().addReporter(reporter);
           },

           // Close the report after all tests finish
           afterLaunch: function(exitCode) {
              return new Promise(function(resolve){
                reporter.afterLaunch(resolve.bind(this, exitCode));
              });
           },


    Jasmine Reporter which is used to generate xml reports
        onPrepare: function() {

            var jasmineReporters = require('C:/Protractor_Scripts/node_modules/jasmine-reporters');
            jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
                consolidateAll: true,
                savePath: 'C:/Protractor_Scripts/Results',
                filePrefix: 'xmloutput'
            }));
        },

         // ----- Options to be passed to minijasminenode -----
          jasmineNodeOpts: {
            // onComplete will be called just before the driver quits.
            onComplete: null,
            // If true, display spec names.
            isVerbose: false,
            // If true, print colors to the terminal.
            showColors: true,
            // If true, include stack traces in failures.
            includeStackTrace: true,
            // Default time to wait in ms before a test fails.
            defaultTimeoutInterval: 1200000
          }

        };

最佳答案

不要定义两个onPrepare函数,将所有函数放到一个函数中:

onPrepare: function() {
    jasmine.getEnv().addReporter(reporter);

    var jasmineReporters = require('C:/Protractor_Scripts/node_modules/jasmine-reporters');
    jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
        consolidateAll: true,
        savePath: 'C:/Protractor_Scripts/Results',
        filePrefix: 'xmloutput'
    }));
},

07-24 09:49