By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: How to Build a Modular Selenium + Cucumber Framework in Java | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > How to Build a Modular Selenium + Cucumber Framework in Java | HackerNoon
Computing

How to Build a Modular Selenium + Cucumber Framework in Java | HackerNoon

News Room
Last updated: 2025/07/01 at 5:49 PM
News Room Published 1 July 2025
Share
SHARE

Modern QA demands more than just writing test cases — it requires building scalable, maintainable, and modular automation frameworks. If you’re using Selenium with Java, integrating it with Cucumber brings structure and clarity to your test design. But how do you build a modular framework that can scale across projects and teams?

This guide walks through how to design a robust Selenium + Cucumber automation framework using Java, following best practices in architecture, reusability, and CI/CD integration.

Why Modular Design?

A modular automation framework:

  • Promotes code reuse and separation of concerns
  • Makes test maintenance easier when UI changes occur
  • Allows for parallel and CI-driven test execution
  • Encourages cleaner collaboration among QA, dev, and business teams

Recommended Folder Structure

Here’s a logical structure to keep the codebase clean and scalable:

lua
CopyEdit
src/test/java
├── base            --> Base classes (WebDriver setup, Hooks)
├── pages           --> Page Object classes
├── stepdefinitions--> Step definitions for Gherkin steps
├── runners         --> Test runners (Cucumber options)
├── utils           --> Utilities like config reader, wait, logs
├── features        --> Gherkin (.feature) files

Tech Stack

ComponentToolUI AutomationSelenium WebDriverBDDCucumber + GherkinLanguageJavaBuild ToolMaven

GradleTest ReportingAllure

ExtentReportsCI/CDJenkins

GitHub Actions

Setting Up WebDriver & Hooks

Base Class: Centralized WebDriver setup

java
CopyEdit
public class BaseTest {
    public static WebDriver driver;

    public void initializeDriver() {
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
    }

    public void tearDown() {
        driver.quit();
    }
}

Hooks Class: To run before and after each scenario

java
CopyEdit
public class Hooks {
    BaseTest base = new BaseTest();

    @Before
    public void setup() {
        base.initializeDriver();
    }

    @After
    public void cleanUp() {
        base.tearDown();
    }
}

Page Object Model (POM)

Helps encapsulate element locators and actions:

java
CopyEdit
public class LoginPage {
    WebDriver driver;

    @FindBy(id = "username") WebElement username;
    @FindBy(id = "password") WebElement password;
    @FindBy(id = "login") WebElement loginBtn;

    public LoginPage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void login(String user, String pass) {
        username.sendKeys(user);
        password.sendKeys(pass);
        loginBtn.click();
    }
}

Feature File (BDD Scenario)

gherkin
CopyEdit
Feature: Login functionality

  Scenario: Successful login with valid credentials
    Given User is on login page
    When User enters valid credentials
    Then User is navigated to the homepage

Step Definitions

java
CopyEdit
public class LoginSteps {
    WebDriver driver = BaseTest.driver;
    LoginPage login = new LoginPage(driver);

    @Given("User is on login page")
    public void userIsOnLoginPage() {
        driver.get("https://example.com/login");
    }

    @When("User enters valid credentials")
    public void userEntersValidCredentials() {
        login.login("testuser", "testpass");
    }

    @Then("User is navigated to the homepage")
    public void userIsOnHomePage() {
        Assert.assertTrue(driver.getTitle().contains("Dashboard"));
    }
}

Reporting Integration

Add Allure Maven dependencies:

xml
CopyEdit
<dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-cucumber6-jvm</artifactId>
    <version>2.13.0</version>
</dependency>

Use annotations like @Step, @Attachment to enhance test traceability in reports.

CI/CD with Jenkins

Create a Jenkins job linked to your Git repository.

Add Maven build step: clean test

Post-build step: Publish Allure results

Configure triggers for nightly or pull request builds.

Best Practices

Use @BeforeStep and @AfterStep for fine-grained logs or screenshots.

Avoid hardcoded test data; externalize into .properties or Excel files.

Implement RetryAnalyzer to auto-retry flaky tests.

Run tests in parallel using TestNG or Cucumber plugin for threads.

Final Thoughts

A modular Selenium + Cucumber framework is not just about cleaner code — it’s about test resilience, scalability, and team collaboration. With the right structure and CI integrations, it can become a powerful asset for any automation team.

If you’re starting out, begin small and scale your framework piece by piece. Over time, this structured approach will save you hundreds of hours in test maintenance and onboarding.

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article I’ve used the Nothing Phone 3, and it’s the most interesting Android device of 2025
Next Article Is Pixelmator Pro Apple’s true follow-up to the defunct Aperture app?
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

NetApp: Not just NAS filers, and a comprehensive cloud strategy | Computer Weekly
News
Today's NYT Mini Crossword Answers for July 2 – CNET
News
Huawei to pre-install self-developed HarmonyOS on all new devices in 2025 · TechNode
Computing
Trump’s sectoral-trade pivot: What it will take to succeed
News

You Might also Like

Computing

Huawei to pre-install self-developed HarmonyOS on all new devices in 2025 · TechNode

1 Min Read
Computing

Midas And 0G Partner To Bring Real-World Assets To AI-Native Blockchain Infrastructure | HackerNoon

5 Min Read
Computing

Baidu’s AI bot has 300 million users, two months after reaching 200 million milestone · TechNode

1 Min Read
Computing

Block3 Unveils Prompt-To-Game AI Engine As Presale Launches | HackerNoon

6 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?