0

As it seems page object model and page factory is doing same thing. So i am confused.

IpmObjectInitializer initialize = new IpmObjectInitializer(driver.getWebDriver()); 

// Initialize elements in BatchCreationPageFactory class

batchCreationPageFactory = initialize.getBatchCreationPageFactoryObj(); 

2 Answers 2

6

Page Object is a class that represents a web page and hold the functionality and members.

public class LogInPage { private WebElement userName; private WebElement password; public LogInPage() { } public void locateElements() { userName = driver.findElement(By.id("userName")); password = driver.findElement(By.id("password")); } public void doLogIn() { userName.sendKeys("qwe"); password.sendKeys("123"); } } 

Page Factory is a way to initialize the web elements you want to interact with within the page object when you create an instance of it.

public class LogInPage { @FindBy(id="userName") private WebElement userName; @FindBy(id="password") private WebElement password; public LogInPage() { PageFactory.initElements(driver, this); // initialize the members like driver.findElement() } public void doLogIn() { userName.sendKeys("qwe"); password.sendKeys("123"); } } 
Sign up to request clarification or add additional context in comments.

Comments

4

Page Object Model (POM)

1.. POM is a Design pattern which segregates selenium code based on pages.

Ex: Create a separate java class for the Login page, one more class for Home Page etc.

2.. A Page Object Model is a way of representing an application in a test framework. For every ‘page’ in the application, you create a Page Object to reference the ‘page’.

Page Factory

1.. Advanced concept ( POM + new features )or

  1. Elements are identified using @FindBy or @FindBys Annotation

  2. Initialism all the elements declared in Point#1 at a time.

( in POM, initialization happens on the fly )

PageFactory.initElements(driver,this);

2.. A Page Factory is one way of implementing a Page Object Model. In order to support the Page Object pattern, WebDriver’s support library contains a factory class.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.