TestNG setup using Maven for Selenium

Reading Time: 3 minutes


TestNG (Test Next Generationis) is an open source testing framework. TestNG is inspired from JUnit and NUnit. It is an improvised framework which makes it more powerful and easier. It provides the developer to write more powerful and flexible tests with the help of easy annotations, sequencing, grouping and parametrization. We can use TestNG for generating reports. The reports generated will be of two types pass and fail. If we wish we can run any of the report anytime.

Maven was created to have a standard way in which Projects can be built. One of its powerful features is dependency management. IntelliJ IDEA has in-built support for Maven.

Isn’t it great to use TestNG and Maven together Lets get started with TestNG setup using Maven for Selenium


  • Java
  • Inellij

Don’t worry if the prerequisites are not installed. You can refer to my previous blog.


How to import Maven project in Intellij IDEA?

  • Go to File > Project
  • Select Maven and Project SDK to java package and click next.
  • Add GroupId, ArtifactId and click next. We should add a project name after clicking next. We are ready to implement.
  • Go to Pom.xml and add dependencies for TestNg, Maven, Selenium
  • We have to add selenium Java in Pom.xml from the below external link.
  • For TestNg go to the below link.
  • Copy the dependencies and paste in POM.xml. Now you will get option to import the dependencies. Do that.

How to use TestNg annotations ?

  • If you are not aware of the format used for TesntNg, stay calm and use the below format.
@DataProvider (name = “name_of_dataprovider”)
public Object[][] dpMethod() {
return new Object [][] { values}
  • Good going. Now you have to create a java project and implement the below example. Run the code as TestNGTest
import org.testng.annotations.Parameters; import org.testng.annotations.Test; import org.openqa.selenium.By;
public class MyFirstTestNg { @DataProvider (name = “data-provider”) public Object[][] dataMethod(){ return new Object[][] {{“FirstName”}, {“SecondName”}}; }
@Test (dataProvider = “data-provider”) public void test (String val) { System.out.println(“Passed Parameter Is : “+ val); } }
  • Run the above example as Run As -> TestNG Test.Run testing.xml and check the output.
<suite name = “Suite”> <test name=” Test”>
<classes> <class name = “Code.MyFirstTestNg”>
</class> </classes> </test> </suite>
  • You should run testing.xml and after running you check the output

Congratulations we have completed a data driven program with the help of TestNg hence TestNG setup using Maven for Selenium





Written by 

I work with Knoldus and have experience of 8+ years in quality assurance I have good experience on SeleniumWebdriver(C#), Selenium IDE, Nightwatch,Appium, Jira, TFS, ZAP, Fiddler, Jmeter, Jenkins, Selenium Webdriver. I am also ITIL certified.