Back to cheat sheet hub

Selenium Framework Cheat Sheet

A reference for building maintainable Selenium frameworks with page objects, reusable layers, logging, reporting, and CI-ready structure.

Selenium Modules 7 to 9 POM + framework Reporting + retries

POM Purpose

Page Object Model separates test intent from raw Selenium operations.

Tests say what to do.
Pages know how to do it.

Page Class Pattern

Keep locators and actions in page classes, not in tests.

public class LoginPage {
    By email = By.id("email");
    By password = By.id("password");
    By loginButton = By.id("login");
}

BasePage

Move shared utilities into a base layer only when multiple pages need them.

public class BasePage {
    protected WebDriver driver;

    public BasePage(WebDriver driver) {
        this.driver = driver;
    }
}

PageFactory

PageFactory is useful to know, especially in interviews and legacy frameworks.

@FindBy(id = "email")
WebElement email;

PageFactory.initElements(driver, this);

Component Objects

Headers, modals, and repeated widgets deserve their own reusable classes.

Examples:
- HeaderComponent
- SidebarComponent
- CartModal

DTO and Test Data

Use data objects instead of long parameter lists when flows grow.

public class LoginData {
    public String username;
    public String password;
}

Logging and Reporting

Frameworks should explain failures quickly, not just fail silently.

Common reporting pieces:
- Log4j
- ExtentReports
- screenshots on failure
- execution metadata

Retry and Failure Capture

Retries can reduce noise, but failure evidence still matters.

On failure:
- capture screenshot
- log locator/action context
- attach to report
- mark retried state clearly

Folder Structure

Keep framework responsibilities separated and obvious.

src/main/java/pages
src/main/java/utils
src/test/java/tests
src/test/resources/testdata
reports/