Types of Selenium Test Frameworks
Common Framework Types for Selenium
- Modular Framework: breaks the application into independent modules/scripts, each testable in isolation.
- Data-Driven Framework: separates test data from script logic, running the same test against multiple data sets.
- Keyword-Driven Framework: represents test steps as reusable keywords, readable even by non-programmers.
- Hybrid Framework: combines two or more of the above approaches.
- Page Object Model (POM): represents each web page as a class, encapsulating its elements and actions.
How the Framework Styles Compare
Each style answers a different question: how to organise code, where to keep data, and who writes the tests. Most real projects end up mixing them, which is why the hybrid approach is so common.
| Framework | Main idea | Strength | Weakness |
|---|---|---|---|
| Modular | Split the app into small test modules | Easy to reuse and maintain pieces | Test data still lives inside scripts |
| Data-driven | Read inputs from Excel, CSV or JSON | One script covers many cases | Needs good data management |
| Keyword-driven | Steps written as keywords in a table | Readable by non-programmers | Building the keyword engine takes effort |
| Page Object Model | One class per page | Locators change in one place only | Many classes on large apps |
| Hybrid | Mix of the above | Flexible for real projects | Needs clear team conventions |
Behaviour-driven development (BDD) with Cucumber is often added on top. Tests are written as plain-language Given, When, Then scenarios, and step definitions call page objects underneath.
A Page Object Model Example in Java
The page class hides locators and exposes meaningful actions. The test class reads like a description of user behaviour.
public class LoginPage {
private final WebDriver driver;
private final By username = By.id("username");
private final By password = By.id("password");
private final By loginBtn = By.cssSelector("button[type='submit']");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public DashboardPage loginAs(String user, String pass) {
driver.findElement(username).sendKeys(user);
driver.findElement(password).sendKeys(pass);
driver.findElement(loginBtn).click();
return new DashboardPage(driver);
}
}
// In the test (TestNG)
@Test(dataProvider = "validUsers")
public void userCanLogIn(String user, String pass) {
DashboardPage dash = new LoginPage(driver).loginAs(user, pass);
Assert.assertTrue(dash.isLoaded());
}
Notice the hybrid idea already: the page object gives structure, and the TestNG data provider makes the same test data-driven.
Choosing a Framework for Your Project
- Look at who writes tests. If manual testers or business users contribute, keyword-driven or BDD layers help.
- Count the data variations. Forms with many input combinations benefit from data-driven design.
- Check how often the UI changes. Frequent UI changes make the Page Object Model almost essential.
- Plan reporting and CI early. Decide on a runner (TestNG or JUnit), a report tool and how the suite runs in the pipeline.
A typical folder layout separates concerns clearly: pages for page objects, tests for test classes, data for input files, and utils for driver setup, waits and screenshots.
Common Framework Mistakes
- Putting assertions inside page objects, which makes them hard to reuse.
- Using fixed
Thread.sleep()calls instead of explicit waits. - Hard-coding URLs and credentials instead of reading them from configuration.
- Building a keyword engine nobody maintains; start simple and grow only when needed.
- Letting tests depend on each other's order, which causes random failures in parallel runs.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.