Skip to content

Instantly share code, notes, and snippets.

@PramodDutta
Created August 16, 2023 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PramodDutta/960b95ae0c16b05e02e15b07899e2608 to your computer and use it in GitHub Desktop.
Save PramodDutta/960b95ae0c16b05e02e15b07899e2608 to your computer and use it in GitHub Desktop.
Page Object Model and Page Factory

Page Object Model and Page Factory

Feature Page Object Model Page Factory
Definition Design pattern to create object repository for web UI elements Extension of Page Object Model that uses @FindBy annotation
Object Repository Objects for each web page stored in separate class Object repository created in the same class
Locating elements FindElement or FindElements used to locate elements @FindBy annotation used to locate elements
Example public class LoginPage{<br>WebElement username = driver.findElement(By.id("username"));<br>WebElement password = driver.findElement(By.id("password"));} public class LoginPage{<br>@FindBy(id = "username") WebElement username;<br>@FindBy(id = "password") WebElement password;}
Initialization No need for initialization Requires initialization using PageFactory.initElements()
Usage LoginPage login = new LoginPage();<br>login.username.sendKeys("name"); LoginPage login = PageFactory.initElements(driver, LoginPage.class);<br>login.username.sendKeys("name");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment