Using XML::XSLT to make your test results pretty

来源:互联网 发布:罗志祥女友的淘宝店 编辑:程序博客网 时间:2024/06/05 00:57

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:

View as plain text
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...

 

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.

原创粉丝点击