How to do TestNG test suite with Hello World test case – step by step explanation given below.

Prerequisite: Eclipse + Maven + Selenium + TestNG Setup
If you already have necessary software setup, jump to step 1. Else refer this link for details about software setup;

Software used are listed below;

Eclipse 4.6.x
JDK 1.8.x
Selenium Java WebDriver 3.4.0
Chrome Driver 2.29
TestNG 6.10

Finally the project should look as below;

Step 1: Create TestNG Suite xml

Create new file TestNGRegressionSuite.xml under src/main/resources folder.

TestNGRegressionSuite.xml provided below

<!DOCTYPE suite SYSTEM "" >
<suite name="RegressionSuite" verbose="1" >
  <test name="RegressionTestCases"   >
      <package name="com.regression" />

Step 2: Create TestNG test class

Create new TestNG test class and name it as In this class setup the system property value. Also open the home page of website.

Create new test method called testProductSearch(). Find Search text box and enter iPhone as search key word.

Complete source code of class provided below

package com.regression;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;

import static org.testng.Assert.assertNotNull;

import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterClass;

public class ProductSearchTest {

  ChromeDriver driver = null;
  public void beforeClass() {
      // Replace with chrome driver absolute path
      System.setProperty("", "/Users/Niranjan/My Briefcase/My Development/eclipse_learning/Selenium/TestingProject/src/main/resources/webdrivers/chromedriver");
      driver = new ChromeDriver();

  public void testProductSearch(){
      WebElement searchElement = driver.findElementById("twotabsearchtextbox");
      // Looking for search results page
      WebElement searchResults = driver.findElementByLinkText("Cell Phones & Accessories");
      // Verify search results page opened and the web element is Not null
  public void afterClass() {


Step 3: Execute TestNG suite xml

Now you can right click on suite xml (TestNGRegressionSuite.xml) and run as – TestNG Suite.

Refer YouTube tutorial with detailed explanation

Finally the project should look as below;

For further reading refer Java Selenium Programming Category posts.

Share this post

How to write TestNG Product Search selenium test case
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *