Using XML::XSLT to make your test results pretty

This question came up at QAForums recently:

Q: Is it possible to export QTP results to HTML format?

A: Mercury has provided nearly everything you'd ever need to make this happen, and it's highly customizable if you take the time to learn XSLT.

XSLT is a simple technology, used to transform XML documents into other kinds of documents. QTP comes with three XSL files, which transform the Results.xml file into perfectly readable HTML code.

These stylesheets live in the <QTP root>\dat\ folder (on mine, it's C:\Program Files\Mercury Interactive\QuickTest Professional\dat):
PShort.xsl
PDetails.xsl
PSelection.xsl

When the test run report is generated, it's stored in a directory something like this:
<test folder>\Res1\Report\Results.xml

To see it, you have to add the following line below the XML declaration in Results.xml, so it looks like this:

XML:
  1. <?xml version="1.0"?>
  2. <!-- This assumes you've made the PShort.xsl file available via a web server!! -->
  3. <?xml-stylesheet href="http://localhost/qtp/PShort.xsl" type="text/xsl"?>

Then view the Results.xml file in IE (which has an XSL engine built into it).

What we do is, we use an external XSLT transformation tool called 'xsltproc' (which comes from the LibXML2 suite at XMLSoft) to generate an HTML file, which we then upload to a server that archives all our test result information. That way nobody needs Mercury's Results Viewer app (that blasted thing takes you through too many clicks to get what you want, and it doesn't remember your filter preferences from one session to the next... GARR!!!!)

This is much better for everyone on my team.

So, it's not difficult, and you have everything you need already. Now if only there were a way to have QTP insert that stylesheet declaration by default into every test...

Tags: , , ,

6 Comments for “Using XML::XSLT to make your test results pretty”

  1. Graeme Says:

    You do not need to link the xml and the xslt inside the xml file.

    You can create a new html that points to a xml file and also a xslt file.

    e.g.

    // Load XML
    var xml = new ActiveXObject(”Microsoft.XMLDOM”)
    xml.async = false
    xml.load(”Results.xml”)// Load XSL
    var xsl = new ActiveXObject(”Microsoft.XMLDOM”)
    xsl.async = false
    xsl.load(”PShort.xsl”)// Transform
    document.write(xml.transformNode(xsl))

    You should be able to get QTP to create a html like this to point to the correct results.xml.

    Reply to Graeme

  2. Marcus Says:

    Excellent! I’ve mostly been playing around with all the Perl XSLT modules, and hadn’t gotten around to using the ones already installed in my machine. I’ll definitely be able to use this.

    Thanks!

    Reply to Marcus

  3. Huw Says:

    How do I modify the XSLT stylesheets to get the screen captures from the test results to display? In the Results XML the code is there but it doesnt display.

    I am pretty clueless about xslt syntax, so any help would be appreciated.

    Reply to Huw

  4. The Software Inquisition » A CGI Script to Launch QTP Tests Says:

    [...] There are a couple pieces of information missing from here: what is the big textarea called “XML”? How does the stylesheet get passed in? What’s all this XSLT nonsense? [...]

    Reply to The Software Inquisition » A CGI Script to Launch QTP Tests

  5. Anuj Says:

    When I export results to HTML format, I get results including object.exists, etc etc…

    I just need the passed and failed messages to be displayed. Can some1 provide me the solution for that?

    Reply to Anuj

  6. Executing test cases via the queue | The Software Inquisition Says:

    [...] the Results.xml file into HTML by using a slightly altered version of PShort.xsl (available in the dat folder of your QTP [...]

    Reply to Executing test cases via the queue | The Software Inquisition

Leave a Reply