This repository serves as a beginner-friendly guide to Selenium automation testing. We will use the Guru99 website for our test cases, covering essential Selenium concepts like locating elements, interacting with forms, and running automated browser tests.
Before getting started, ensure you have the following installed:
- Java (JDK 8+): Download here
- Maven (for dependencies management): Install guide
- Selenium WebDriver: Included via Maven dependencies
- TestNG (for test execution)
- An IDE (Eclipse, IntelliJ IDEA, or VS Code)
- Google Chrome & ChromeDriver (or other browser drivers)
- Clone the repository:
git clone https://github.com/your-repo/selenium-guru99.git cd selenium-guru99
- Set up dependencies using Maven
Add the following to
pom.xml
:<dependencies> <!-- Selenium WebDriver --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.10.0</version> </dependency> <!-- TestNG --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.8.0</version> <scope>test</scope> </dependency> <dependency> <groupId>bayern.steinbrecher.jcommander</groupId> <artifactId>jcommander</artifactId> <version>1.8.0</version> <scope>test</scope> </dependency> </dependencies>
- Download and place the ChromeDriver in your system path
- Download from here
- Place it in a known directory and add to the system environment variable (PATH)
Create a test file LoginTest.java
under src/test/java/tests/scripts/
:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class LoginTest {
WebDriver driver;
@BeforeTest
public void setup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox");
options.addArguments("--headless");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
@Test
public void testLogin() {
driver.get("https://www.demo.guru99.com/V4/");
WebElement username = driver.findElement(By.name("uid"));
WebElement password = driver.findElement(By.name("password"));
WebElement loginButton = driver.findElement(By.name("btnLogin"));
username.sendKeys("testuid");
password.sendKeys("testpassword");
loginButton.click();
String expectedTitle = "Guru99 Bank Manager HomePage";
Assert.assertEquals(driver.getTitle(), expectedTitle);
}
@AfterTest
public void teardown() {
driver.quit();
}
}
To run tests using TestNG, execute:
mvn test
Or in IntelliJ IDEA:
- Right-click
LoginTest.java
- Select Run 'LoginTest'
- Page Object Model (POM) for better test structuring
- Data-driven testing using TestNG & Excel
- Headless execution for faster testing
- CI/CD integration (Jenkins, GitHub Actions)
This guide provides a foundational start for Selenium automation testing using the Guru99 website. As you progress, explore advanced concepts to enhance your automation skills.
I am currently learning Selenium and automation testing. 🚀