0% found this document useful (0 votes)
18 views

Common Packages in Selenium Java Automation Framework

The document outlines a modular architecture for a Selenium Java Automation Framework, detailing the roles of various packages such as base, pages, testcases, utils, data, and listeners. Each package serves specific functions, enhancing reusability, scalability, and maintainability in test automation. The framework supports a data-driven approach and ensures efficient test execution through organized structure and separation of concerns.

Uploaded by

vineeth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Common Packages in Selenium Java Automation Framework

The document outlines a modular architecture for a Selenium Java Automation Framework, detailing the roles of various packages such as base, pages, testcases, utils, data, and listeners. Each package serves specific functions, enhancing reusability, scalability, and maintainability in test automation. The framework supports a data-driven approach and ensures efficient test execution through organized structure and separation of concerns.

Uploaded by

vineeth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Common Packages in Selenium Java Automation Framework

A well-structured Selenium Java Automation Framework follows a modular architecture with


separate packages to enhance reusability, scalability, and maintainability. Below is a breakdown of
commonly maintained packages and their roles.

1. base Package (Test Setup & WebDriver Management)

Purpose:

• Manages WebDriver initialization, browser settings, and basic configurations.

• Ensures that each test has a consistent WebDriver setup.

Common Files:

• BaseTest.java → Initializes WebDriver, sets browser properties, handles test setup and
teardown.

• DriverManager.java → Creates WebDriver instances based on browser type.

Example:

public class DriverManager {

private static WebDriver driver;

public static WebDriver getDriver() {

if (driver == null) {

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

driver = new ChromeDriver();

return driver;

public static void quitDriver() {

if (driver != null) {

driver.quit();

driver = null;

}
2. pages Package (Page Object Model - POM)

Purpose:

• Contains Java classes representing different pages of the application.

• Implements the Page Object Model (POM) to encapsulate UI elements and actions.

Common Files:

• LoginPage.java → Contains login page elements and methods.

• HomePage.java → Handles homepage interactions.

Example:

public class LoginPage {

private WebDriver driver;

public LoginPage(WebDriver driver) {

this.driver = driver;

PageFactory.initElements(driver, this);

@FindBy(id = "username")

private WebElement usernameField;

@FindBy(id = "password")

private WebElement passwordField;

@FindBy(id = "loginButton")

private WebElement loginButton;

public void login(String username, String password) {

usernameField.sendKeys(username);

passwordField.sendKeys(password);

loginButton.click();

}
}

3. testcases Package (Test Execution)

Purpose:

• Contains actual test scripts.

• Uses the Page Object Model for cleaner test cases.

Common Files:

• LoginTest.java → Automates the login scenario.

• CheckoutTest.java → Automates the checkout process.

Example:

public class LoginTest {

private WebDriver driver;

@BeforeMethod

public void setUp() {

driver = DriverManager.getDriver();

driver.get("https://example.com/login");

@Test

public void testLogin() {

LoginPage loginPage = new LoginPage(driver);

loginPage.login("testuser", "password123");

Assert.assertEquals(driver.getTitle(), "Home Page");

@AfterMethod

public void tearDown() {

DriverManager.quitDriver();

}
4. utils Package (Reusable Utility Methods)

Purpose:

• Contains reusable utility methods like file reading, date handling, waits, screenshots, etc.

Common Files:

• ExcelReader.java → Reads test data from an Excel file.

• WaitUtils.java → Implements explicit waits.

• ScreenshotUtil.java → Captures screenshots on test failures.

Example:

public class ScreenshotUtil {

public static void takeScreenshot(WebDriver driver, String fileName) {

File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

File dest = new File("screenshots/" + fileName + ".png");

FileUtils.copyFile(src, dest);

5. data Package (Test Data Management)

Purpose:

• Stores test data in Excel, JSON, or CSV files.

• Helps in data-driven testing.

Common Files:

• testdata.xlsx → Contains login credentials, search terms, etc.

• config.properties → Stores global settings (browser type, URL, etc.).

Example (config.properties):

baseURL=https://example.com

browser=chrome

username=testuser

password=pass123

Reading Config in Java:

public class ConfigReader {


private static Properties properties;

static {

try (FileInputStream file = new FileInputStream("config.properties")) {

properties = new Properties();

properties.load(file);

} catch (IOException e) {

e.printStackTrace();

public static String getProperty(String key) {

return properties.getProperty(key);

6. listeners Package (TestNG Listeners for Reporting & Logs)

Purpose:

• Implements TestNG listeners for logging, reporting, and screenshot capture on failure.

Common Files:

• TestListener.java → Implements ITestListener for test event handling.

Example:

public class TestListener implements ITestListener {

@Override

public void onTestFailure(ITestResult result) {

ScreenshotUtil.takeScreenshot(DriverManager.getDriver(), result.getName());

Data Flow in Selenium Framework

Step-by-Step Execution Process:


1. Test Execution Starts → testcases package contains test scripts that initiate the process.

2. WebDriver Setup → base.DriverManager initializes WebDriver and opens the browser.

3. Page Interactions → pages.LoginPage interacts with the login form.

4. Data Fetching → data.ExcelReader reads data for login credentials.

5. Utility Methods → utils.WaitUtils ensures elements are loaded before interacting.

6. Assertions & Reporting → listeners.TestListener captures test failures and logs results.

7. Teardown → Browser closes via DriverManager.quitDriver().

Conclusion

• Separation of Concerns: Each package serves a specific purpose.

• Modularity: Easy to update and maintain.

• Scalability: Suitable for large projects with multiple test cases.

• Data-Driven Approach: Uses external data sources for test flexibility.

This structured Selenium Java framework ensures efficient and reusable test automation.

You might also like