Selenium WebDriver Page Object Model Framework Introduction

Page Object Model Framework in Selenium WebDriver has come to be very popular Selenium WebDriver test automation framework in the software industry and many IT companies are following this framework because of its easy to

1.write test scripts,
2.script maintenance and
3.reduces the duplication of code

The main merit of Page Object Model in Selenium WebDriver is that if the Web UI changes for any module pages, it don’t require to change any Selenium WebDriver Test Scripts, we just need to change only the Test Page code within the page objects.


Send Extent Reports in Email with Screenshots

Page Object Model Framework in Selenium WebDriver

public class LoginPage{

public static WebDriver driver;

private By pageTile = By.xpath("//input[@title='Selenium WebDriver']");
private By homePage=By.id("home");
private By singInPage=By.id("login");
private By uname=By.id("userName");
private By password = By.id("password");

}

In the above code, we’ve identified the Element locators and defined in the after the class. In this way we can achieve readability of test scripts and we can easily identify Web Element locators and change the Element Locators as per required only in page object classes.
Page Object model in Selenium WebDriver is useful in preparing the AUT functionalities or Reusable components of a Webpage which we want to automate in a separate Test class. Let’s consider as Login Page.

As per Selenium WebDriver ORG Page Object Model is

Generate HTML Reports using Selenium.
How to write Test Cases PASS or FAIL in Excel using Selenium
Pass webdriver instance to multiple classes

"Within your web app’s UI there are areas that your tests interact 
with. A Page Object simply models these as objects within the test code.
This reduces the amount of duplicated code
and means that if the UI changes,the fix need only be applied in one place."


For the above page I’m creating simile class as LoginPage.class. In this class we’ll write reusable methods to call in another class to implement the Test cases.

Example:

Let’s consider entry page as Bing Search Page which will have many options like Search, Sign In, Images, Videos, Maps, News Languages, MSN, Outlook.com links. Here as per user action it will navigates to respective web pages to achieve this all functionalities that we want to automate should have reusable methods/components for each web-page and main Entry screen is Bing Home page ,user can navigate to respective pages by clicking on any Hyperlink from the Bing Search page. Whenever users are navigating to respective pages, has to return particular page objects Otherwise return current page object as this action doesn’t navigate to another page signified by another Page Object.

ALSO READ  How to Generate Reports in Selenium using TestNG

The Page Object model advantages

1.Clean Code between test code and page specific code such as locators and layout.
2.Single Object Repository for all functionalities, No Duplication of codes.
In above situation this allows you to perform modifications only in UI because of CR in current requirements or changes in UI Designs.

ALSO READ  How to handle authentication required in selenium webdriver

As per Selenium WebDriver WIKI Page,There is a PageFactory in the support package that provides support for this pattern, and helps to remove some boiler-plate code from your Page Objects at the same time.

Rajesh K

Leave a Reply

Your email address will not be published. Required fields are marked *