Nodejs Protractor + Jasmine + JUnitXmlReporter run

2019-08-10 03:50发布

问题:

Im doing end to end testing of a Angular website using protractor, but wanted to export the results to a file that Jenkins can read (JUnitXmlReporter), so for this to work I need to do a "simple change" to my protractor config file on the "onPrepare":

exports.config = {
  // Do not start a Selenium Standalone sever - only run this using chrome.
  framework: 'jasmine',
  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  specs: [
    './test1.js',
    './test2.js'
  ], 
  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    isVerbose: true
  },
  onPrepare: function() {
      var jasmineReporters = require('jasmine-node-reporter-fix');
      jasmine.getEnv().addReporter(
             new jasmineReporters.JUnitXmlReporter('protractor_output', true, true, 'testresults.e2e.');
  }
};

but once I add this "onPrepare" code, all the test run without waiting for the browser to render the html. If I remove the "onPrepare" code, all the test will start working as expected, but no files generated for jenkins.

Any ideas whats wrong?

回答1:

You may need to wait for the browser's promise.

onPrepare: function() {
  var jasmineReporters = require('jasmine-node-reporter-fix');
  var capsPromise = browser.getCapabilities();
  capsPromise.then(function (caps) {
    jasmine.getEnv().addReporter(
      new jasmineReporters.JUnitXmlReporter(
        'protractor_output', true, true, 'testresults.e2e.');
  }
}

That said, if you are using Protractor, then you may need to call the JUnitXmlReporter off the jasmine object, not jasmineReporters. I'm not using node-jasmine or jasmine-node-reporter-fix, so I can't speak to how the reporter gets exported, but on "jasmine-reporters":"~1.0.0" the reporter was still attached to the jasmine object.

https://github.com/larrymyers/jasmine-reporters#protractor