DEV Community

Cover image for πŸ› οΈ Day 02 - Building a Complete Selenium Java Framework – Project Initiation and Structure
Utkarsh
Utkarsh

Posted on

πŸ› οΈ Day 02 - Building a Complete Selenium Java Framework – Project Initiation and Structure

Day 02 – Project Initiation and Structure

On Day 01, we designed the blueprint of our Selenium Java framework.
On Day 02, we finally move from planning to action.

Today is about setting up the foundation of the projectβ€”the part you build once and rely on throughout the framework’s lifetime. If this step is done correctly, everything that comes later becomes easier, cleaner, and more scalable.


🎯 What We Will Do Today

By the end of Day 02, you will have:

  • A Maven-based Selenium project
  • All required dependencies configured
  • A clean, industry-standard folder structure
  • A central configuration file for global settings

This setup works the same way in real-world automation projects.


Step 1: Creating the Maven Project

We use Maven because it automatically:

  • Downloads required libraries
  • Manages versions
  • Integrates easily with CI/CD tools like Jenkins

You can use Eclipse or IntelliJ IDEAβ€”both are widely used.


β–Ά Option 1: Create Maven Project in Eclipse

  1. Open Eclipse IDE
  2. Go to File β†’ New β†’ Maven Project
  3. Click Next
  4. Select:
  • Archetype: maven-archetype-quickstart
  • Version: 1.4 or 1.5

    1. Click Next
    2. Enter:
  • Group Id: com.orangehrm

  • Artifact Id: OrangeHRM_Project

    1. Finish the setup
    2. Ensure the project is using Java 17:
  • Right-click project β†’ Properties β†’ Java Compiler β†’ Set to 17

Eclipse will create a basic Maven project with a pom.xml file.


β–Ά Option 2: Create Maven Project in IntelliJ IDEA

  1. Open IntelliJ IDEA
  2. Click New Project
  3. Select Maven
  4. Click Next
  5. Enter:
    • GroupId: com.orangehrm
    • ArtifactId: OrangeHRM_Project
  6. Select JDK 17
  7. Finish

IntelliJ will automatically download Maven dependencies in the background.


Step 2: Configuring Dependencies (pom.xml)

The pom.xml file is the heart of a Maven project.
This is where we define all external libraries our framework needs.

For now, we add:

  • Selenium WebDriver
  • TestNG

πŸ“Œ Why these?

  • Selenium β†’ Browser automation
  • TestNG β†’ Test execution, grouping, reporting, and parallel runs

πŸ”§ pom.xml – Essential Dependencies

Add the following inside the <dependencies> section:

<dependencies>

    <!-- Selenium WebDriver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.27.0</version>
    </dependency>

    <!-- TestNG Framework -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.10.2</version>
        <scope>compile</scope>
    </dependency>

</dependencies>
Enter fullscreen mode Exit fullscreen mode

Once saved:

  • Eclipse β†’ Right-click project β†’ Maven β†’ Update Project
  • IntelliJ β†’ Maven reload happens automatically

If there are no errors, your dependencies are set correctly.


Step 3: Designing the Folder Structure

The default Maven structure is good, but not enough for a scalable automation framework.

We now create a clean, logical package hierarchy.

🚨 First Step

Delete any default packages created under:

  • src/main/java
  • src/test/java

We’ll build our own structure.


πŸ“ Packages Under src/main/java

Create the following packages:

Package Purpose
com.orangehrm.base Browser setup and teardown
com.orangehrm.actiondriver Common Selenium actions
com.orangehrm.pages Page Object classes
com.orangehrm.utilities Excel, reporting, helpers
com.orangehrm.listeners TestNG listeners

This separation ensures:

  • Clean code
  • Easy maintenance
  • Better scalability

πŸ“ Resources Folder Setup

Under src/main/resources, create:

  • config.properties
  • log4j2.xml

We will use these files throughout the framework.


Step 4: Global Configuration Using config.properties

Hardcoding values like URLs and browsers is a bad practice.
Instead, we store them in a configuration file.

This makes switching environments easy (QA, UAT, Production).


πŸ“ config.properties – Initial Setup

Create this file in src/main/resources:

# Application Settings
url=https://opensource-demo.orangehrmlive.com/
browser=chrome

# Timeout Settings
implicit_wait=10
explicit_wait=30

# Test Credentials
username=admin
password=admin123
Enter fullscreen mode Exit fullscreen mode

Later, our framework will read these values dynamically.


βœ… Day 02 Summary

By the end of today, you have:

  • A Maven-based Selenium project
  • Selenium and TestNG fully configured
  • A professional folder structure
  • A central configuration system

This is the backbone of the automation framework.


πŸ“Œ Day 02 Task

  1. Create the Maven project (Eclipse or IntelliJ)
  2. Add Selenium and TestNG dependencies
  3. Create all required packages
  4. Validate the setup:
  • Maven dependencies resolve successfully
  • No build errors

πŸš€ What’s Next?

On Day 03, we will:

  • Create the Base Class
  • Configure WebDriver using Selenium Manager
  • Launch the browser dynamically

The real automation begins next 🚦

Top comments (0)