How do you Handle reporting in your project ?
Method 1 : Maven - Testng - Surefire report
The project will be created in Maven with SureFire Plugin and SuiteXmlFile tag in the POM.xml . The testng.xml will be called in the POM.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>
C:\Users\har\InterviewTraining\MavenXslt\testng.xml
</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>
true
</testFailureIgnore>
</configuration>
</plugin>
The Report will be generated in the target/surefire-reports folder
Report will be generated like below ( index.html)
Method 2 : Maven - Testng - XSLT report
Step 1: Generate above report using Maven - Surefire plugin
Step 2 : Download testng-xslt project from below link or some other link which is available. Use Download Zip link on this to download the project in zip file
https://github.com/prashanth-sams/testng-xslt-1.1.2
Step 3 : Copy the "testng-results.XSL" from the TestNG package to your base directory i.e, your project folder. "testng-results.XSL" will be available at [..\testng-xslt-1.1.2-master\src\main\resources]
Step 4 : Create a lib folder in you project and put copy the saxon library from (testng-xslt-1.1.2-master\testng-xslt-1.1.2-master\lib) to your project lib folder.
Step 5: .Now add build.xml in your maven project with below content. This is just to run the "testng-xslt-report" target.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="anttest" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${ws.home}/lib" />
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${ws.home}/Reports"/>
<property name="test.resources" value="${ws.home}/src/test/resources"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<pathelement location="${ws.home}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${ws.jars}">
<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}/target/surefire-reports/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
<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="testcase.path">
</classpath>
</xslt>
</target>
</project>
Step 6 : Now run your Maven project with mvn clean compile test , which will generate the testng-results.xml in target directory
Step 7 : Now you run ANT target "ant testng-xslt-report"
Step 8 : Above step will generate index.html in the testng-xslt report.
Step 9 : Open index.html in web browser.
Method 3 : Customized HTML report
Customized HTML report can also be generated by writing a java code generated HTML file at the run time, based upon the steps/status of test cases.
Method 4 : Test Report in Excel file
The status of Test Cases can also be sent to Excel file to generate a report.
Method 1 : Maven - Testng - Surefire report
The project will be created in Maven with SureFire Plugin and SuiteXmlFile tag in the POM.xml . The testng.xml will be called in the POM.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>
C:\Users\har\InterviewTraining\MavenXslt\testng.xml
</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>
true
</testFailureIgnore>
</configuration>
</plugin>
The Report will be generated in the target/surefire-reports folder
Report will be generated like below ( index.html)
Method 2 : Maven - Testng - XSLT report
Step 1: Generate above report using Maven - Surefire plugin
Step 2 : Download testng-xslt project from below link or some other link which is available. Use Download Zip link on this to download the project in zip file
https://github.com/prashanth-sams/testng-xslt-1.1.2
Step 3 : Copy the "testng-results.XSL" from the TestNG package to your base directory i.e, your project folder. "testng-results.XSL" will be available at [..\testng-xslt-1.1.2-master\src\main\resources]
Step 4 : Create a lib folder in you project and put copy the saxon library from (testng-xslt-1.1.2-master\testng-xslt-1.1.2-master\lib) to your project lib folder.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="anttest" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${ws.home}/lib" />
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${ws.home}/Reports"/>
<property name="test.resources" value="${ws.home}/src/test/resources"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<pathelement location="${ws.home}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${ws.jars}">
<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}/target/surefire-reports/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
<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="testcase.path">
</classpath>
</xslt>
</target>
</project>
Step 6 : Now run your Maven project with mvn clean compile test , which will generate the testng-results.xml in target directory
Step 7 : Now you run ANT target "ant testng-xslt-report"
Step 8 : Above step will generate index.html in the testng-xslt report.
Step 9 : Open index.html in web browser.
Method 3 : Customized HTML report
Customized HTML report can also be generated by writing a java code generated HTML file at the run time, based upon the steps/status of test cases.
Method 4 : Test Report in Excel file
The status of Test Cases can also be sent to Excel file to generate a report.
-----------------------------------------------------------------------------------------------------------
XSLT report in Selenium
XSLT: XML STYLESHEET LANGUAGE TRANSFORMATION
When we execute our project using TestNg.xml, it automatically create a basic html report and testng-results.xml.XSLT is going to use this testing-result.xml and transform into better htmlreport
Steps to Generate XSLT reports
Step1: Create a project having test cases like
- Pass
- Fail
- Skip
Create 4 .java files such a way that: 2 successful, 1 skipped and 1 failed on run
testcase1: pass
package test;
import org.testng.annotations.Test;
import org.testng.annotations.Test;
public class passtc {
@Test
public void passresult()
{
System.out.println("Pass");
}
}
testcase2: pass
package test;
import org.testng.annotations.Test;
public class passtc1 {
@Test
public void show()
{
System.out.println("Testcase2 passed");
}
}
testcase3: failed
package test;
import org.testng.annotations.Test;
import org.testng.AssertJUnit;
import org.testng.Assert;
import org.testng.annotations.Test;
public class failtc {
@Test
public void failresult()
{
System.out.println("Fail");
AssertJUnit.assertEquals("Fail", "Pass");
}
}
testcase4: skipped
package test;
import org.testng.SkipException;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class skiptc {
@BeforeTest
public void intlize()
{
System.out.println("this test will skip");
}
@Test
public void skip()
{
throw new SkipException("Skipped");
}
}
After creating above testclasses your project look like below
testng.xml
Right click on the project, select "TestNG" and click on "Convert to TestNG" to create the testng.xml and place under project folder.
ANT build
Download the latest zip file from here,
Extract and keep it in a easily accessible folder and follow below steps:
Comments
Post a Comment