Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created May 6, 2016 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/c266eaf9adae2a0df9c7beb70d0f3dee to your computer and use it in GitHub Desktop.
Save vendettamit/c266eaf9adae2a0df9c7beb70d0f3dee to your computer and use it in GitHub Desktop.
xml stylesheet to transform MS Coded UI test results to html with xslt 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xp="http://www.xmlprime.com/"
xmlns:ext="urn:extensions">
<xsl:output method="html" />
<xsl:param name="applicationPath" select="'.'" />
<xsl:key name="groups" match="result" use="testCaseStatus"/>
<xsl:template match="/">
<script language="javascript">
function toggle (name, spn)
{
var element = name;//document.getElementById (name);
var span = spn; //document.getElementById (spn);
if (element.style.display == 'none'){
element.style.display = '';
span.innerText = 'Hide';
}
else {
span.innerText = 'Show';
element.style.display = 'none';
}
}
</script>
<div id="test-report">
<style type="text/css">
#test-report
{
font-family: Arial, Helvetica, sans-serif;
margin-left: 0;
margin-right: 0;
margin-top: 0;
}
#test-report .header
{
background-color: #566077;
background-repeat: repeat-x;
color: #fff;
font-weight: bolder;
height: 85px;
vertical-align: middle;
}
#test-report .headertext
{
height: 35px;
margin-left: 15px;
padding-top: 15px;
width: auto;
}
#test-report .wrapper
{
padding-left: 20px;
padding-right: 20px;
width: auto;
}
#test-report .legend
{
background-color: #ffc;
border: #d7ce28 1px solid;
font-size: small;
margin-top: 15px;
padding: 5px;
vertical-align: middle;
width: inherit;
}
#test-report .clickablerow
{
cursor: pointer;
}
#test-report .tabletotal
{
border-top: 1px #000;
font-weight: 700;
}
#test-report .results-table
{
border-collapse: collapse;
font-size: 12px;
margin-top: 20px;
text-align: left;
width: 100%;
}
#test-report .results-table th
{
background: #b9c9fe;
border-bottom: 1px solid #fff;
border-top: 4px solid #aabcfe;
color: #039;
font-size: 13px;
font-weight: 400;
padding: 8px;
}
#test-report .results-table td
{
background: #e8edff;
border-bottom: 1px solid #545409;
border-top: 1px solid transparent;
color: #669;
padding: 5px;
}
#test-report .errorlist td
{
background: #FFF;
border-bottom: 0;
border-top: 0 solid transparent;
color: #000;
padding: 0;
}
#test-report .inner-results
{
border-collapse: collapse;
font-size: 12px;
margin-bottom: 3px;
margin-top: 4px;
text-align: left;
/*width: 100%;*/
width: auto;
}
#test-report .inner-results td
{
background: #FFF;
border-bottom: 1px solid #545409;
border-top: 1px solid transparent;
color: #669;
padding: 3px;
}
.summaryline-Item
{
padding:10px;
}
.center{
text-align:center;
}
.left{
text-align:left
}
#test-report .inner-header th
{
background: #b9c9fe;
color: #039;
border: 1px solid;
}
#test-report .inner-rule-description
{
background-color: transparent;
border-collapse: collapse;
border: 0px;
font-size: 12px;
margin-bottom: 3px;
margin-top: 4px;
text-align: left;
width: 100%;
}
#test-report .inner-rule-description tr
{
background-color: transparent;
border: 0px;
}
#test-report .inner-rule-description td
{
background-color: transparent;
border-bottom: 1px solid #545409;
}
#btn {
cursor: pointer;
cursor: hand;
color: deepskyblue;
text-decoration: underline;
font-style: italic;
}
</style>
<div class="header">
<div class="headertext">
<div style="float:left" class="summaryline-Item">
<b>Your Project</b> - Test Execution Results
<br/>
Total tests: <xsl:value-of select="count(//result)"/>
</div>
<div style="float:right" class="summaryline-Item">
<small>
<i>
Execution Date:
<xsl:variable name="executionTime" select="/body/result/executionDate[1]"/>
<xsl:value-of select="substring-before($executionTime, ' ')" />
</i>
</small>
</div>
</div>
</div>
<div class="wrapper">
<div class="legend">
Summary (By status):
</div>
<div class="results-table">
<table cellpadding="2" cellspacing="0" width="100%" class="inner-results">
<thead>
<tr class="inner-header">
<th scope='col'>Status</th>
<th scope='col'>Count</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="body/result[generate-id() = generate-id(key('groups', testCaseStatus)[1])]"/>
</tbody>
</table>
</div>
<div class="legend">
Test Execution report:
</div>
<!--</div>
<div class="wrapper">-->
<div class="results-table">
<table cellpadding="2" cellspacing="0" width="100%" class="inner-results">
<tr class="inner-header">
<!--<th scope='col'>Execution Date</th>-->
<th scope='col'>Module</th>
<th scope='col'>UseCase-ID</th>
<th scope='col'>Test Case Name</th>
<th scope='col'>Priority</th>
<th scope='col'>Status</th>
<th scope='col'>Duration (in secs.)</th>
<th scope='col'>Failure Message</th>
</tr>
<xsl:for-each select="body/result">
<tr>
<!--<td class="summaryline-Item">
<xsl:value-of select="executionDate"/>
</td>-->
<td class="summaryline-Item">
<xsl:value-of select="moduleName"/>
</td>
<td class="summaryline-Item">
<xsl:value-of select="useCaseID"/>
</td>
<td class="summaryline-Item">
<xsl:value-of select="testCaseName"/>
</td>
<td class="summaryline-Item">
<xsl:value-of select="testCasePriority"/>
</td>
<td class="summaryline-Item">
<xsl:variable name="status" select="testCaseStatus"/>
<xsl:choose>
<xsl:when test="$status = 'Passed'">
<span style="color:green">
<xsl:value-of select="$status"/>
</span>
</xsl:when>
<xsl:otherwise>
<span style="color:red">
<xsl:value-of select="$status"/>
</span>
</xsl:otherwise>
</xsl:choose>
</td>
<td class="summaryline-Item">
<xsl:value-of select="testCaseDuration"/>
</td>
<td class="summaryline-Item">
<xsl:variable name="errMessage" select="failureMessage"/>
<xsl:if test="$errMessage != ''">
<xsl:variable name="message.id" select="generate-id()" />
<span id="btn" onclick="toggle({$message.id}, this)">Show</span>
<div id="{$message.id}" style="display:none;color:red">
<xsl:value-of select="$errMessage"/>
</div>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</table>
</div>
</div>
</div>
</xsl:template>
<xsl:template match="result">
<xsl:variable name="currentGroup" select="testCaseStatus"/>
<xsl:for-each select="testCaseStatus[count(. | key('groups', testCaseStatus)[1]) = 1]">
<tr>
<td class="summaryline-Item ">
<b>
<xsl:value-of select="$currentGroup"/>
</b>
</td>
<td class="summaryline-Item center">
<b>
<xsl:value-of select="count(key('groups', $currentGroup))"/>
</b>
</td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment