My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
XSLParameters  
Configuring the transformer using XSL parameters
Updated Feb 4, 2010 by cosmin...@gmail.com

XSL Parameters

The XSL transformation can be configured using the parameters described below.

  • testNgXslt.outputDir - Sets the target output directory for the HTML content. This is mandatory and must be an absolute path. If you are using the Maven plugin this is set automatically so you don't have to provide it.
  • testNgXslt.cssFile - Specifies and alternative style sheet file overriding the default settings. Read more about this here. This parameter is not required.
  • testNgXslt.showRuntimeTotals - Boolean flag indicating if the report should display the aggregated information about the methods durations. The information is displayed for each test case and aggregated for the whole suite. Non-mandatory parameter, defaults to false.
  • testNgXslt.reportTitle - Use this setting to specify a title for your HTML reports. This is not a mandatory parameter and defaults to "TestNG Results".
  • testNgXslt.sortTestCaseLinks - Indicates whether the test case links (buttons) in the left frame should be sorted alphabetically. By default they are rendered in the order they are generated by TestNG so you should set this to true to change this behavior.
  • testNgXslt.chartScaleFactor - A scale factor for the SVG pie chart in case you want it larger or smaller. Defaults to 1.
  • testNgXslt.testDetailsFilter - Specified the default settings for the checkbox filters at the top of the test details page. Can be any combination (comma-separated) of: FAIL,PASS,SKIP,CONF,BY_CLASS

Setting the XSL Parameters from Maven

Read the MavenPlugin page for detailed information about this.

Comment by xuanngol...@yahoo.ca, Aug 8, 2008

Ant

For the total runtime to be shown at the top of the page, you have to set the testNgXslt.showRuntimeTotals parameter to true as follows:

<param name="testNgXslt.showRuntimeTotals" expression="true"/>
Comment by xuanngol...@yahoo.ca, Sep 5, 2008

How to add SVG in overview.html

Summary of how I did to insert SVG in overview.html:

  • Extract data(failed, passed, skipped) from overview.html using XSL.
  • Convert data extracted into an input file for ChartSVG.
  • Process the input file with ChartSVG.
  • Insert the resulting SVG in overview2.html.

Step by step

1)In testng-results.xsl, change

<xsl:result-document href="{testng:absolutePath('overview.html')}" format="html">

to

<xsl:result-document href="{testng:absolutePath('overview.html')}" method="xhtml">

2)Download ChartSVG from http://www.hardcoded.net/chartsvg/.

Decompress chartsvg.zip. In lib_pie.xsl, comment out

<xsl:script implements-prefix="math"
      language="java"
      src="java:java.lang.Math" />

3)Apply XSL sheets. Here, I use Ant but you can use other XSLT processors.

<!--
////////////////////////////////////
Adapt to your environment.
////////////////////////////////////
-->
<target name="chart">

	<!-- Remove namespaces from overview.html -->
	<xslt in="${basedir}/testng_nice_report/overview.html" style="removeNamespaces.xsl"
	      out="${basedir}/testng_nice_report/overview.xml">
		<classpath refid="myClasspath"/>
	</xslt>	
	
	<!-- Extract data from overview.html and transform the extracted data into ChartSVG input file format. -->
	<xslt in="${basedir}/testng_nice_report/overview.xml" style="overview2chartSvg.xsl"
	      out="${basedir}/testng_nice_report/overview2.csvg">
		<classpath refid="myClasspath"/>
	</xslt>	
	
	<!-- Create SVG using ChartSVG. -->
	<xslt in="${basedir}/testng_nice_report/overview2.csvg" style="chartsvg.xsl"
	      out="${basedir}/testng_nice_report/overview2.svg">
		<classpath refid="myClasspath"/>
	</xslt>
	
	<!-- Copy clean version of overview.html(overview.xml) and insert SVG -->
	<xslt in="${basedir}/testng_nice_report/overview.xml" style="cpNinsert.xsl"
	      out="${basedir}/testng_nice_report/overview2.html">
		<classpath refid="myClasspath"/>
	</xslt>			

</target>

XSL sheets needed

<?xml version="1.0" encoding="UTF-8"?>
<!-- removeNamespaces.xsl: Remove Namespace -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="*">
      <!-- remove element prefix (if any) -->
      <xsl:element name="{local-name()}">
        <!-- process attributes -->
        <xsl:for-each select="@*">
          <!-- remove attribute prefix (if any) -->
          <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates/>
      </xsl:element>
  </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<!--overview2chartSvg.xsl: Extract data from overview.html and transform the extracted data into ChartSVG input file format. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes"></xsl:output>
    
    <xsl:template match="/">
        <xsl:for-each select="//body/table">
            <!--<xsl:value-of select="tr/td[contains(@style, 'FFBBBB')]" />-->
	<xsl:call-template name="ng2svg">
	    <xsl:with-param name="chartName"><!--<xsl:value-of select="tr/td[@width='100%']" />--></xsl:with-param>
	    <xsl:with-param name="failedCnt"><xsl:value-of select="tr/td[contains(@style, 'FFBBBB')]/div" /></xsl:with-param>
	    <xsl:with-param name="passedCnt"><xsl:value-of select="tr/td[contains(@style, 'lightgreen')]/div" /></xsl:with-param>
	    <xsl:with-param name="skippedCnt"><xsl:value-of select="tr/td[contains(@style, 'FFFFBB')]/div" /></xsl:with-param>
	</xsl:call-template>
	    
        </xsl:for-each>	
    </xsl:template>
    
    <xsl:template name="ng2svg">
        <xsl:param name="chartName"/>
        <xsl:param name="failedCnt"/>
        <xsl:param name="passedCnt"/>
        <xsl:param name="skippedCnt"/>
	
	<!-- ChartSVG input file format -->
	<hsgraph>
		<title><xsl:value-of select="$chartName"/></title> 
		<charttype>pie</charttype> 
		<showlegend chartfitpos="0" showpercent="y"/> 
		<bgcolor>white</bgcolor> 
		<series showvalues="y"> 
			<serie explode="y"> 
				<name>Failed</name> 
				<color>red</color> 
				<xsl:element name="point">
				    <xsl:attribute name="x">0</xsl:attribute>
				    <xsl:attribute name="y"><xsl:value-of select="$failedCnt"></xsl:value-of></xsl:attribute>
				</xsl:element>
				
			</serie>
			
			<serie> 
				<name>Passed</name> 
				<color>green</color> 
				<xsl:element name="point">
				    <xsl:attribute name="x">0</xsl:attribute>
				    <xsl:attribute name="y"><xsl:value-of select="$passedCnt"></xsl:value-of></xsl:attribute>
				</xsl:element>
			</serie>
			
			<serie> 
				<name>Skipped</name> 
				<color>yellow</color> 
				<xsl:element name="point">
				    <xsl:attribute name="x">0</xsl:attribute>
				    <xsl:attribute name="y"><xsl:value-of select="$skippedCnt"></xsl:value-of></xsl:attribute>
				</xsl:element>
			</serie>
		</series>
	</hsgraph>	
	
	
    </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<!-- cpNinsert.xsl: Copy clean version of overview.html(overview.xml) and insert SVG -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="html" version="2.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="table/tr[last()]">
        <xsl:element name="tr">
	<xsl:element name="td">
		<xsl:attribute name="align">center</xsl:attribute>
		<xsl:attribute name="colspan">6</xsl:attribute>
		    <xsl:element name="embed">
			<xsl:attribute name="src">overview2.svg</xsl:attribute>
			<xsl:attribute name="type">image/svg+xml</xsl:attribute>
			<xsl:attribute name="name">emap</xsl:attribute>
			<xsl:attribute name="width">800</xsl:attribute>
			<xsl:attribute name="height">600</xsl:attribute>
		    </xsl:element>
	</xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
Comment by project member cosmin...@gmail.com, Jan 17, 2009

TestNG-XSLT now supports SVG reports out of the box, so the above method is not necessary if you need a pie chart with the results overview.

Thanks to Xuan for the suggestions and the help to get this working.

Comment by aostadsa...@gmail.com, Dec 18, 2011

In the report that I generate, there is no pie chart. Based on the last comment, the pie chart (SVG report) should work in TestNG out of the box. Just wondering what I'm missing. Is there any library that need to be added to my environment other than saxon?

Comment by aostadsa...@gmail.com, Dec 18, 2011

OK. It does not work with IE8 but works fine with googlechrome. I think a SVG viewer plugin is needed for IE8. I couldn't find it yet.

Comment by asksan...@gmail.com, Feb 6, 2012

hai, i am new to maven.but i need to create the test report in the form of pie chart. can u share the details of pom.xml along with corresponding xslt stylesheets, please.......


Sign in to add a comment
Powered by Google Project Hosting