Introduction to Page Object Model Framework

Posted By : Neha Saini | 24-Nov-2017

Page Object Model-POM

 

Page Object Model is a Framework.It is a very popular test automation framework in the industry and most of the companies are applying it for automation testing because it is easy to maintenance test and reduces the duplicacy of code. Page Object Model", is a design pattern in UI automation testing.

Main advantage of Page Object Model:-

Main advantage of POM is that, if there in any changes in UI of any page, then  there is no need to change any tests, we just need to change the code within the page objects (Only at one Place)

public class SignInPage

{
private WebDriver driver;
private By PageTest = By.cssSelector(“.hidden-small:);
private By createAccLink = By.id(“link-signup”);
private By emailTxtBox = By.id(“Email”);
private By pwdTxtBox = by.id(“Password”);
Private By loginButton = By.id(“signIn”);
private By errorMessageTxt = By.id(“errormsg_0_password”);
}

 

In the above code, we have identified the web elements using locators and defined it after the class that means on the top. In this way, we can achieve readability of test scripts and it is easy to identify locators and change them if required at only one place.

 

Advantages of the Page Object model:-

  • There is the clear separation between Locators and layout such as test code and page specific code.

  • There is Only one repository offered by the page.This repository is used for the services or operations rather than scattered these services through out the tests.

  • Increases code re usability – This means, code to work with the events of a page is written only once and used in different test cases.

  • Improves code maintainability – If there are any changes of UI on the pages, updating the code in page object classes only leaving the test classes unaffected.

Take a simple login example:

 /*

Tests login functionality
*/
public void loginTestCase()
{
driver.navigate().to(URL);
driver.findElement(By.name(“signin”)).click();
driver.findElement(By.id(“username”)).sendKeys(“user”);
driver.findelement(By.id(“password”)).sendkeys(“password”);
driver.findElement(By.name(“loginbutton”)).click();
WebDriverWait wait = new WebDriver(driver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“profile”)));
String Expectedresult = driver.findelement(By.id(“message”)).getText();
Assert.assertEqualsIs(Expected,”Welcome”);
}

 

In future, if UI has been changed it must be changed in multiple places. It will be difficult for us to identify where these locators are used as the changes of locators is being used in multiple tests are more.

public void loginTestcase()
{
//go to home page.
homePage.gotoHomePage();
//Click on SignIn link.
accountLoginPage=homepage.clickOnSignIn();
//Verify if user is navigate to SignIn page.
Assert.assertTrue(accountLoginPage.varifyPage());
//Login to The Account.
AccountLoginPage.userLogin(username,password);
//Verify if user is navigated to user home page after successful Login
Assert.assertTrue(userHomePage.verifyPage());
}

In the above code, we did not use any locators. It is separated by driver.findElement 's, waits, exceptions and no static values.

 

Related Tags

About Author

Author Image
Neha Saini

Neha is a QA Engineer in Oodles and have good knowledge of Manual Testing and Automation Testing , always eager to learn new things.

Request for Proposal

Name is required

Comment is required

Sending message..