Selenium with TestNG Setup Tutorial

What is TestNG Framework & How to Setup or Install TestNG Selenium Framework?

TestNG is a testing framework inspired by JUnit & NUnit with many additional features that makes it even more powerful & can help in designing a more robust automation testing framework.

TestNG is designed to cover all categories of tests:  unit, functional, end-to-end, integration, etc…

And, In this TestNG tutorial of ThoughtCoders you will learn “How to install and setup TestNG Selenium Framework” using Java? with step by step process and with a sample TestNG Selenium Framework.

Pre-Requisites:

  1. Java must be installed
  2. Any IDE like – Eclipse, IntelliJ IDEA, etc.
  3. Setup Selenium on System
  4. Browser driver (like- chrome driver, gecko driver, etc. ) must be downloaded

Tutorial on Selenium Installation & Setup: Click Here

Steps to Install and Setup TestNG Selenium Framework:

Install TestNG jar files from “mvnrepository”

  • Step 2: Click on testng 6.14.3 version and download jar file

Now, Create Java project & add Selenium, TestNG dependency or jar file

  • Step 1: Open an IDE (Recommended – IntelliJ) & Create a Java Project
Create java project
  • Step 2: After, setting up Java project, Project structure look like this
Java project structure
  • Step 3: Right click on project folder and click on “Open Module Settings” option
  • Step 4: Go to Module -> “Dependencies” tab -> Click on “+” icon -> Click on Jars or directories
Add Jars or directories in IntelliJ IDE

Note: Enlarge or Zoom above image to see steps to add Jar file

  • Step 5: Browse & Select testng jar file and Click on “Ok” button
testng-6.14.3 jar file
Selenium 3.141.59 version zip download
Selenium API jar files dependencies

Selenium with TestNG Project Structure after Selenium and TestNG Jar dependencies are added:

Selenium with TestNG project structure
  • Step 7: Right click on “src” folder -> Click on New -> “Java class” -> Create Java class file (SampleTest)
Create java class file
SampleTest Java file

Coding our First Test Case

Let’s create our first Test Case that will check if ThoughtCoder’s Blog page is correct. Refer to the code below.

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.*;

public class SampleTest {
    public String baseUrl = "https://thoughtcoders.com/blog";
    public WebDriver driver;

    //Using @Test testng annotation
    @Test
    public void verifyBlog(){
        System.out.println("Launching Browser");
        System.setProperty("webdriver.chrome.driver","C:\\Users\\NEKumar\\Downloads\\drivers\\chromedriver.exe");

        driver = new ChromeDriver();
        driver.navigate().to(baseUrl);
    }
}
SampleTest Java file code & TestNG report window

Hope, this tutorial helped in installation, setup of Selenium with TestNG automation framework, and above SampleTest code clearly given an illustration that how we use TestNG annotation with Selenium to enable extraordinary features & reporting.

We will continue exploring other Selenium with TestNG topics. So, subscribe to our newsletter to stay updated with our next blog.

Subscribe to our Newsletter:

0 0 vote
Article Rating
close

Subscribe to our Newsletter:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Open chat
Feel free to contact