Selenium Automation Project for Portfolio
A Selenium Automation Project for Portfolio is a complete practical automation project that demonstrates how Selenium WebDriver can be used to automate a real-world web application using a maintainable testing framework. Instead of creating isolated Selenium scripts, the project combines WebDriver, TestNG, Page Object Model (POM), reusable utilities, test data, assertions, reporting, configuration, and build tools into a structured automation solution.
Selenium WebDriver provides an interface for controlling browsers and interacting with web elements, while a framework structure helps organize tests so that they are easier to maintain and extend. Selenium documentation also recommends Page Objects as a design pattern for reducing duplicated UI code and separating test logic from page-specific implementation details. :contentReference[oaicite:0]{index=0}
This project can be used as a practical portfolio project to demonstrate knowledge of Selenium automation, Java, TestNG, Maven, Page Object Model, data-driven testing, assertions, screenshots, reporting, reusable utilities, and CI/CD concepts.
Course Resource: Selenium Training | Register for Selenium Course Demo
1. What is a Selenium Automation Portfolio Project?
A Selenium Automation Portfolio Project is a practical software testing project in which automated tests are created for a web application. The project demonstrates how a QA automation engineer designs, develops, executes, and maintains automated tests.
A professional portfolio project should demonstrate more than basic browser interactions. It should show framework organization, reusable code, test coverage, reporting, test data management, error handling, and maintainability.
A typical project can automate workflows such as:
- User registration.
- User login and logout.
- Product search.
- Product filtering.
- Product details validation.
- Add to cart.
- Update cart quantity.
- Checkout.
- Form validation.
- Order confirmation.
- Negative scenarios.
- Logout functionality.
2. Objective of the Project
The primary objective is to create a reusable Selenium automation framework that can execute multiple functional test cases against a web application.
The project should demonstrate the following skills:
- Java programming.
- Selenium WebDriver.
- TestNG.
- Page Object Model.
- Locators.
- Explicit waits.
- Assertions.
- Data-driven testing.
- TestNG DataProvider.
- Configuration management.
- Screenshot capture.
- Test reporting.
- Maven.
- Git and GitHub.
- CI/CD integration concepts.
3. Recommended Project Type
For a portfolio project, an e-commerce application is a useful example because it contains multiple realistic workflows and allows different types of Selenium interactions to be demonstrated.
A sample project can be called:
Selenium E-Commerce Automation Framework
The application may contain:
- Login page.
- Home page.
- Products page.
- Product details page.
- Shopping cart.
- Checkout page.
- Order confirmation page.
4. Project Scope
The project can cover functional automation for the complete customer journey.
Launch Application
|
v
Login
|
v
Home Page
|
v
Search Product
|
v
Select Product
|
v
Add to Cart
|
v
Verify Cart
|
v
Checkout
|
v
Enter Customer Details
|
v
Place Order
|
v
Verify Order
|
v
Logout
5. Why Use Selenium WebDriver?
Selenium WebDriver is designed for browser automation and provides an API for controlling browser sessions, locating elements, navigating pages, and interacting with web applications. It supports major browsers through WebDriver implementations. :contentReference[oaicite:1]{index=1}
For a portfolio project, Selenium demonstrates practical browser automation skills such as:
- Opening web pages.
- Locating web elements.
- Entering text.
- Clicking buttons.
- Selecting options.
- Handling browser windows.
- Working with alerts and frames.
- Waiting for dynamic elements.
- Capturing screenshots.
- Validating application behavior.
6. Technology Stack
| Technology | Purpose |
| Java | Programming language for automation |
| Selenium WebDriver | Browser automation |
| TestNG | Test execution and assertions |
| Maven | Dependency and build management |
| Page Object Model | Framework design and maintainability |
| Git | Version control |
| GitHub | Source-code repository and portfolio presentation |
| Excel/CSV/JSON | External test data |
| Extent-style reporting or another reporting solution | Test execution reporting |
| Jenkins/GitHub Actions | CI/CD execution |
7. Project Architecture
A maintainable Selenium project separates test cases, page objects, utilities, test data, configuration, and reports.
Test Cases
|
v
Page Objects
|
v
Selenium WebDriver
|
v
Web Application
Supporting Components:
Configuration
Test Data
Utilities
Driver Factory
Reports
Screenshots
Logs
8. Recommended Project Structure
SeleniumAutomationProject
|
|-- pom.xml
|-- testng.xml
|-- README.md
|
|-- src
| |-- main
| | |-- java
| | |-- pages
| | | |-- LoginPage.java
| | | |-- HomePage.java
| | | |-- ProductsPage.java
| | | |-- ProductDetailsPage.java
| | | |-- CartPage.java
| | | |-- CheckoutPage.java
| | |
| | |-- utilities
| | | |-- DriverFactory.java
| | | |-- ConfigReader.java
| | | |-- ScreenshotUtil.java
| | | |-- WaitUtil.java
| | | |-- ExcelReader.java
| | |
| | |-- base
| | |-- BaseTest.java
| |
| |-- test
| |-- java
| |-- tests
| | |-- LoginTest.java
| | |-- ProductTest.java
| | |-- CartTest.java
| | |-- CheckoutTest.java
| |
| |-- data
| |-- LoginData.java
| |-- ProductData.java
|
|-- config
| |-- config.properties
|
|-- test-data
| |-- testdata.xlsx
| |-- testdata.json
|
|-- screenshots
|
|-- reports
|
|-- logs
9. Creating the Maven Project
Maven can be used to manage Selenium, TestNG, reporting, and other project dependencies.
A basic Maven project can be created with a pom.xml file.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>selenium-automation-project</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
10. Selenium Dependency
Selenium Java bindings are added as a Maven dependency so that Java test classes can use Selenium WebDriver APIs.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.49.0</version>
</dependency>
Always verify the appropriate Selenium version for the project from the official Selenium release information rather than blindly copying an old version. :contentReference[oaicite:2]{index=2}
11. TestNG Dependency
TestNG can be used as the test runner for organizing test methods, setup and cleanup operations, assertions, groups, data providers, and test execution.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
12. Base Test Class
A BaseTest class can contain common setup and cleanup operations. This prevents repeated browser initialization code across every test class.
package base;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class BaseTest {
protected WebDriver driver;
@BeforeMethod
public void setUp() {
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@AfterMethod
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
13. Driver Factory
A DriverFactory can centralize WebDriver creation and make it easier to support multiple browsers.
package utilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DriverFactory {
public static WebDriver createDriver(String browser) {
if (browser.equalsIgnoreCase("chrome")) {
return new ChromeDriver();
}
if (browser.equalsIgnoreCase("firefox")) {
return new FirefoxDriver();
}
throw new IllegalArgumentException(
"Unsupported browser: " + browser
);
}
}
Selenium's current documentation describes Selenium Manager as a tool that can automatically handle browser driver management for Selenium bindings, reducing the need for manual driver setup in many standard local configurations. :contentReference[oaicite:3]{index=3}
14. Configuration File
Application configuration should be separated from test logic whenever practical.
Example config.properties:
browser=chrome
baseUrl=https://example.com
username=testuser
timeout=10
15. ConfigReader Utility
package utilities;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class ConfigReader {
private static final Properties properties = new Properties();
static {
try {
FileInputStream input =
new FileInputStream("config/config.properties");
properties.load(input);
input.close();
} catch (IOException e) {
throw new RuntimeException(
"Unable to load configuration file", e
);
}
}
public static String get(String key) {
return properties.getProperty(key);
}
}
16. Introduction to Page Object Model
The Page Object Model (POM) is a design pattern in which application pages are represented by classes. The page classes contain locators and methods representing operations that users can perform on those pages.
Selenium's documentation describes Page Objects as a way to model UI areas as objects, reduce duplicated code, and keep page-specific changes localized to the page object. :contentReference[oaicite:4]{index=4}
Test Class
|
v
Page Object
|
v
Locators + Page Actions
|
v
WebDriver
|
v
Browser
17. Creating LoginPage
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class LoginPage {
private WebDriver driver;
private By username =
By.id("username");
private By password =
By.id("password");
private By loginButton =
By.id("loginButton");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public void enterUsername(String value) {
driver.findElement(username).sendKeys(value);
}
public void enterPassword(String value) {
driver.findElement(password).sendKeys(value);
}
public void clickLogin() {
driver.findElement(loginButton).click();
}
public void login(String user, String pass) {
enterUsername(user);
enterPassword(pass);
clickLogin();
}
}
18. Creating HomePage
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class HomePage {
private WebDriver driver;
private By dashboard =
By.id("dashboard");
public HomePage(WebDriver driver) {
this.driver = driver;
}
public boolean isDashboardDisplayed() {
return driver.findElement(dashboard).isDisplayed();
}
}
19. Creating ProductsPage
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class ProductsPage {
private WebDriver driver;
private By searchBox =
By.id("search");
private By searchButton =
By.id("searchButton");
public ProductsPage(WebDriver driver) {
this.driver = driver;
}
public void searchProduct(String product) {
driver.findElement(searchBox)
.clear();
driver.findElement(searchBox)
.sendKeys(product);
driver.findElement(searchButton)
.click();
}
}
20. Creating CartPage
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class CartPage {
private WebDriver driver;
private By cartTitle =
By.id("cartTitle");
private By checkoutButton =
By.id("checkout");
public CartPage(WebDriver driver) {
this.driver = driver;
}
public boolean isCartDisplayed() {
return driver.findElement(cartTitle)
.isDisplayed();
}
public void clickCheckout() {
driver.findElement(checkoutButton)
.click();
}
}
21. Creating CheckoutPage
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class CheckoutPage {
private WebDriver driver;
private By firstName =
By.id("firstName");
private By lastName =
By.id("lastName");
private By address =
By.id("address");
private By placeOrder =
By.id("placeOrder");
public CheckoutPage(WebDriver driver) {
this.driver = driver;
}
public void enterCustomerDetails(
String first,
String last,
String customerAddress) {
driver.findElement(firstName)
.sendKeys(first);
driver.findElement(lastName)
.sendKeys(last);
driver.findElement(address)
.sendKeys(customerAddress);
}
public void placeOrder() {
driver.findElement(placeOrder)
.click();
}
}
22. Creating Login Test
package tests;
import base.BaseTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import pages.LoginPage;
import pages.HomePage;
public class LoginTest extends BaseTest {
@Test
public void validLoginTest() {
driver.get("https://example.com/login");
LoginPage loginPage =
new LoginPage(driver);
loginPage.login(
"testuser",
"password123"
);
HomePage homePage =
new HomePage(driver);
Assert.assertTrue(
homePage.isDashboardDisplayed()
);
}
}
23. Data-Driven Login Test
A portfolio project should demonstrate data-driven testing instead of relying only on one hard-coded test case.
@DataProvider(name = "loginData")
public Object[][] loginData() {
return new Object[][] {
{"admin", "admin123"},
{"manager", "manager123"},
{"user", "user123"}
};
}
@Test(dataProvider = "loginData")
public void loginTest(
String username,
String password) {
driver.get("https://example.com/login");
LoginPage loginPage =
new LoginPage(driver);
loginPage.login(
username,
password
);
}
24. Product Search Test
package tests;
import base.BaseTest;
import org.testng.annotations.Test;
import pages.ProductsPage;
public class ProductTest extends BaseTest {
@Test
public void productSearchTest() {
driver.get("https://example.com");
ProductsPage productsPage =
new ProductsPage(driver);
productsPage.searchProduct(
"Laptop"
);
}
}
25. Add to Cart Test
The product test can be expanded to validate the complete shopping-cart workflow.
@Test
public void addProductToCartTest() {
driver.get("https://example.com/products");
ProductsPage productsPage =
new ProductsPage(driver);
productsPage.searchProduct("Laptop");
// Select product
// Add product to cart
// Open cart
CartPage cartPage =
new CartPage(driver);
Assert.assertTrue(
cartPage.isCartDisplayed()
);
}
26. Checkout Test
@Test
public void checkoutTest() {
driver.get(
"https://example.com/checkout"
);
CheckoutPage checkoutPage =
new CheckoutPage(driver);
checkoutPage.enterCustomerDetails(
"John",
"Doe",
"Mumbai"
);
checkoutPage.placeOrder();
}
27. Explicit Wait Utility
Modern web applications frequently load elements dynamically. Explicit waits can be encapsulated in reusable utility methods.
package utilities;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class WaitUtil {
public static WebElement waitForElement(
WebDriver driver,
By locator,
int seconds) {
WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(seconds)
);
return wait.until(
ExpectedConditions.visibilityOfElementLocated(
locator
)
);
}
}
28. Why Explicit Waits Matter
Automation should synchronize with the application rather than relying on arbitrary fixed delays.
A good framework should prefer condition-based synchronization for dynamic elements.
Application starts loading
|
v
Element not ready
|
v
Wait for expected condition
|
v
Element becomes available
|
v
Perform action
29. Assertions in the Portfolio Project
Assertions verify whether the actual application behavior matches the expected behavior.
Assert.assertEquals(
actualTitle,
expectedTitle
);
Assert.assertTrue(
element.isDisplayed()
);
Assert.assertFalse(
element.isDisplayed()
);
Assertions should generally remain in test code rather than being hidden inside page objects. Selenium's Page Object guidance specifically recommends keeping test verification in the test code, while page objects represent page services and interactions. :contentReference[oaicite:5]{index=5}
30. Screenshot Utility
Screenshots are useful when diagnosing failed automated tests and documenting execution results.
package utilities;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class ScreenshotUtil {
public static void capture(
WebDriver driver,
String fileName) {
File source =
((TakesScreenshot) driver)
.getScreenshotAs(
OutputType.FILE
);
try {
Files.copy(
source.toPath(),
Path.of(
"screenshots",
fileName + ".png"
),
StandardCopyOption.REPLACE_EXISTING
);
} catch (IOException e) {
throw new RuntimeException(
"Unable to save screenshot", e
);
}
}
}
31. Capture Screenshot on Failure
A framework can capture a screenshot automatically when a test fails.
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
@AfterMethod
public void captureFailure(
ITestResult result) {
if (result.getStatus() ==
ITestResult.FAILURE) {
ScreenshotUtil.capture(
driver,
result.getName()
);
}
}
32. TestNG Test Suite
A testng.xml file can be used to organize multiple test classes.
<!DOCTYPE suite SYSTEM
"https://testng.org/testng-1.0.dtd">
<suite name="Selenium Portfolio Suite">
<test name="Login Tests">
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
<test name="Product Tests">
<classes>
<class name="tests.ProductTest"/>
</classes>
</test>
<test name="Checkout Tests">
<classes>
<class name="tests.CheckoutTest"/>
</classes>
</test>
</suite>
33. Test Groups
TestNG groups can organize tests into categories such as smoke, regression, sanity, and checkout tests.
@Test(groups = "smoke")
public void loginTest() {
// Login test
}
@Test(groups = "regression")
public void productSearchTest() {
// Product search test
}
34. Smoke Test Suite
Smoke tests can validate the most important application functionality.
<suite name="Smoke Suite">
<test name="Smoke Tests">
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<classes>
<class name="tests.LoginTest"/>
<class name="tests.ProductTest"/>
</classes>
</test>
</suite>
35. Regression Test Suite
A regression suite can include a larger collection of functional tests.
<suite name="Regression Suite">
<test name="Regression Tests">
<groups>
<run>
<include name="regression"/>
</run>
</groups>
<packages>
<package name="tests"/>
</packages>
</test>
</suite>
36. Test Reporting
Test reporting provides a readable record of test execution. A portfolio framework should make it easy to identify passed tests, failed tests, skipped tests, execution duration, and failure information.
A useful report can contain:
- Test suite name.
- Test case name.
- Execution status.
- Execution time.
- Failure message.
- Stack trace.
- Screenshot reference.
- Environment information.
- Browser information.
37. Logging
Logging can help identify what happened during test execution.
System.out.println(
"Opening login page"
);
System.out.println(
"Entering username"
);
System.out.println(
"Clicking login button"
);
System.out.println(
"Validating dashboard"
);
For a production-quality framework, a dedicated logging library can be used instead of relying only on console output.
38. Test Data Management
Test data should be organized separately from page interaction logic.
Possible data sources include:
- Java DataProvider.
- Properties files.
- CSV files.
- Excel files.
- JSON files.
- Database records.
- Environment variables.
39. DataProvider for Product Testing
@DataProvider(name = "products")
public Object[][] products() {
return new Object[][] {
{"Laptop"},
{"Mobile"},
{"Tablet"},
{"Headphones"}
};
}
@Test(dataProvider = "products")
public void searchProductTest(
String product) {
ProductsPage productsPage =
new ProductsPage(driver);
productsPage.searchProduct(product);
}
40. Parameterizing Browser
A portfolio project can demonstrate cross-browser testing using TestNG parameters.
@Parameters("browser")
@BeforeMethod
public void setUp(String browser) {
driver =
DriverFactory.createDriver(browser);
driver.manage()
.window()
.maximize();
}
TestNG can be used for parameterized execution and parallel test execution, making it suitable for organizing Selenium test suites. :contentReference[oaicite:6]{index=6}
41. Cross-Browser Test Configuration
<suite name="Cross Browser Suite"
parallel="tests"
thread-count="2">
<test name="Chrome Tests">
<parameter
name="browser"
value="chrome"/>
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
<test name="Firefox Tests">
<parameter
name="browser"
value="firefox"/>
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
</suite>
42. Handling Multiple Environments
A portfolio framework can support QA, staging, and other test environments by externalizing the application URL.
environment=qa
baseUrl=https://qa.example.com
Another configuration might contain:
environment=staging
baseUrl=https://staging.example.com
43. Login Test Scenarios
| Scenario | Input | Expected Result |
| Valid Login | Valid username and password | Dashboard displayed |
| Invalid Username | Invalid username | Error displayed |
| Invalid Password | Invalid password | Error displayed |
| Empty Username | Blank username | Validation displayed |
| Empty Password | Blank password | Validation displayed |
| Logout | Logged-in user | User returned to login page |
44. Product Test Scenarios
| Scenario | Expected Result |
| Search product | Relevant product displayed |
| Open product details | Correct product page displayed |
| Add product to cart | Cart count updated |
| Remove product | Product removed from cart |
| Update quantity | Total recalculated |
| Checkout | Checkout page displayed |
45. Checkout Test Scenarios
- Verify checkout page.
- Enter valid customer information.
- Validate required fields.
- Validate invalid input.
- Select payment method.
- Verify order summary.
- Place order.
- Verify confirmation message.
- Verify order identifier when available.
46. Handling Alerts
driver.switchTo()
.alert()
.accept();
For a reusable framework, alert handling can be encapsulated in a utility method.
47. Handling Frames
driver.switchTo()
.frame("paymentFrame");
driver.findElement(
By.id("cardNumber")
).sendKeys("4111111111111111");
driver.switchTo()
.defaultContent();
48. Handling Multiple Windows
String parentWindow =
driver.getWindowHandle();
for (String window :
driver.getWindowHandles()) {
if (!window.equals(parentWindow)) {
driver.switchTo()
.window(window);
}
}
49. Reusable Utility Classes
A scalable framework should avoid repeating common Selenium operations.
Useful utilities include:
- DriverFactory.
- ConfigReader.
- WaitUtil.
- ScreenshotUtil.
- ExcelReader.
- JSONReader.
- BrowserUtil.
- WindowUtil.
- AlertUtil.
- FileUtil.
50. BasePage Class
A BasePage can contain common page-level functionality shared by page classes.
package pages;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class BasePage {
protected WebDriver driver;
protected WebDriverWait wait;
public BasePage(WebDriver driver) {
this.driver = driver;
this.wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
}
protected void click(By locator) {
wait.until(
ExpectedConditions.elementToBeClickable(
locator
)
).click();
}
protected void type(
By locator,
String text) {
wait.until(
ExpectedConditions.visibilityOfElementLocated(
locator
)
).sendKeys(text);
}
protected String getText(By locator) {
return wait.until(
ExpectedConditions.visibilityOfElementLocated(
locator
)
).getText();
}
}
51. Page Classes Extending BasePage
public class LoginPage extends BasePage {
private By username =
By.id("username");
private By password =
By.id("password");
private By loginButton =
By.id("loginButton");
public LoginPage(WebDriver driver) {
super(driver);
}
public void login(
String user,
String pass) {
type(username, user);
type(password, pass);
click(loginButton);
}
}
52. Page Object Design Principles
Page Objects should expose meaningful operations rather than forcing tests to understand the HTML structure of the page.
- Keep locators inside page classes.
- Keep page-specific actions inside page classes.
- Keep assertions in test classes where practical.
- Return another Page Object when an action navigates to another page.
- Avoid exposing unnecessary WebDriver internals.
- Use meaningful method names.
- Keep page classes focused.
These principles align with Selenium's Page Object guidance, which emphasizes page services, encapsulation of page structure, reduced duplication, and keeping assertions in test code. :contentReference[oaicite:7]{index=7}
53. Test Naming Convention
Good naming makes a portfolio project easier for another developer or interviewer to understand.
validLoginTest()
invalidPasswordTest()
searchProductTest()
addProductToCartTest()
removeProductFromCartTest()
checkoutWithValidDataTest()
emptyCheckoutFieldValidationTest()
logoutTest()
54. Locator Strategy
Reliable locators are important for maintainable Selenium automation.
| Locator | Example |
| ID | By.id("username") |
| Name | By.name("email") |
| Class Name | By.className("login-button") |
| CSS Selector | By.cssSelector("#username") |
| XPath | By.xpath("//button[@type='submit']") |
| Tag Name | By.tagName("button") |
Selenium provides locator strategies through its WebElement and element-search APIs. :contentReference[oaicite:8]{index=8}
55. Avoiding Hard-Coded Waits
Avoid using unnecessary fixed delays such as:
Thread.sleep(5000);
Prefer explicit waits based on application conditions.
WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.id("dashboard")
)
);
56. Handling Test Failures
A professional portfolio framework should make failures easy to diagnose.
When a test fails, the framework should ideally provide:
- Failed test name.
- Failure message.
- Stack trace.
- Screenshot.
- Browser information.
- Environment.
- Execution timestamp.
- Relevant logs.
57. Retry Mechanism
A retry mechanism can sometimes be used for known transient failures, but retries should not be used to hide genuine application or automation defects.
public class RetryAnalyzer
implements IRetryAnalyzer {
private int count = 0;
private static final int maxRetry = 1;
@Override
public boolean retry(
ITestResult result) {
if (count < maxRetry) {
count++;
return true;
}
return false;
}
}
58. Parallel Execution
Parallel execution can reduce total execution time when tests are independent and the framework is thread-safe.
<suite
name="Parallel Suite"
parallel="tests"
thread-count="3">
<test name="Chrome">
<parameter
name="browser"
value="chrome"/>
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
<test name="Firefox">
<parameter
name="browser"
value="firefox"/>
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
</suite>
59. Thread Safety
When running Selenium tests in parallel, WebDriver instances should be isolated between concurrent tests.
Thread 1
|
+-- WebDriver 1
|
+-- Browser 1
Thread 2
|
+-- WebDriver 2
|
+-- Browser 2
Thread 3
|
+-- WebDriver 3
|
+-- Browser 3
Sharing one mutable WebDriver instance between concurrent tests can cause session interference and unpredictable results.
60. Test Execution Flow
Start Test Suite
|
v
Read Configuration
|
v
Create WebDriver
|
v
Open Application
|
v
Execute Test
|
v
Use Page Object
|
v
Interact with Web Application
|
v
Perform Assertions
|
+------ PASS ------+
| |
| v
| Report
|
+------ FAIL ------+
|
v
Screenshot
|
v
Report
|
v
Close Browser
|
v
End Test
61. End-to-End Portfolio Workflow
A complete e-commerce automation project can implement the following flow:
Login
|
v
Verify Home Page
|
v
Search Product
|
v
Open Product
|
v
Verify Product Details
|
v
Add Product
|
v
Open Cart
|
v
Verify Product
|
v
Proceed to Checkout
|
v
Enter Customer Information
|
v
Verify Order Summary
|
v
Place Order
|
v
Verify Confirmation
|
v
Logout
62. Complete End-to-End Test Example
@Test
public void completePurchaseFlow() {
driver.get("https://example.com");
LoginPage loginPage =
new LoginPage(driver);
loginPage.login(
"testuser",
"password123"
);
HomePage homePage =
new HomePage(driver);
Assert.assertTrue(
homePage.isDashboardDisplayed()
);
ProductsPage productsPage =
new ProductsPage(driver);
productsPage.searchProduct(
"Laptop"
);
// Select product
// Add product to cart
CartPage cartPage =
new CartPage(driver);
Assert.assertTrue(
cartPage.isCartDisplayed()
);
cartPage.clickCheckout();
CheckoutPage checkoutPage =
new CheckoutPage(driver);
checkoutPage.enterCustomerDetails(
"John",
"Doe",
"Mumbai"
);
checkoutPage.placeOrder();
// Verify order confirmation
}
63. API and UI Separation
If the portfolio project later includes API testing, API utilities should remain separate from UI page objects.
Automation Framework
|
+----------------+
| |
v v
UI Tests API Tests
| |
v v
Page Objects API Clients
| |
v v
Selenium HTTP/API Layer
64. Git and GitHub Repository
A portfolio project should be maintained in a version-control repository with a clear README file.
The repository can contain:
- Source code.
- pom.xml.
- TestNG suite files.
- Configuration examples.
- Page objects.
- Test classes.
- Utilities.
- Test data templates.
- Sample screenshots.
- Sample reports.
- README documentation.
65. README File Structure
A strong project README can contain:
- Project title.
- Project overview.
- Application under test.
- Technology stack.
- Framework architecture.
- Project structure.
- Installation instructions.
- Configuration instructions.
- How to execute tests.
- How to execute smoke tests.
- How to execute regression tests.
- Reporting information.
- Screenshot examples.
- Future improvements.
66. Example README Commands
# Clone project
git clone <repository-url>
# Navigate to project
cd SeleniumAutomationProject
# Run tests
mvn test
# Run a specific TestNG suite
mvn test -DsuiteXmlFile=testng.xml
67. CI/CD Integration
The automation project can be executed automatically through a CI/CD pipeline.
Developer Push
|
v
Git Repository
|
v
CI/CD Pipeline
|
v
Checkout Source
|
v
Install Dependencies
|
v
Build Project
|
v
Execute Selenium Tests
|
v
Generate Reports
|
v
Store Artifacts
|
v
Notify Result
68. Jenkins Integration Concept
A Jenkins job can execute the Maven test command.
mvn clean test
The pipeline can then archive reports and screenshots as build artifacts.
69. GitHub Actions Integration Concept
A GitHub Actions workflow can automatically run the Selenium project after a push or pull request.
name: Selenium Tests
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Run Tests
run: mvn clean test
70. Security Considerations
Credentials and secrets should not be committed to public repositories.
Avoid code such as:
String password = "MyRealPassword123";
Instead, use secure environment variables or an appropriate secret-management mechanism.
String password =
System.getenv("TEST_PASSWORD");
71. Handling Environment Variables
String browser =
System.getenv("BROWSER");
String baseUrl =
System.getenv("BASE_URL");
This allows the same framework to be configured differently across local, QA, staging, and CI environments.
72. Test Coverage Matrix
| Module | Smoke | Regression | Negative |
| Login | Yes | Yes | Yes |
| Search | Yes | Yes | Yes |
| Product Details | Yes | Yes | Yes |
| Cart | Yes | Yes | Yes |
| Checkout | Yes | Yes | Yes |
| Logout | Yes | Yes | No |
73. Portfolio Project Test Cases
| ID | Test Case | Type |
| TC001 | Verify valid login | Positive |
| TC002 | Verify invalid login | Negative |
| TC003 | Verify logout | Functional |
| TC004 | Search product | Functional |
| TC005 | Verify product details | Functional |
| TC006 | Add product to cart | Functional |
| TC007 | Remove product from cart | Functional |
| TC008 | Update product quantity | Functional |
| TC009 | Open checkout | Functional |
| TC010 | Validate checkout fields | Negative |
| TC011 | Place order | End-to-End |
| TC012 | Verify order confirmation | End-to-End |
74. Common Mistakes in Selenium Portfolio Projects
- Putting all automation code into one large class.
- Duplicating locators across multiple tests.
- Using excessive Thread.sleep().
- Hard-coding credentials.
- Hard-coding environment URLs.
- Sharing WebDriver incorrectly during parallel execution.
- Putting assertions inside every page-object method.
- Using unstable locators.
- Not capturing useful failure information.
- Not documenting how to execute the project.
- Uploading secrets to GitHub.
- Creating a project without meaningful test coverage.
- Ignoring maintainability.
75. Best Practices
- Follow Page Object Model principles.
- Keep locators inside page classes.
- Create reusable utilities.
- Use explicit waits for dynamic conditions.
- Use meaningful test names.
- Separate test data from test logic.
- Use TestNG groups.
- Use DataProviders for repeated test data.
- Use configuration files for environment-specific values.
- Protect credentials and secrets.
- Capture screenshots for useful failure diagnosis.
- Generate readable reports.
- Keep the project under Git version control.
- Document the project in README.md.
- Run tests through Maven.
- Integrate CI/CD where practical.
- Keep page objects focused on page services and interactions.
76. Advanced Improvements
After completing the basic framework, additional capabilities can be added.
- Parallel execution.
- Cross-browser execution.
- Remote WebDriver.
- Selenium Grid.
- Cloud browser execution.
- Advanced reporting.
- Centralized logging.
- Database validation.
- API integration.
- Visual testing.
- Accessibility checks.
- CI/CD pipeline.
- Docker-based execution.
- Environment-specific configuration.
- Dynamic test data.
Selenium Grid is intended for scenarios where browser execution needs to be distributed across machines, while WebDriver remains the browser-control layer. :contentReference[oaicite:9]{index=9}
77. Portfolio Dashboard Concept
The project can present execution information in a simple dashboard.
Selenium Automation Dashboard
--------------------------------
Total Tests : 50
Passed Tests : 44
Failed Tests : 4
Skipped Tests : 2
Execution Time : 08:35
Browser : Chrome
Environment : QA
--------------------------------
78. Skills Demonstrated by the Project
| Skill | Demonstrated Through |
| Selenium | Browser automation |
| Java | Automation programming |
| TestNG | Test execution and organization |
| POM | Page classes |
| Data-driven testing | DataProvider |
| Synchronization | Explicit waits |
| Assertions | Expected vs actual validation |
| Reporting | Execution reports |
| Git | Version control |
| Maven | Build and dependency management |
| CI/CD | Automated pipeline execution |
79. How to Present the Project in a Portfolio
The portfolio description should clearly communicate what was automated and which technologies were used.
Example:
Selenium E-Commerce Automation Framework
Developed a Java-based Selenium automation framework
for testing an e-commerce web application.
Key Features:
- Selenium WebDriver
- TestNG
- Page Object Model
- Data-driven testing
- Explicit waits
- Cross-browser execution
- Screenshot capture
- Test reporting
- Maven
- Git/GitHub
- CI/CD integration
80. Resume Project Description
A concise resume description can be written as:
Developed a Selenium WebDriver automation framework
using Java, TestNG, Maven, and Page Object Model to
automate login, product search, cart, checkout, and
order workflows. Implemented reusable page classes,
data-driven testing, explicit waits, screenshots,
reporting, cross-browser execution, and CI/CD-ready
test execution.
81. Interview Explanation
When asked to explain the project during an interview, describe it in a structured manner.
Application
|
v
Test Scenarios
|
v
TestNG Test Classes
|
v
Page Object Classes
|
v
Utilities
|
v
Selenium WebDriver
|
v
Browser
|
v
Assertions
|
v
Reports
Explain what you automated, how the framework is structured, how test data is handled, how failures are diagnosed, and how the tests can be executed in different environments.
82. Project Development Roadmap
- Create Maven project.
- Add Selenium dependency.
- Add TestNG dependency.
- Create BaseTest.
- Create DriverFactory.
- Create configuration reader.
- Create BasePage.
- Create LoginPage.
- Create HomePage.
- Create ProductsPage.
- Create CartPage.
- Create CheckoutPage.
- Create LoginTest.
- Create ProductTest.
- Create CartTest.
- Create CheckoutTest.
- Add DataProvider.
- Add assertions.
- Add explicit waits.
- Add screenshots.
- Add reporting.
- Add test groups.
- Add cross-browser execution.
- Add Maven execution.
- Add Git repository.
- Add README.
- Add CI/CD integration.
83. Practical Project Deliverables
- Complete source code.
- Maven pom.xml.
- TestNG suite.
- Page Object classes.
- Base classes.
- Utility classes.
- Test data.
- Configuration files without secrets.
- Execution reports.
- Failure screenshots.
- README.md.
- CI/CD configuration.
84. Final Architecture
Selenium Automation Project
|
+---------------------+---------------------+
| | |
v v v
Test Classes Page Objects Test Data
| | |
| v |
| Base Page |
| | |
+-----------> Utilities <------------------+
|
v
Driver Factory
|
v
Selenium WebDriver
|
v
Browser
|
v
Web Application
|
v
Assertions
|
+------------+------------+
| |
v v
Screenshots Reports
| |
+------------+------------+
|
v
CI/CD
85. Quick Reference Table
| Component | Purpose |
| WebDriver | Controls the browser |
| TestNG | Runs and organizes tests |
| Page Object | Represents page functionality |
| BasePage | Provides common page operations |
| BaseTest | Provides common test setup and cleanup |
| DriverFactory | Creates WebDriver instances |
| ConfigReader | Reads configuration values |
| WaitUtil | Provides reusable synchronization |
| DataProvider | Supplies multiple test data sets |
| ScreenshotUtil | Captures screenshots |
| Reports | Displays execution results |
| Maven | Manages dependencies and builds |
| Git | Tracks source-code changes |
| CI/CD | Automates test execution |
86. Interview Questions
1. Explain your Selenium automation project.
Explain the application, test scenarios, framework architecture, technologies, Page Object Model, test data, reporting, and execution process.
2. Why did you use Page Object Model?
POM separates test logic from page-specific locators and operations and reduces duplication.
3. What is the role of BaseTest?
BaseTest centralizes common test setup and cleanup functionality.
4. What is the purpose of DriverFactory?
DriverFactory centralizes WebDriver creation and can support different browsers.
5. How do you handle waits?
Use explicit waits based on expected application conditions rather than unnecessary fixed delays.
6. How do you manage test data?
Use DataProviders or external data sources such as CSV, Excel, JSON, or databases depending on the project requirements.
7. How do you handle failed tests?
Use reports, logs, stack traces, and screenshots to make failures easier to diagnose.
8. How do you run tests in different browsers?
Use a driver factory combined with TestNG parameters or another configuration mechanism.
9. How do you run the project from the command line?
mvn clean test
10. How can the framework be integrated with CI/CD?
The Maven test command can be executed from a CI/CD pipeline, with reports and screenshots stored as build artifacts.
11. Why should credentials not be stored in GitHub?
Credentials are sensitive information and should be managed through secure configuration or secret-management mechanisms.
12. How do you make the framework maintainable?
Use POM, reusable utilities, centralized configuration, meaningful naming, stable locators, explicit waits, and clear project organization.
13. How do you execute smoke and regression suites?
Use TestNG groups and suite configuration to select the required test categories.
14. How do you support parallel execution?
Configure TestNG parallel execution and ensure that WebDriver and test state are isolated between concurrent tests.
15. What makes a Selenium project portfolio-ready?
A portfolio-ready project should demonstrate complete automation workflows, clean architecture, reusable components, test data, reporting, documentation, source control, and practical execution instructions.
87. Practical Exercises
- Create a Selenium Maven project.
- Add Selenium and TestNG dependencies.
- Create a BaseTest class.
- Create a DriverFactory.
- Create a LoginPage.
- Create a HomePage.
- Create a ProductsPage.
- Create a CartPage.
- Create a CheckoutPage.
- Create login test cases.
- Create search test cases.
- Create cart test cases.
- Create checkout test cases.
- Add DataProvider.
- Add assertions.
- Add explicit waits.
- Add screenshots.
- Add reports.
- Add TestNG groups.
- Add cross-browser execution.
- Push the project to GitHub.
- Create a detailed README.
- Configure CI/CD execution.
88. Learning Roadmap
- Learn Java fundamentals.
- Learn Selenium WebDriver.
- Learn locators.
- Learn browser interactions.
- Learn waits.
- Learn TestNG.
- Learn assertions.
- Learn DataProviders.
- Learn Page Object Model.
- Learn Maven.
- Learn Git and GitHub.
- Learn reporting.
- Learn framework utilities.
- Learn cross-browser testing.
- Learn parallel execution.
- Learn CI/CD.
- Build a complete portfolio project.
89. Summary
A Selenium Automation Project for Portfolio is a practical way to demonstrate real-world automation engineering skills. Instead of creating only individual Selenium scripts, the project combines browser automation, TestNG, Page Object Model, reusable utilities, test data, assertions, reporting, configuration, Maven, Git, and CI/CD concepts.
The most important architectural principle is separation of responsibilities. Test classes should describe test scenarios, page classes should model page functionality, utilities should provide reusable technical operations, configuration should be externalized, and reports should communicate execution results.
Selenium's own guidance emphasizes that Page Objects can reduce duplicated code and centralize page-specific implementation, while WebDriver provides the browser automation interface used by the framework. :contentReference[oaicite:10]{index=10}
A strong portfolio implementation should therefore demonstrate not only that Selenium can automate a browser, but also that the automation solution can be organized, reused, maintained, debugged, executed across environments, and integrated into a software delivery workflow.
90. Course Resources
Learn more about Selenium automation and related testing concepts:
Final Takeaway: A well-structured Selenium portfolio project demonstrates practical automation skills through reusable page classes, TestNG test execution, data-driven testing, synchronization, assertions, screenshots, reporting, cross-browser support, Maven execution, Git-based version control, and CI/CD readiness.