0
0
Selenium Javatesting~3 mins

Why Action methods per page in Selenium Java? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could fix all your test problems by changing code in just one place?

The Scenario

Imagine testing a website manually by clicking buttons, filling forms, and checking results on every page one by one.

You have to remember each step and repeat it exactly the same way every time.

The Problem

Manual testing is slow and tiring.

It's easy to forget steps or make mistakes.

When the website changes, you must redo everything from scratch.

The Solution

Action methods per page organize all actions for a page into one place.

This makes tests easier to write, read, and update.

When the page changes, you only update the methods for that page.

Before vs After
Before
driver.findElement(By.id("login")).click();
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("pass");
driver.findElement(By.id("submit")).click();
After
loginPage.clickLogin();
loginPage.enterUsername("user");
loginPage.enterPassword("pass");
loginPage.submit();
What It Enables

It enables fast, clear, and maintainable automated tests that adapt easily to page changes.

Real Life Example

When a website redesign changes button IDs, you only update the action methods in one place instead of all tests.

Key Takeaways

Manual testing is slow and error-prone.

Action methods group page actions for easy reuse.

Tests become simpler to write and maintain.