Page Object Model in Selenium
Posted By : Mohd Sheemal | 28-May-2018
Page Object Model in selenium :
POM : Page object model is an object / element design pattern to create repositories for web elements.
Example : Link, Button, Edit box etc.
-> For centralised maintenance of object/elements we create repositories.
Under this model contains classes for web elements are created that behave as as object repories.
We can create page object model in two ways :
1- Page object model,
2- Page object model with page factory.
Page object model :
Page object model without page factory :
No object repository facility in selenium web driver . It is a programing interface . In UFT / QTP we have object repository facility (Local and shared object repository).
-> Under this model for each website in the application, there should be corresponding page class.
-> This page class will find the web elements of the web page and also contains the methods which pe
If no object repository / Our tag object model then it is difficult to maintain objects or elements in testcases.
Advantages of POM :
1- Reusability of elements, reduces code size.
2- It is efficient and scalable .
3- Easy maintenance of elements/objects.
Implement Page object model :
In this approach all page components of the application and client activities on those web components are kept up as strategies inside a class document, by bringing in the page class, we can make testcases.
Create page class :
Requirements – create a page class / object repository using some elements.
(uername, password, login button, error message , only catelog the etc.... )
Create test cases :
login, verify error message, verify re direction.
Example :
package com.amave.com.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class LoginPage
{
WebDriver driver;
By userName = By.name("uid");
By password99Guru = By.name("password");
By titleText =By.className("barone");
By login = By.name("btnLogin");
public void Login(WebDriver driver){
this.driver = driver;
}
public void setUserName(String strUserName){
driver.findElement(userName).sendKeys(strUserName);
}
public void setPassword(String strPassword){
driver.findElement(password99Guru).sendKeys(strPassword);
}
public void clickLogin(){
driver.findElement(login).click();
}
public String getLoginTitle(){
return driver.findElement(titleText).getText();
}
public void loginToGuru99(String strUserName,String strPasword){
this.setUserName(strUserName);
this.setPassword(strPasword);
this.clickLogin();
}
}
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Mohd Sheemal
Mohd Sheemal is a Bright QA Engineer. He has a good knowledge over Selenium.