TestNG is a testing framework which is inspired by junit. TestNG is the latest framework of selenium. it gives to complete freedom to write the testcases in group or dependent to the other method. NG  stand for ‘NEXT GENERATION’. testing of next generation.

TestNG gives the lot of advantage over the other testing framework.

1-we  can run the parallel test cases using TestNG.

2-TestNG gives the feature of test annotation.by using annotation we can easily understand.

3-TestNG gives the feature to generate the report in HTML format and also XML format.

TestNG framework we can divide the testcases in three part.




@Beforemethod- In before method we launch the Firefox or chrome driver get the URL.

@Test- In test we execute the main login of our test case.its like a main method.

@Aftermethod- we can write the close or quit method.

We can install the TestNG easily. TestNG plugin easily available for ECLIPSE IDE.

Here is the code of TestNG-

package automationframework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class TestNG {

public WebDriver driver;
public void main() {
System.out.println("Login Successfully, now it is the time to Log Off buddy");

public void beforeMethod() {

driver = new FirefoxDriver();


public void afterMethod() {



TestNG also generate the report in HTML format which are describe the your test case result which emailable-report.html.


TestNG emailable




TestNG reports 2016-01-19 18-21-13

Handle Multiple Test cases in TestNG-

In the end of test we need to execute all the test cases. these test cases dependent to each other. TestNG gives the functionality to execute these test cases simultaneously.

We need to create a testing.xml file which handle multiple test cases.


<suite name ="Test-suite">
<test name = "testng">
<class name = "automationframework.TestNG"/>
<class name = "automationframework.Login"/>

its a very simple XML code first of all we make a <suite> tag where we can define the test suite name after that we write <test> tag where we define test name. we can give the any name of test suite and test case but <class> tag name is combination of package name and test name.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s