import java (2)
import java (2)
enterUsername("testuser");
loginPage.enterPassword("testpassword"); loginPage.clickLogin(); // Add assertions or
further actions here // Close the browser driver.quit(); } } Advantages of Using POM •
Separation of Concerns: UI interactions are separated from test logic. • Easier Updates: If
an element's locator changes, you only need to update it in one place. • Clear Structure:
The code structure is clear, making it easier for new team members to understand. POM
VS Page Factory Page Object Model (POM) 1. Definition: POM is a design pattern that
creates an object repository for web UI elements. Each web page in the application has a
corresponding class that contains methods to interact with the elements on that page. 2.
Structure: • Each page class contains locators for web elements and methods that
perform actions on those elements. • The locators are defined using the By class. 3.
Initialization: • Objects of page classes must be initialized individually in the test scripts. •
It does not provide lazy initialization, meaning that all elements are found at the time of
method execution. 4. Advantages: • Reduces code duplication and improves test
maintenance. • Makes the code cleaner and easier to understand by separating UI
operations from test logic. 5. Example: public class LoginPage { private WebDriver driver; //
Locators private By username = By.id("username"); private By password =
By.id("password"); private By loginButton = By.id("login"); public LoginPage(WebDriver
driver) { this.driver = driver; } public void enterUsername(String user)
{ driver.findElement(username).sendKeys(user); } public void enterPassword(String pass)
{ driver.findElement(password).sendKeys(pass); } public void clickLogin()
{ driver.findElement(loginButton).click(); } } Page Factory 1. Definition: Page Factory is an
extension of the Page Object Model provided by Selenium WebDriver. It simplifies the
process of creating Page Objects by using annotations to initialize web elements.