Before this we learn how to configure TestNG from eclipcs(By default TestNG framework comes with NetBeans) and if we run our tests TestNG report generated into the default location. Here we learn how we make more user friendly reporting using TestNG-XSLT.
We follow this Steps:
Step 1:
Download TestNG-XSLT from here and going to File -> Download option
Step 2:
Extract all files from zip folder, after the unzipping it looks like
Step 3:
Just copy the testng-results.xsl from the testng-xslt folder(\testng-xslt-1.1.2-master\src\main\resources) to our own project folder.
Step 4:
Now copy the saxon library from (testng-xslt-1.1.2-master\lib\saxon-8.7.jar) to our own project lib folder.
Step 5:
Now we are do the main thing that is modify build.xml of ant and add the following target to it.
**Please change the path which is marked Red as per directory structure.
Note:
1. testNgXslt.outputDir - Sets the target output directory for the HTML content. This is mandatory and must be an absolute path.
e.g : <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
2. 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.
e.g : <param expression="true" name="testNgXslt.showRuntimeTotals" />
3. 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
e.g : <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
4. 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
e.g : <param expression="true" name="testNgXslt.sortTestCaseLinks" />
5. testNgXslt.reportTitle - Use this setting to specify a title for your HTML reports. This is not a mandatory parameter and defaults to "TestNG Results".
e.g : <param expression="TestName" name="testNgXslt.reportTitle" />
We need to provide the testng-xslt stylesheet the testng-results.xml , the path to the style sheet testng-results.xsl and the output index.html ( Those are here <xslt in="${basedir}/build/test/results/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison"> ) path.
We also add the saxon library to our target classpath else we will get an error. In our case it is the master-classpath.
Now we run the ant target for report generation (in my case "testng-xslt-report") and check the ouput folder configured by us for testng-xslt report.
We follow this Steps:
Step 1:
Download TestNG-XSLT from here and going to File -> Download option
Step 2:
Extract all files from zip folder, after the unzipping it looks like
Step 3:
Just copy the testng-results.xsl from the testng-xslt folder(\testng-xslt-1.1.2-master\src\main\resources) to our own project folder.
Step 4:
Now copy the saxon library from (testng-xslt-1.1.2-master\lib\saxon-8.7.jar) to our own project lib folder.
Step 5:
Now we are do the main thing that is modify build.xml of ant and add the following target to it.
<project name="test" basedir=".">
<property name="LIB" value="${basedir}/lib" />
<property name="BIN" value="${basedir}/bin" />
<path id="master-classpath">
<pathelement location="${BIN}" />
<fileset dir="${LIB}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="testng-xslt-report">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/build/test/results/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<property name="LIB" value="${basedir}/lib" />
<property name="BIN" value="${basedir}/bin" />
<path id="master-classpath">
<pathelement location="${BIN}" />
<fileset dir="${LIB}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="testng-xslt-report">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/build/test/results/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="master-classpath">
</classpath>
</xslt>
</target>
</project>
</classpath>
</xslt>
</target>
</project>
**Please change the path which is marked Red as per directory structure.
Note:
1. testNgXslt.outputDir - Sets the target output directory for the HTML content. This is mandatory and must be an absolute path.
e.g : <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
2. 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.
e.g : <param expression="true" name="testNgXslt.showRuntimeTotals" />
3. 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
e.g : <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
4. 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
e.g : <param expression="true" name="testNgXslt.sortTestCaseLinks" />
5. testNgXslt.reportTitle - Use this setting to specify a title for your HTML reports. This is not a mandatory parameter and defaults to "TestNG Results".
e.g : <param expression="TestName" name="testNgXslt.reportTitle" />
We need to provide the testng-xslt stylesheet the testng-results.xml , the path to the style sheet testng-results.xsl and the output index.html ( Those are here <xslt in="${basedir}/build/test/results/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison"> ) path.
We also add the saxon library to our target classpath else we will get an error. In our case it is the master-classpath.
Now we run the ant target for report generation (in my case "testng-xslt-report") and check the ouput folder configured by us for testng-xslt report.
helped me to fine tune my testng reporting
ReplyDeleteThanks a lot