Selenium result report + testNG + ANT build.xml

In this post, we will see how to convert testng report (index.html) to a more readable/emailable report by using ANT build and build.xml.
We will see how we can generate the following report[screenshot] after done the required steps:














Things Required:

Eclipse IDE -
If you are new, please follow this link
Create 4 .java files such a way that: 2 successful, 1 skipped and 1 failed on run
testcase1: pass
1
2
3
4
5
6
7
package tcs;
import org.testng.annotations.Test;
public class tc1 {
    @Test
    public void method1(){
    System.out.println("tc1: testcase1");}
}
testcase2: pass
1
2
3
4
5
6
7
package tcs;
import org.testng.annotations.Test;
public class tc2 {
 @Test
 public void method1(){
 System.out.println("tc2: testcase2");}
}
testcase3: failed
1
2
3
4
5
6
7
8
9
package tcs;
import org.testng.annotations.Test;
public class tc3 {
 @Test
 public void method1(){
 int i = 5/0;
 System.out.println(i+"testcase3");
 }
}
testcase4: skipped
1
2
3
4
5
6
7
8
package tcs;
import org.testng.SkipException;
import org.testng.annotations.Test;
public class tc4 {
 @Test
 public void method1(){
 throw new SkipException("skipped: testcase4");}
}

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:
Environmental setup for ANT:
Add / Edit System variables "path" as: append the "apache ANT" extracted folder path as value.
path = C:\apache-ant-1.9.4\bin (consider the extracted file is on C:\ drive)
To know how to update environmental variable, click here.

build.xml and testng-results.xsl:
Download from here and place under your project folder.

How to Run the build.xml:
1) After all the above setup is done, Right click on the build.xml and select "Run As", click on "Ant Build...", a dialog appears to select and execute the required targets.
2) Even we can run the build.xml from the command prompt:

On the current directory (location, where your project resides), Hold "Shift key" and Right click on the directory and select option "Open command window here" and type the following command to execute build.xml or tests

            let's say my project is under c:\
            c:\myproject > ant -buildfile build.xml and press Enter (this will execute the default target)
            To execute particular target (let's say I have a target "GenerateReport"
             c:\myproject > ant -buildfile build.xml GenerateReport and click on Enter

Customized html report page - open from folder /XSLT_Reports/output/index.html to see the report as shown in the beginning.


11 comments:

  1. Testing is the only way to deliver reliable products in the Information Technology market. Articles like this are vital in improvising one's ability as a software testing professional. Thank you so much for sharing this information in here. Keep blogging.

    Software testing training in chennai | Software testing training | Software testing training chennai | Software testing course chennai

    ReplyDelete
  2. Automation will make any work to be completed so soon(Selenium training in chennai), in addition to this recording the actions is possible with automated tool. Your content explicitely states the same(Selenium testing training). Thanks for sharing this worth able content in here. This was very useful to me as well. Keep blogging like this.

    ReplyDelete
  3. GSSSB 2480 Revenue Talati Bharti Recruitment 2016

    Very well written information. It will be beneficial to anyone who utilizes it, Keep up the good work.

    ReplyDelete
  4. Assam 2564 Police Constable Recruitment 2016 Apply Online


    I go to see everyday a few web pages and information sites to read posts, however this blog gives quality based articles...........

    ReplyDelete
  5. Hi, I am really happy to found such a helpful and fascinating post that is written in well manner. Thanks for sharing such an informative post. keep update your blog. Selenium Training in Chennai

    ReplyDelete
  6. Technology place a vital part in humans ecosystem. So in order to survive one must be up to date. Thanks for sharing this information in here. Keep blogging article like this. I have bookmarked this page for future reference.

    Hadoop Training Chennai | Hadoop Training in Chennai | JAVA training in Chennai

    ReplyDelete
  7. Hi, This is really nice blog. You have done really great job. Keep posting.
    Regards..
    QTP Training in Chennai

    ReplyDelete
  8. Awesome article to nice sharing Training and certification on courses helps you to study this technology in featurebest selenium training in chennai

    ReplyDelete

  9. I am happy to found such helpful and fascinating post that is written in well manner.
    QTP Training in Chennai | Software Testing Training in Chennai | Selenium Training in Chennai

    ReplyDelete