jasmine-reporters is not generating any file

2019-05-29 06:52发布

问题:

i'm using jasmine-reporters to generate a report after protractor finish the tests,

this is my configuration file:

  onPrepare: function(){
            var jasmineReporters = require('jasmine-reporters');
            var capsPromise = browser.getCapabilities();
            capsPromise.then(function(caps){
                var browserName = caps.caps_.browserName.toUpperCase();
                var browserVersion = caps.caps_.version;
                var prePendStr = browserName + "-" + browserVersion + "-";
                jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter("protractor_output", true, true,prePendStr));
            });
     },

i don't get any error, the reporters installed, but i don't see any file in protractor_output folder.

Any idea what am i doing wrong?

回答1:

The problem is with the jamsine version:

If you are trying to use jasmine-reporters with Protractor, keep in mind that Protractor is built around Jasmine 1.x. As such, you need to use a 1.x version of jasmine-reporters.

npm install jasmine-reporters@~1.0.0

then the configuration should be:

onPrepare: function() {
    // The require statement must be down here, since jasmine-reporters@1.0
    // needs jasmine to be in the global and protractor does not guarantee
    // this until inside the onPrepare function.
    require('jasmine-reporters');
    jasmine.getEnv().addReporter(
        new jasmine.JUnitXmlReporter('xmloutput', true, true)
    );
}

If you are on a newer version of the Jasmine Reporter, then the require statement no longer puts the JUnitXmlReporter on the jasmine object, but does put it on the module export. Your setup would then look like this:

onPrepare: function() {
    // The require statement must be down here, since jasmine-reporters@1.0
    // needs jasmine to be in the global and protractor does not guarantee
    // this until inside the onPrepare function.
    var jasmineReporters = require('jasmine-reporters');
    jasmine.getEnv().addReporter(
        new jasmineReporters.JUnitXmlReporter('xmloutput', true, true)
    );
}

also you need to verify that xmloutput directory exist!



回答2:

To complete the answer, if the output is still not generating,

Try adding these configuration line to your protractor exports.config object :

framework: "jasmine2",
onPrepare: function() {
    var jasmineReporters = require('jasmine-reporters');
.......
}