Create TestNG Project In Eclipse & Run Selenium Test Script

Create TestNG Project In Eclipse

Adding Selenium JAR files To Selenium TestNG Project

Creating a TestNG class in Eclipse

Writing Our First Test Case Using Selenium and TestNG

package testNG;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;

public class TestNGTestOne {

WebDriver driver;

@Test
public void f() {
//Setting up the chrome driver exe, the second argument is the location where you have kept the driver in your system
System.setProperty("webdriver.chrome.driver", "E:\\Softwares\\chromedriver.exe");

//Setting the driver to chrome driver
driver = new ChromeDriver();
String url = "https://www.google.com";
driver.get(url);
//Capturing the title and validating if expected is equal to actual
String expectedTitle = "Google";
String actualTitle = driver.getTitle();
Assert.assertEquals(actualTitle, expectedTitle);
}
@BeforeMethod
public void beforeMethod() {
System.out.println("Starting the browser session");
}

@AfterMethod
public void afterMethod() {
System.out.println("Closing the browser session");
driver.quit();
}
}

Running Selenium TestNG Script

TestNG Reports and Results

Bonus Pointer: Use A Cloud Selenium Grid For Parallel Testing

--

--

--

I am a Computer Science Engineer by degree, and a Digital Marketer by heart who works at LambdaTest. A social media maven!!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introduction to Docker and Kubernetes on GCP with Hands-on Configuration (Part 1 — Docker)

How to setup a GNU development Environment on all Platforms

Image of VSCodes settings with the line below pasted in.

Must-Read Books for Software Developers

How I used Github Actions to automatically update my Covid-19 dashboard every morning

AWS EKS and TLS terminated Load Balancer

Get Your Cloud Migration Strategy Right the First Time Around

First time deploying my app

How we made parsing BSON cost no overhead performance

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
Praveen Mishra

Praveen Mishra

I am a Computer Science Engineer by degree, and a Digital Marketer by heart who works at LambdaTest. A social media maven!!

More from Medium

Basic Selenium Web Testing Tutorial

Login automation using Selenium WebDriver: Tutorial

Creating our First project to Run Selenium script in Jenkins

Run Project On Jenkins