Why is my HTML test report always one XML file behind?
Asked Answered
W

1

11

This code in my protractor config file works perfectly... except that the html file creation in onComplete always uses the junitresults xml file from the previous test run, instead of the xml file created in the same config file's onPrepare function. So the html page is always showing test results one run behind what the timestamp displayed on the html page claims.

A simple illustration is that if I start with no xml file from a previous test in the test-results folder, the html generator finds no xml file at all to build an html file from, and therefore generates no html file. But the new xml file does show still get created, dropped into the folder, and totally ignored... until the next test run.

Can you help me get my test to generate an xml file and then use that xml file to generate the html file?

Thanks!

onPrepare: function() {
    var capsPromise = browser.getCapabilities();   
    capsPromise.then(function(caps) {
        browser.browserName = caps.caps_.browserName.replace(/ /g,"-");
        browser.browserVersion = caps.caps_.version; 
        browserName = browser.browserName;
        browser.reportPath = 'c:/QA/test-results/' + browser.browserName + '/';
    }). then(function(caps) {
            var jasmineReporters = require('jasmine-reporters');
            jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({    
                consolidateAll: true,
                savePath: 'c:/QA/test-results/' + browser.browserName + '/',
                filePrefix: 'junitresults'
        }));
    });
    return browser.browserName, browser.browserVersion, browser.reportPath;
},

onComplete: function() {
  var HTMLReport = require('jasmine-xml2html-converter');
  // Call custom report for html output
  testConfig = {
    reportTitle: 'Test Execution Report',
    outputPath: browser.reportPath,
    seleniumServer: 'default',
    applicationUrl: browser.baseUrl,
    testBrowser: browser.browserName + ' v.' + browser.browserVersion
  };
  new HTMLReport().from(browser.reportPath + 'junitresults.xml', testConfig);
  console.log("... aaaannnnd... done.");
},
Wadding answered 12/1, 2016 at 14:51 Comment(0)
V
5

This is all about the timing. JUnitXmlReporter from jasmine-reporters writes the output to an XML file on the jasmineDone callback (source), which happens after the onComplete.

First things to try should be to switch to afterLaunch or onCleanup instead of onComplete. Note the browser object would not be available in these methods and you would need other ways to share the variables between the callbacks. Also see:


You may also add a custom reporter, providing the jasmineDone callback:

jasmine.getEnv().addReporter({
    jasmineDone: function () {
          var HTMLReport = require('jasmine-xml2html-converter');
          // Call custom report for html output
          testConfig = {
            reportTitle: 'Test Execution Report',
            outputPath: browser.reportPath,
            seleniumServer: 'default',
            applicationUrl: browser.baseUrl,
            testBrowser: browser.browserName + ' v.' + browser.browserVersion
          };
          new HTMLReport().from(browser.reportPath + 'junitresults.xml', testConfig);
          console.log("... aaaannnnd... done.");
    }
});

Another option would be to produce an HTML report directly via, for example, protractor-jasmine2-html-reporter.

Vano answered 28/1, 2016 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.