How to run your test using selenium and TestNG-Intellij IDEA

2 min readJan 13, 2021

Why we use selenium with TestNG?

These two are very powerful automation tools which can make our lives easier while writing testcases. But default selenium is not providing user friendly reports for test. Using selenium with TestNG, we can generate more readable test results.

How we can start?

  1. As the first step, create a maven project in Intellij

File->New-> project->maven

maven project window

2. click on Next button and enter a project name,location,GroupId,Artifactid and Version.

3. Click on finish button and now you have a newly created maven project.

4. Add dependencies related to selenium and TestNG inside the newly created pom.xml

pom.xml with dependencies

How we can write test?

Example :Let’s assume we want to write a test case for login to an web application by a particular user.

  • user enter a valid ID
  • user enter a valid password
  • user logged in to the web application
  • Verify whether user logged in valid url
  1. Create a new Java class and add your test methods. Here is the sample I prepared.
public class TestNg {
public String baseurl="";
public WebDriver driver;
String driverpath="/home/chali/Downloads/geckodriver";
public void LaunchBrowser()
System.out.println("Launching the Web application");
driver=new FirefoxDriver();
public void loginHomepage()
public void verifyHomepage()
String ActualURL=driver.getCurrentUrl();
String ExpectedURL="";

public void closeBrowser()

Sample Output of test execution