Hey all, just thought I'd share something with you that has made my
testing life a little easier. I don't have my test suite set up in
Cruise Control yet, and even when I do I don't really want to run it
every time I'm messing with the tests. So I wrote this xml stylesheet
that puts CI_Reporter's output in a little more friendly format. I
have it in 3 parts: the xml stylesheet, a ruby script that edits your
output file to use the script, and a batch file that runs the script
and then opens the results. I like the batch file just cause it saves
me from remembering to run the script every time. This assumes that
all 3 of these files are in the same directory as your test results.
The stylesheet formats the results so that it lists the number of
tests run and the number of errors or failures (the failures get big
and red, the errors get big and purple). Then it lists each test,
whether it passed, failed, or had an error, and then how long it took,
along with a total time at the bottom (you can mouseover for the time
in minutes). Then it lists separately the failures, showing which test
failed, the failure message, and you can mouseover for the entire
failure output, including line #s, etc...). Then another table exactly
the same for any errors.

Here's the stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
  <html>
    <head>
      <style type="text/css">
        a.info{
          position:relative; /*this is the key*/
          z-index:24; background-color:#FFFFFF;
          color:#000;
          text-decoration:none}
        a.info:hover{z-index:25; background-color:#000000;
color:#FFFFFF}
        a.info span{display: none}
        a.info:hover span{ /*the span will display just on :hover
state*/
          display:block;
          position:absolute;
          top:2em; left:2em; width:40em;
          border:1px solid #000000;
          background-color:#FFFFFF; color:#000000;
          text-align: center}
      </style>
    </head>
  <body bgcolor="5B94CC">
  <table><tr><td>
  <h1>Test Results</h1>
  </td></tr></table>
    <table border="1" rules="ROWS" bgcolor="FFFFFF">
      <tr align="center">
        <xsl:for-each select="testsuite" >
          <td>Tests Run: <xsl:value-of select="@tests" /></td>
          <xsl:choose>
            <xsl:when test="@failures>0">
              <td><font size="5">Failures: </font><font size="5"
color="red"><xsl:value-of select="@failures"/></font></td>
            </xsl:when>
            <xsl:otherwise>
              <td>Failures: <xsl:value-of select="@failures"/></td>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="@errors>0">
              <td><font size="5">Errors: </font><font size="5"
color="purple"><xsl:value-of select="@errors"/></font></td>
            </xsl:when>
            <xsl:otherwise>
              <td>Errors: <xsl:value-of select="@errors"/></td>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </tr>
      <tr bgcolor="#9acd32">
        <th>Test Name</th>
        <th>Results</th>
        <th>Time</th>
      </tr>
      <xsl:for-each select="testsuite/testcase">
      <xsl:variable name="testname" select="@name" />
        <tr>
          <td><xsl:value-of select="substring-after
($testname,'test_')"/></td>
          <td>
            <xsl:choose>
              <xsl:when test="failure">
                <xsl:variable name="failtype"
select="'Test::Unit::AssertionFailedError'" />
                <xsl:choose>
                  <xsl:when test="failure/@type=$failtype" >
                    <font color="red">Failed</font>
                  </xsl:when>
                  <xsl:otherwise>
                    <font color="purple">Error</font>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                <font color="green">Passed</font>
              </xsl:otherwise>
            </xsl:choose>
          </td>
          <td><xsl:value-of select="@time"/> seconds</td>
        </tr>
      </xsl:for-each>

      <xsl:for-each select="testsuite" >
        <tr><td /><td>Total Time:</td><td><a class="info"
href="#"><xsl:value-of select="@time"/> seconds<span><xsl:value-of
select="floor(@time div 60)"/> minutes, <xsl:value-of select="round
(@time mod 60)"/> seconds</span></a></td></tr>
      </xsl:for-each>
    </table>
    <p/>
    <table border="1" rules="ALL" bgcolor="FFFFFF">
      <tr>
        <th>Test Failed</th>
        <th />
        <th>Failure Message <font size="2">(mouseover for details)</
font></th>
      </tr>
      <xsl:for-each select="testsuite/testcase">
        <xsl:if test="failure">
          <xsl:variable name="failtype"
select="'Test::Unit::AssertionFailedError'" />
          <xsl:if test="failure/@type=$failtype" >
            <tr>
              <xsl:variable name="testname" select="@name" />
              <xsl:variable name="testfail" select="failure" />
              <td><xsl:value-of select="substring-after
($testname,'test_')"/></td>
              <td />
              <td><a class="info" href="{$testfail}"><xsl:value-of
select="failure/@message"/><span><xsl:value-of select="failure"/></
span></a></td>
            </tr>
          </xsl:if>
        </xsl:if>
      </xsl:for-each>
    </table>
    <p/>
    <table border="1" rules="ALL" bgcolor="FFFFFF">
      <tr>
        <th>Test With Error(s)</th>
        <th />
        <th>Error Message <font size="2">(mouseover for details)</
font></th>
      </tr>
      <xsl:for-each select="testsuite/testcase">
        <xsl:if test="failure">
          <xsl:variable name="failtype"
select="'Test::Unit::AssertionFailedError'" />
          <xsl:if test="failure/@type != $failtype" >
            <tr>
              <xsl:variable name="testname" select="@name" />
              <xsl:variable name="testfail" select="failure" />
              <td><xsl:value-of select="substring-after
($testname,'test_')"/></td>
              <td />
              <td><a class="info" href="{$testfail}"><xsl:value-of
select="failure/@message"/><span><xsl:value-of select="failure"/></
span></a></td>
            </tr>
          </xsl:if>
        </xsl:if>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>



Here's the ruby script(not elegant but functional):

require 'fileutils'
xml_output = File.open(".\\tempfile.xml","w+")
xml_output.puts "<?xml-stylesheet type=\"text/xsl\" href=
\"stylesheet.xsl\"?>"
xml_input = File.open(".\\TEST-Results.xml","r")
xml_input.each {|line| xml_output.puts(line)}
xml_input.close
xml_output.close
xml_output = File.open(".\\tempfile.xml","r")
xml_final = File.open(".\\TEST-Results.xml","w+")
xml_output.each {|line| xml_final.puts(line)}
xml_output.close
xml_final.close
File.delete(".\\tempfile.xml")

and here's the batch file (I just call mine Results.bat):
@ECHO OFF
START .\editxml.rb
START .\TEST-Results.xml

Feel free to edit as you like. Hope this makes someone else's testing
life easier like it did mine. :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to