Update of /cvsroot/http-webtest/HTTP-WebTest-Plugin-XMLReport/example/transform
In directory sc8-pr-cvs1:/tmp/cvs-serv19392/example/transform
Added Files:
content.xsl email.xsl extract-failed.xsl listtests-html.xsl
listtests.xsl merge-results.xsl sidebar.xsl
Log Message:
Added example script for using the XMLReport output
--- NEW FILE: content.xsl ---
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
omit-xml-declaration="yes"
indent="yes"
encoding="utf-8"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Refresh" content="600; url=content.html"/>
<meta http-equiv="Pragma" content="no-cache"/>
<title>
<xsl:value-of select="testresults/title"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="testresults/@date"/>
</title>
<xsl:call-template name="style"/>
<xsl:call-template name="script"/>
</head>
<body>
<a name="top"><xsl:comment>top</xsl:comment></a>
<h2>
<xsl:value-of select="testresults/title"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="testresults/@date"/>
</h2>
<h3>WebTest results</h3>
<ul>
<xsl:apply-templates select="testresults/group" mode="toc"/>
</ul>
<p>
<a href="javascript:addNetscapePanel('{testresults/title}'); void(0);">Add this to Mozilla Sidepanel</a>
</p>
<xsl:apply-templates select="testresults/group" mode="body"/>
</body>
</html>
</xsl:template>
<xsl:template match="group" mode="toc">
<li>
<span class="{@status}">
<xsl:value-of select="@status"/>
</span>
<xsl:text>: </xsl:text>
<a href="#group{position()}">
<xsl:value-of select="string(@name)"/>
</a>
</li>
</xsl:template>
<xsl:template match="group" mode="body">
<a name="group{position()}">
<xsl:comment> This space for rent </xsl:comment>
</a>
<div class="group">
<div style="float: right; padding-right: 5px;">
<a href="#top">TOP</a>
</div>
<a href="{@url}" onclick="return warn(this, '{@method}');" title="Link: request url for {@name}">
<xsl:value-of select="@name"/>
</a>
<xsl:if test="@method">
<xsl:text> (method = </xsl:text>
<xsl:value-of select="@method"/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:apply-templates select="test"/>
</div>
</xsl:template>
<xsl:template match="test">
<div class="test">
<span title="{@name}">
<xsl:value-of select="string(@name)"/>
</span>
<xsl:apply-templates select="result"/>
</div>
</xsl:template>
<xsl:template match="result">
<xsl:element name="div">
<xsl:attribute name="class">
<xsl:text>result </xsl:text>
<xsl:value-of select="@status"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="."/>
</xsl:attribute>
<div class="status">
<xsl:value-of select="string(@status)"/>
</div>
<xsl:value-of select="string(.)"/>
</xsl:element>
</xsl:template>
<!-- Utilities -->
<xsl:template name="script">
<script language="JavaScript">
<xsl:text disable-output-escaping="yes"><![CDATA[ //<![CDATA[
function warn(oLink, strMethod) {
var strWarn = oLink.href;
if (strWarn.length > 53) {
strWarn = strWarn.substring(0,50) + "...";
}
strWarn += '\n \n';
if (strMethod == 'POST') {
strWarn += 'This link does not match the test condition\n';
strWarn += 'because POST data is missing.\n \n';
} else {
strWarn += 'This link may not fully match the test conditions.\n';
strWarn += 'Cookies or adapted http-headers may exist.\n \n'
}
strWarn += 'Continue?';
return window.confirm(strWarn);
}
function addNetscapePanel(strTitle) {
if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
{
if (!strTitle) strTitle = "WebTest";
var url = document.location.protocol + '//' + document.location.host + document.location.pathname;
url = url.substring(0,url.indexOf('content.html')) + 'sidebar.html';
window.sidebar.addPanel (strTitle, url, "");
} else {
var rv = window.confirm ("This page is enhanced for use with Netscape 6. "
+ "Would you like to upgrade now?");
if (rv)
document.location.href = "http://home.netscape.com/download/index.html";
}
}
]]>// ]]></xsl:text>
</script>
</xsl:template>
<xsl:template name="style">
<style type="text/css">
<xsl:text disable-output-escaping="yes"><![CDATA[
body {
background-color: white;
font-family: arial,helvetica,sans-serif;
font-size: 10pt;
}
a {
text-decoration: none;
color: darkblue;
}
a:hover {
text-decoration: underline;
color: blue;
}
div.group {
margin: 16px 0px;
padding: 0px 3px;
background-color: white;
border: 1px solid black;
font-weight: bold;
}
div.test {
margin: 4px 0px;
padding: 1px 4px;
background-color: white;
border: 1px solid #999;
font-weight: normal;
}
div.result {
margin: 1px 0px;
padding: 1px 8px;
font-family: courier,monospace;
}
.PASS {
background-color: #1d1;
}
.FAIL {
background-color: #e00;
}
div.status {
font-family: arial,helvetica,sans-serif;
font-weight: bold;
font-size: 9pt;
width: 50px;
float: left;
color: white;
}
]]></xsl:text>
</style>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: email.xsl ---
<?xml version="1.0"?>
<!-- define a DOS type line ending as entity -->
<!DOCTYPE stylesheet [ <!ENTITY crlf " "> ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="text"
omit-xml-declaration="yes"
indent="no"
encoding="iso-8859-1"/>
<xsl:strip-space elements="*"/>
<!-- read the test definition document into variable "$testdef" -->
<xsl:param name="testdoc"/>
<xsl:variable name="testdef" select="document($testdoc)"/>
<xsl:template match="/">
<!-- count number of failed tests -->
<xsl:variable name="failed">
<xsl:value-of select="count(//group[test/result/@status = 'FAIL'])"/>
</xsl:variable>
<!-- list failed test numbers -->
<xsl:variable name="testnums">
<xsl:for-each select="//group[test/result/@status = 'FAIL']">
<xsl:text> </xsl:text>
<xsl:apply-templates select="$testdef/WebTest/testgroup" method="testnumber">
<xsl:with-param name="testname" select="@name"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$failed = 0">
<!--
<xsl:message terminate="yes">
<xsl:text>All tests passed.</xsl:text>
</xsl:message>
-->
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="email-headers">
<xsl:with-param name="num" select="$failed"/>
<xsl:with-param name="list" select="$testnums"/>
</xsl:call-template>
<xsl:text>Output of </xsl:text>
<xsl:value-of select="concat($testdef/WebTest/@title,' (',$failed,' failed) at ')"/>
<xsl:value-of select="testresults/@date"/>
<xsl:text>&crlf;&crlf;</xsl:text>
<xsl:apply-templates select="testresults"/>
<xsl:call-template name="email-footer"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="testresults">
<xsl:apply-templates mode="list-tests"
select="group[count(test/result[normalize-space(@status) = 'FAIL']) > 0]"/>
<xsl:text>&crlf;Test links:&crlf;</xsl:text>
<xsl:apply-templates mode="list-links"
select="group[count(test/result[normalize-space(@status) = 'FAIL']) > 0]"/>
</xsl:template>
<xsl:template match="group" mode="list-tests">
<!-- we only have nodes with failed subtests -->
<xsl:variable name="failed">
<xsl:value-of select="count(test/result[normalize-space(@status) = 'FAIL'])"/>
</xsl:variable>
<xsl:variable name="testname">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:variable name="testnumber">
<!-- test number in original test specification -->
<xsl:apply-templates select="$testdef/WebTest/testgroup" method="testnumber">
<xsl:with-param name="testname" select="$testname"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:value-of disable-output-escaping="yes"
select="concat('[',position(),'] test #',$testnumber,': ',normalize-space(@name),'&crlf;')"/>
<xsl:value-of select="concat('Failed: ',$failed,' of ',count(test/result),' subtest')"/>
<xsl:if test="count(test/result) > 1">
<xsl:text>s</xsl:text>
</xsl:if>
<xsl:if test="$testdef/WebTest/testgroup[@test_name=$testname]/@method">
<xsl:text> (method=</xsl:text>
<xsl:value-of select="$testdef/WebTest/testgroup[@test_name=$testname]/@method"/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text>&crlf;</xsl:text>
<xsl:for-each select="test/result[normalize-space(@status) = 'FAIL']">
<xsl:value-of disable-output-escaping="yes"
select="concat(' ',../@name,': "',normalize-space(.),'"&crlf;')"/>
</xsl:for-each>
<xsl:text>&crlf;</xsl:text>
</xsl:template>
<xsl:template match="testgroup" method="testnumber">
<xsl:param name="testname"/>
<xsl:if test="@test_name=$testname">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:template>
<xsl:template match="group" mode="list-links">
<xsl:variable name="num">
<xsl:value-of select="position()"/>
</xsl:variable>
<xsl:variable name="testname">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:if test="$num < 100">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="$num < 10">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:number value="$num" format="1. "/>
<xsl:value-of select="@url"/>
<xsl:if test="$testdef/WebTest/testgroup[@test_name=$testname]/@method">
<xsl:text> (method=</xsl:text>
<xsl:value-of select="$testdef/WebTest/testgroup[@test_name=$testname]/@method"/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text>&crlf;</xsl:text>
</xsl:template>
<xsl:template name="email-headers">
<xsl:param name="num"/>
<xsl:param name="list"/>
<xsl:text>From: </xsl:text>
<xsl:value-of disable-output-escaping="yes" select="$testdef/WebTest/param/mail_from"/>
<xsl:text>&crlf;To: </xsl:text>
<xsl:for-each select="$testdef/WebTest/param/mail_addresses">
<xsl:value-of disable-output-escaping="yes" select="concat(text(), ', ')"/>
</xsl:for-each>
<xsl:choose>
<xsl:when test="normalize-space($testdef/WebTest/param/mail_method)='SMS'">
<xsl:text>&crlf;Subject: Webtest:</xsl:text>
<xsl:value-of select="$list"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>&crlf;Subject: [webtest] </xsl:text>
<xsl:value-of select="$num"/>
<xsl:choose>
<xsl:when test="$num > 1">
<xsl:text> tests</xsl:text>
</xsl:when>
<xsl:when test="$num = 1">
<xsl:text> test</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text> failed for "</xsl:text>
<xsl:value-of select="$testdef/WebTest/@title"/>
<xsl:text>".</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>&crlf;&crlf;</xsl:text>
</xsl:template>
<xsl:template name="email-footer">
<xsl:text>
--
NOTE: the test links will not properly work if the original
test contained POST data, cookie headers or other http-headers
which affect the application's behaviour.
</xsl:text>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: extract-failed.xsl ---
<?xml version="1.0"?>
<!--
Usage:
xsltproc -param testdoc "'Input.xml'" extract-failed.xsl Output.xml
Where:
Input.xml = original webtest specification
Output.xml = output of webtest, based on Input.xml
Returns:
WebTest specification with only tests that failed in Output.xml
Purpose:
Use the resulting document to run previously failed webtest groups again
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
omit-xml-declaration="no"
indent="yes"
encoding="utf-8"/>
<xsl:param name="testdoc"/>
<xsl:variable name="testtree" select="document($testdoc)"/>
<xsl:key name="testNameKey" match="/WebTest/testgroup" use="@test_name"/>
<xsl:template match="/testresults">
<WebTest title="{$testtree/WebTest/@title}">
<xsl:comment>
<xsl:text>Failed tests from Webtest run at </xsl:text>
<xsl:value-of select="@date"/>
</xsl:comment>
<!-- copy global test parameter block -->
<xsl:apply-templates select="$testtree/WebTest/param" />
<!-- find testgroups with failed subtests -->
<xsl:for-each select="group">
<xsl:variable name="name" select="@name"/>
<xsl:if test="test/result[@status='FAIL']">
<!-- breaks when test-text contains 'dash-dash' sequence...
<xsl:comment>
<xsl:text>First failed test: </xsl:text>
<xsl:value-of select="test[result/@status='FAIL']/@name"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="test/result[@status='FAIL']"/>
</xsl:comment>
-->
<xsl:apply-templates select="$testtree/WebTest/testgroup[@test_name=$name]"/>
</xsl:if>
</xsl:for-each>
</WebTest>
</xsl:template>
<xsl:template match="testgroup">
<!-- first copy previous testgroup if there is no url attribute -->
<xsl:if test="not(@url)">
<xsl:apply-templates select="preceding-sibling::*[position()=1]"/>
</xsl:if>
<!-- then the current testgroup element -->
<xsl:element name="testgroup">
<xsl:apply-templates select="@*|node()|comment"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()|comment">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: listtests-html.xsl ---
<?xml version="1.0"?>
<!--
Stylesheet to list names of testgroups
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="html"
omit-xml-declaration="no"
indent="yes"
encoding="utf-8"/>
<xsl:template match="/">
<html>
<head>
<title>WebTest: <xsl:value-of select="/WebTest/@title"/></title>
</head>
<body>
<h2>WebTest: <xsl:value-of select="/WebTest/@title"/></h2>
<table border="1">
<tr>
<th>#</th>
<th>Test</th>
<th>Comment</th>
</tr>
<xsl:apply-templates select="//testgroup"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="testgroup">
<tr>
<td><xsl:value-of select="position()"/></td>
<td><xsl:value-of select="@test_name"/></td>
<td><xsl:value-of select="comment"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: listtests.xsl ---
<?xml version="1.0"?>
<!--
Stylesheet to list names of testgroups
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="text"
omit-xml-declaration="no"
indent="yes"
encoding="utf-8"/>
<xsl:template match="/">
<xsl:apply-templates select="//testgroup"/>
</xsl:template>
<xsl:template match="testgroup">
<xsl:value-of select="position()"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="/WebTest/@title"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="@test_name"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="comment"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: merge-results.xsl ---
<?xml version="1.0"?>
<!--
Stylesheet to merge results of two test-runs
Set "status" attribute of "group" element according to one failing subtest
Copy a few values from test definition
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
omit-xml-declaration="no"
indent="yes"
encoding="utf-8"/>
<!-- read the results of the second pass into variable "$retried" -->
<xsl:param name="merge"/>
<xsl:variable name="retried" select="document($merge)"/>
<!-- read the test definition document into variable "$testdef" -->
<xsl:param name="testdoc"/>
<xsl:variable name="testdef" select="document($testdoc)"/>
<xsl:template match="/">
<xsl:apply-templates select="*|@*"/>
</xsl:template>
<xsl:template match="testresults">
<xsl:element name="testresults">
<xsl:apply-templates select="@*"/>
<!-- insert title based on test-def. attribute -->
<title>
<xsl:value-of select="$testdef/WebTest/@title"/>
</title>
<xsl:apply-templates select="*"/>
</xsl:element>
</xsl:template>
<xsl:template match="group">
<xsl:variable name="localname" select="@name"/>
<xsl:element name="group">
<!-- insert attribute status based on subtests -->
<xsl:attribute name="status">
<xsl:choose>
<!-- check only for second testrun result -->
<xsl:when test="$retried/testresults/group[@name=$localname]/test/result[@status='FAIL']">
<xsl:text>FAIL</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>PASS</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$testdef/WebTest/testgroup[@test_name=$localname]/@method='POST'">
<xsl:attribute name="method">POST</xsl:attribute>
</xsl:if>
<!-- copy remaining attributes -->
<xsl:apply-templates select="@*"/>
<!-- select results from latest testrun -->
<xsl:choose>
<xsl:when test="$retried/testresults/group[@name=$localname]">
<xsl:apply-templates select="$retried/testresults/group[@name=$localname]/test"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="test"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
<!-- Utilities -->
<!-- ## default elements: just copy ## -->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*"/>
<!--xsl:apply-templates select="node()"/-->
<xsl:apply-templates select="*|processing-instruction()|comment()|text()"/>
</xsl:element>
</xsl:template>
<!-- ## attributes: just copy ## -->
<xsl:template match="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!-- ## PI: just copy ## -->
<xsl:template match="processing-instruction()">
<xsl:processing-instruction name="{name()}">
<xsl:value-of select="."/>
</xsl:processing-instruction>
</xsl:template>
<!-- ## Comment: just copy ## -->
<xsl:template match="comment()">
<xsl:comment>
<xsl:value-of select="."/>
</xsl:comment>
</xsl:template>
</xsl:stylesheet>
--- NEW FILE: sidebar.xsl ---
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
omit-xml-declaration="yes"
indent="yes"
encoding="utf-8"/>
<!-- establish a "random" variable to force reload of target url -->
<xsl:variable name="rnd" select="translate(/testresults/@date,' :','--')"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Refresh" content="600; url=sidebar.html"/>
<meta http-equiv="Pragma" content="no-cache"/>
<title>
<xsl:text>WebTest Output</xsl:text>
</title>
<xsl:call-template name="style"/>
</head>
<body>
<p>
<xsl:value-of select="testresults/@date"/>
<br/>
<a href="content.html?{$rnd}#top" target="_content">
<xsl:text>-> test results</xsl:text>
</a>
</p>
<xsl:apply-templates select="testresults/group"/>
</body>
</html>
</xsl:template>
<xsl:template match="group">
<xsl:element name="div">
<xsl:attribute name="title">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="class">
<xsl:text>group</xsl:text>
<xsl:if test="@status = 'FAIL'">
<xsl:text> failed</xsl:text>
</xsl:if>
</xsl:attribute>
<a href="content.html?{$rnd}#group{position()}"
title="{@name}" target="_content">
<xsl:value-of select="string(@name)"/>
</a>
</xsl:element>
</xsl:template>
<xsl:template name="style">
<style type="text/css">
<xsl:text disable-output-escaping="yes"><![CDATA[
body {
background-color: white;
font-family: arial,helvetica,sans-serif;
font-size: 8pt;
}
a {
text-decoration: none;
color: black;
}
a:hover {
text-decoration: underline;
color: blue;
}
div.group a:hover {
text-decoration: underline;
color: white;
}
div.group {
margin: 2px 0px;
padding-left: 3px;
background-color: #1d1;
}
div.failed {
background-color: #e00;
}
]]></xsl:text>
</style>
</xsl:template>
</xsl:stylesheet>
|