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

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

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


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



Software Quality Assurance Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store