You are a QA Lead, and I need your help to create a complete automation framework for the following scenario. The framework should use Java, Selenium WebDriver, Maven, and TestNG, and it must be structured so it can be implemented in a real QA automation project.
The web URL should be read from a text file.
Here is the application URL:
https://ifewsteps.web.app/login-qa/
The page contains a username and password field.
- Username: fewsteps
- Password: paassword
A user can log in successfully only after clicking the login button. If incorrect credentials are entered, an error should appear and access should be denied.
The framework must also include:
- Allure reporting
- Jenkins pipeline integration
- Data-driven login using Excel or JSON
- Parallel test execution setup
Please explain the solution briefly and in detail.
Solution 1:
Got it โ you want the same full automation framework, but with clear, short, clean explanations below each section, so you understand what each part does.
Here is the improved version โ FULL CODE + STEP-BY-STEP EXPLANATION, clean and professional.
๐ COMPLETE TEST AUTOMATION FRAMEWORK (WITH EXPLANATIONS)
Java + Selenium + TestNG + Maven + Allure + Jenkins + Data-Driven + Parallel Execution
=====================================
โ 1. PROJECT STRUCTURE
=====================================
automation-framework/
โ
โโโ pom.xml
โโโ Jenkinsfile
โ
โโโ src
โ โโโ main/java/com/framework/base
โ โ โโโ BaseTest.java
โ โ โโโ DriverFactory.java
โ โ
โ โโโ main/java/com/framework/utils
โ โ โโโ FileUtils.java
โ โ โโโ JsonReader.java
โ โ
โ โโโ main/resources
โ โ โโโ url.txt
โ โ โโโ testdata.json
โ โ
โ โโโ test/java/com/framework/pages
โ โ โโโ LoginPage.java
โ โ
โ โโโ test/java/com/framework/tests
โ โ โโโ LoginTest.java
โ โ
โ โโโ test/resources
โ โโโ testng.xml
๐ EXPLANATION
- base/ โ WebDriver setup
- pages/ โ Page Objects (UI locators + actions)
- tests/ โ TestNG test files
- utils/ โ Helper classes (JSON, URL reader)
- resources/ โ Test data & config
- testng.xml โ Controls parallel execution
- Jenkinsfile โ CI/CD pipeline
- pom.xml โ All dependencies
=====================================
โ 2. POM.XML (DEPENDENCIES + PLUGINS)
=====================================
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>qa.framework</groupId>
<artifactId>automation</artifactId>
<version>1.0</version>
<dependencies>
<!-- Selenium WebDriver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.25.0</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
</dependency>
<!-- Allure Reporting -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.25.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Run TestNG from Maven -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<!-- Allure plugin -->
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.12.0</version>
</plugin>
</plugins>
</build>
</project>
๐ EXPLANATION
- Adds Selenium, TestNG, Jackson JSON, Allure
- Surefire plugin allows Maven to run TestNG
- Allure plugin generates reporting files
=====================================
โ 3. URL TEXT FILE
=====================================
๐ src/main/resources/url.txt
https://ifewsteps.web.app/login-qa/
๐ EXPLANATION
This file stores the URL so tests are not hard-coded. You can switch QA โ UAT โ PROD without changing code.
=====================================
โ 4. TEST DATA (JSON)
=====================================
๐ testdata.json
{
"validLogin": {
"username": "fewsteps",
"password": "paassword"
},
"invalidLogin": {
"username": "wrong",
"password": "bad"
}
}
๐ EXPLANATION
This file contains multiple sets of login credentials used for data-driven testing.
=====================================
โ 5. DRIVER FACTORY (WebDriver Manager)
=====================================
๐ DriverFactory.java
package com.framework.base;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DriverFactory {
private static ThreadLocal<WebDriver> driver = new ThreadLocal<>();
public static WebDriver getDriver() {
return driver.get();
}
public static void initDriver() {
WebDriver wd = new ChromeDriver();
driver.set(wd);
wd.manage().window().maximize();
}
public static void quitDriver() {
getDriver().quit();
driver.remove();
}
}
๐ EXPLANATION
- ThreadLocal enables parallel execution
- initDriver() launches Chrome
- quitDriver() closes driver safely
- getDriver() is used everywhere
=====================================
โ 6. BASE TEST
=====================================
๐ BaseTest.java
package com.framework.base;
import com.framework.utils.FileUtils;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class BaseTest {
@BeforeMethod
public void setUp() {
DriverFactory.initDriver();
DriverFactory.getDriver().get(FileUtils.readUrl());
}
@AfterMethod
public void tearDown() {
DriverFactory.quitDriver();
}
}
๐ EXPLANATION
- Runs before every test
- Opens browser and loads URL
- After each test, closes browser
=====================================
โ 7. UTILITY: READ URL FROM FILE
=====================================
๐ FileUtils.java
package com.framework.utils;
import java.nio.file.Files;
import java.nio.file.Paths;
public class FileUtils {
public static String readUrl() {
try {
return Files.readString(Paths.get("src/main/resources/url.txt")).trim();
} catch (Exception e) {
throw new RuntimeException("Error reading URL file");
}
}
}
๐ EXPLANATION
Reads the application URL from url.txt.
Simple, clean, reusable.
=====================================
โ 8. UTILITY: JSON DATA READER
=====================================
๐ JsonReader.java
package com.framework.utils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
public class JsonReader {
public static Map<String, String> getCredentials(String key) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(new File("src/main/resources/testdata.json"));
Map<String, String> data = new HashMap<>();
data.put("username", root.get(key).get("username").asText());
data.put("password", root.get(key).get("password").asText());
return data;
} catch (Exception e) {
throw new RuntimeException("Cannot read JSON test data");
}
}
}
๐ EXPLANATION
- Loads JSON test file
- Returns username & password for any test scenario
=====================================
โ 9. PAGE OBJECT MODEL (POM)
=====================================
๐ LoginPage.java
package com.framework.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class LoginPage {
WebDriver driver;
By username = By.id("username");
By password = By.id("password");
By loginBtn = By.id("loginBtn");
By errorMsg = By.id("errorMessage");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public void enterUsername(String user) {
driver.findElement(username).sendKeys(user);
}
public void enterPassword(String pass) {
driver.findElement(password).sendKeys(pass);
}
public void clickLogin() {
driver.findElement(loginBtn).click();
}
public boolean isErrorVisible() {
try {
return driver.findElement(errorMsg).isDisplayed();
} catch (Exception e) {
return false;
}
}
}
๐ EXPLANATION
This is the Page Object for the login page:
- Locators stored as variables
- Functions represent user actions
- Clean separation from tests
=====================================
โ 10. TEST CASES
=====================================
๐ LoginTest.java
package com.framework.tests;
import com.framework.base.BaseTest;
import com.framework.base.DriverFactory;
import com.framework.pages.LoginPage;
import com.framework.utils.JsonReader;
import org.testng.Assert;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest {
@Test
public void validLoginTest() {
LoginPage login = new LoginPage(DriverFactory.getDriver());
var data = JsonReader.getCredentials("validLogin");
login.enterUsername(data.get("username"));
login.enterPassword(data.get("password"));
login.clickLogin();
Assert.assertFalse(login.isErrorVisible(), "No error expected on valid login");
}
@Test
public void invalidLoginTest() {
LoginPage login = new LoginPage(DriverFactory.getDriver());
var data = JsonReader.getCredentials("invalidLogin");
login.enterUsername(data.get("username"));
login.enterPassword(data.get("password"));
login.clickLogin();
Assert.assertTrue(login.isErrorVisible(), "Error expected on invalid login");
}
}
๐ EXPLANATION
- Uses JSON data
- Interacts through Page Object
- Uses TestNG assertions
- Valid login โ no error
- Invalid login โ error visible
=====================================
โ 11. PARALLEL EXECUTION
=====================================
๐ testng.xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="AutomationSuite" parallel="methods" thread-count="2">
<test name="Login Tests">
<classes>
<class name="com.framework.tests.LoginTest"/>
</classes>
</test>
</suite>
๐ EXPLANATION
parallel="methods"โ run tests simultaneouslythread-count="2"โ run 2 tests in parallel- Uses ThreadLocal WebDriver
=====================================
โ 12. JENKINS PIPELINE
=====================================
๐ Jenkinsfile
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://your-repo-url.git'
}
}
stage('Install Dependencies') {
steps {
sh 'mvn clean install -DskipTests'
}
}
stage('Run Tests') {
steps {
sh 'mvn test'
}
}
stage('Allure Report') {
steps {
allure results: [[path: 'allure-results']]
}
}
}
}
๐ EXPLANATION
- Git checkout
- Build project
- Run tests
- Publish Allure reports
=====================================
โ 13. HOW TO RUN
=====================================
1๏ธโฃ Install dependencies
mvn clean install
2๏ธโฃ Run tests
mvn test
3๏ธโฃ View Allure report
allure serve allure-results