Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.");
},
like image 451
Defpotec2020 Avatar asked Jan 12 '16 14:01

Defpotec2020


People also ask

How can you load XML data into an HTML page?

XML text can also be loaded from a text string. Note that the "loadXML" method (instead of the "load" method) is used to load a text string. To display XML you can use JavaScript. JavaScript (or VBScript) can be used to import data from an XML file, and display the XML data inside an HTML page.

What is HTML XML?

XML stands for eXtensible Markup Language. XML is a markup language much like HTML. XML was designed to store and transport data. XML was designed to be self-descriptive. XML is a W3C Recommendation.

What is XML file format?

What is XML? The Extensible Markup Language (XML) is a simple text-based format for representing structured information: documents, data, configuration, books, transactions, invoices, and much more. It was derived from an older standard format called SGML (ISO 8879), in order to be more suitable for Web use.


1 Answers

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:

  • onCleanUp() vs onComplete() vs afterLaunch()

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.

like image 191
alecxe Avatar answered Sep 25 '22 21:09

alecxe