In the previous tutorial, we have discussed about what is TestNG and why it is important. In this tutorial, will discuss how can we download and install TestNG in Eclipse and how to use it.
Pre-Requisite
1) Eclipse should be installed and configure. Please refer Install and Configure to setup Eclipse to your system.
Install/Setup TestNG
1) Launch Eclipse and go to Help option present at the top and select -“Install New Software”.




import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
public class TestNG_Demo {
public WebDriver driver;
@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.gecko.driver","C:\\Users\\vibha\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.amazon.com//");
}
@Test
public void Validation() {
driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']")).sendKeys("hard drive");
//XPath for search button
driver.findElement(By.xpath("//*[@class='nav-input']")).click();
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
5) To execute this program, we need to Right click and select Run as – TestNG Test.

6) The result will look like something shown below. Here, we can see that Test Case Passed is 1, Failed 0 and Skipped 0.

7) As we know that TestNG also produce HTML Reports. To access the report, go to the Eclipse folder and you can see a folder with name test-output inside the Project where we have created TestNG class. Here, it is C:\Users\vibha\Downloads\eclipse-workspace\Demo

8) Open ‘emailable-report.html‘, as this is a html report open it with browser. It will look like something below. TestNG also produce ‘index.html‘ report and it resides in the same test-output folder. This reports gives the link to all the different component of the TestNG reports like Groups& Reporter Output. On clicking these will display detailed descriptions of execution.

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
Great! Very detailed. I enjoy reading this blog. Screenshots make it very easy to understand
LikeLike
Thank You. There are other blogs on TestNG and interview questions asked on TestNG. Have a look and provide your suggestion
LikeLike
Great article on the installation of TestNg. Appreciate the details provided with screenshots
LikeLike