Changing the Test Case Detailed Report to show only latest test run

Thursday, April 19, 2018
Avatar

We had a request from a customer to change the built-in test case detailed report:

The Test Case Detailed report is very close to what we need, BUT it shows multiple test runs for a single test case.  When a test run results in a failure or a caution, even though there is a retest shown immediately after it, that’s not acceptable to the reviewing folks.

So in this post we include the XSLT template changes needed to accomplish this.

5 Replies
Thursday, April 19, 2018
Avatar
re: inflectra.david Thursday, April 19, 2018

The standard test case detailed report contains the following XSLT section that displays the list of test runs for the current test case:

       <xsl:if test="TestRuns/TestRun">
          <div class="Title4">
            Test Runs:
          </div>
          <table class="DataGrid">
            <tr>
              <th>Run #</th>
              <th>Tester</th>
              <th>Test Set</th>
              <th>Release</th>
              <th>Version</th>
              <th>Status</th>
              <th>Type</th>
              <th>Automation Host</th>
              <th>Est. Duration</th>
              <th>Actual Duration</th>
              <th>Execution Date</th>
            </tr>
            <xsl:for-each select="TestRuns/TestRun">
              <tr>
                <td>
                  TR<xsl:value-of select="TestRunId"/>
                </td>
                <td>
                  <xsl:value-of select="TesterName"/>
                </td>
                <td>
                  <xsl:value-of select="TestSetName"/>
                </td>
                <td>
                  <xsl:value-of select="ReleaseName"/>
                </td>
                <td>
                  <xsl:value-of select="ReleaseVersionNumber"/>
                </td>
                <td>
                  <xsl:value-of select="ExecutionStatusName"/>
                </td>
                <td>
                  <xsl:value-of select="TestRunTypeName"/>
                </td>
                <td>
                  <xsl:value-of select="AutomationHostName"/>
                </td>
                <td class="Timespan">
                  <xsl:value-of select="EstimatedDuration"/>
                </td>
                <td class="Timespan">
                  <xsl:value-of select="ActualDuration"/>
                </td>
                <td class="Date">
                  <xsl:call-template name="format-date">
                    <xsl:with-param name="datetime" select="EndDate" />
                  </xsl:call-template>
                </td>
              </tr>
              <xsl:if test="TestRunSteps/TestRunStep">
                <tr>
                  <td colspan="11">
                    <table class="DataGrid">
                      <tr>
                        <th>Step</th>
                        <th>Description</th>
                        <th>Expected Result</th>
                        <th>Sample Data</th>
                        <th>ActualResult</th>
                        <th>Status</th>
                      </tr>
                      <xsl:for-each select="TestRunSteps/TestRunStep">
                        <tr>
                          <td>
                            <xsl:value-of select="Position"/>
                          </td>
                          <td>
                            <xsl:value-of select="Description" disable-output-escaping="yes"/>
                          </td>
                          <td>
                            <xsl:value-of select="ExpectedResult" disable-output-escaping="yes"/>
                          </td>
                          <td>
                            <xsl:value-of select="SampleData" disable-output-escaping="yes"/>
                          </td>
                          <td>
                            <xsl:value-of select="ActualResult" disable-output-escaping="yes"/>
                          </td>
                          <td>
                            <xsl:value-of select="ExecutionStatusName"/>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>
        </xsl:if>

You would simply change the selector to only find the first match. I.e. you change:

            <xsl:for-each select="TestRuns/TestRun">

to

            <xsl:for-each select="TestRuns/TestRun[1]">

 

Wednesday, August 5, 2020
Avatar
re: inflectra.david Thursday, April 19, 2018

Hi David,

The solution you have provided below just shows one test run for single test . Let's say we have 10 tests and each test is executed multiple times, now we want to show the latest execution of all 10 tests. But the below solution shows test run only for 1 test and doesn't show test runs for the remaining 9 tests. Could you please help with that?

Regards,

Ram

Thursday, August 6, 2020
Avatar
re: rmopuram Wednesday, August 5, 2020

The test case detailed report can be used to show 1 or many test cases. The example code change is in a foreach loop - so for each test case included in the report it will only show one test run.

Thursday, August 6, 2020
Avatar
re: inflectra.clark Thursday, August 6, 2020

Hi Clark, I am using test run details report and i want to show only the latest test run for all the test cases. My xslt is below, could you please suggest what exactly i need to do.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:template match="/TestRunData">
    <xsl:for-each select="TestRun">
      <div class="Title2">
        Test Run TR:<xsl:value-of select="TestRunId"/> - <xsl:value-of select="Name"/>
      </div>
      <div class="Description">
        <xsl:value-of select="Description" disable-output-escaping="yes"/>
      </div>
      <table class="HiddenTable">
        <tr>
          <th>Test Case #:</th>
          <td>
            TC<xsl:value-of select="TestCaseId"/>
          </td>
          <td colspan="2"></td>
        </tr>
        <tr>
          <th>Release #:</th>
          <td>
            <xsl:value-of select="ReleaseVersionNumber"/>
            <xsl:if test="BuildName">
              (Build: <xsl:value-of select="BuildName"/>)
            </xsl:if>
          </td>
          <th>Status:</th>
          <td>
            <xsl:value-of select="ExecutionStatusName"/>
          </td>
        </tr>
        <tr>
          <th>Tester:</th>
          <td>
            <xsl:value-of select="TesterId"/>
          </td>
          <th>Execution Date:</th>
          <td class="Date">
            <xsl:call-template name="format-date">
              <xsl:with-param name="datetime" select="StartDate" />
            </xsl:call-template>
          </td>
        </tr>
        <tr>
          <th>Test Set:</th>
          <td>
            <xsl:value-of select="TestSetName"/>
          </td>
        </tr>
      </table>
      <xsl:if test="TestRunSteps/TestRunStep">
        <table class="DataGrid">
          <tr>
            <th>Step</th>
            <th>Description</th>
            <th>Expected Result</th>
            <th>Sample Data</th>
            <th>Status</th>
          </tr>
          <xsl:for-each select="TestRunSteps/TestRunStep">
            <tr>
              <td>
                <xsl:value-of select="Position"/>
              </td>
              <td>
                <xsl:value-of select="Description" disable-output-escaping="yes"/>
              </td>
              <td>
                <xsl:value-of select="ExpectedResult" disable-output-escaping="yes"/>
              </td>
              <td>
                <xsl:value-of select="SampleData" disable-output-escaping="yes"/>
              </td>
              <td>
                <xsl:value-of select="ExecutionStatusName"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </xsl:if>
      <xsl:if test="Incidents/Incident">
        <div class="Title3">
          Associated Incidents:
        </div>
        <table class="DataGrid">
          <tr>
            <th>Inc #</th>
            <th>Type</th>
            <th>Status</th>
            <th>Priority</th>
            <th>Severity</th>
            <th>Name</th>
            <th>Owned By</th>
            <th>Detected On</th>
          </tr>
          <xsl:for-each select="Incidents/Incident">
            <tr>
              <td>
                <xsl:value-of select="IncidentId"/>
              </td>
              <td>
                <xsl:value-of select="IncidentTypeName"/>
              </td>
              <td>
                <xsl:value-of select="IncidentStatusName"/>
              </td>
              <td>
                <xsl:value-of select="PriorityName"/>
              </td>
              <td>
                <xsl:value-of select="SeverityName"/>
              </td>
              <td>
                <xsl:value-of select="Name"/>
              </td>
              <td>
                <xsl:value-of select="OwnerName"/>
              </td>
              <td class="Date">
                <xsl:call-template name="format-date">
                  <xsl:with-param name="datetime" select="CreationDate" />
                </xsl:call-template>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </xsl:if>
      <xsl:if test="Attachments/Attachment">
        <div class="Title3">
          File Attachments:
        </div>
        <table class="DataGrid">
          <tr>
            <th>Filename</th>
            <th>src</th>
            <th>Date Uploaded</th>
          </tr>
          <xsl:for-each select="Attachments/Attachment">
            <tr>
              <td>
                <xsl:value-of select="Filename"/>
              </td>
              <td>
                    <img>
                        <xsl:attribute name="src">
                        https://spiratest.com/SpiraTeam/<xsl:value-of select="ProjectId" />/Attachment/<xsl:value-of select="AttachmentId" />.aspx
                        </xsl:attribute> 
                    </img>
              </td>
              <td class="Date">
                <xsl:call-template name="format-date">
                  <xsl:with-param name="datetime" select="UploadDate" />
                </xsl:call-template>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </xsl:if>
      <br/>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="format-date">
    <xsl:param name="datetime"/>
    <xsl:variable name="date" select="substring-before($datetime, 'T')" />
    <xsl:variable name="year" select="substring-before($date, '-')" />
    <xsl:variable name="month" select="substring-before(substring-after($date, '-'), '-')" />
    <xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
    <xsl:variable name="time" select="substring-before(substring-after($datetime, 'T'), '.')" />
    <xsl:variable name="monthname">
      <xsl:choose>
        <xsl:when test="$month='01'">
          <xsl:value-of select="'Jan'"/>
        </xsl:when>
        <xsl:when test="$month='02'">
          <xsl:value-of select="'Feb'"/>
        </xsl:when>
        <xsl:when test="$month='03'">
          <xsl:value-of select="'Mar'"/>
        </xsl:when>
        <xsl:when test="$month='04'">
          <xsl:value-of select="'Apr'"/>
        </xsl:when>
        <xsl:when test="$month='05'">
          <xsl:value-of select="'May'"/>
        </xsl:when>
        <xsl:when test="$month='06'">
          <xsl:value-of select="'Jun'"/>
        </xsl:when>
        <xsl:when test="$month='07'">
          <xsl:value-of select="'Jul'"/>
        </xsl:when>
        <xsl:when test="$month='08'">
          <xsl:value-of select="'Aug'"/>
        </xsl:when>
        <xsl:when test="$month='09'">
          <xsl:value-of select="'Sep'"/>
        </xsl:when>
        <xsl:when test="$month='10'">
          <xsl:value-of select="'Oct'"/>
        </xsl:when>
        <xsl:when test="$month='11'">
          <xsl:value-of select="'Nov'"/>
        </xsl:when>
        <xsl:when test="$month='12'">
          <xsl:value-of select="'Dec'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="''" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="concat($day, '-' ,$monthname, '-', $year , ' ', $time)" />
  </xsl:template>
</xsl:stylesheet>

Thursday, August 6, 2020
Avatar
re: rmopuram Thursday, August 6, 2020

This is not how the test run report works. To get this functionality you will need to write a fully custom report. You can learn more about that here: http://spiradoc.inflectra.com/Reporting/Custom-Report-Tutorial/

 

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Thursday, April 19, 2018
  • Last Reply: Thursday, August 6, 2020
  • Replies: 5
  • Views: 6987