Page Object Model using Selenium WebDriver

Author: Shiffy Jose

A Test Automation Framework is a collection of re-usable methods which helps in automating test process. The three most common automation frameworks for Selenium WebDriver available in the market are data-driven framework, hybrid framework and page object model.

Page Object Model (POM) is one of the robust design patterns in automating test cases using Selenium WebDriver when compared to other frameworks. POM framework reduces or even eliminates duplicate test code, supports code re-use and we can create tests with less keystroke. In this design pattern, each web page in an application has a corresponding page class. This confirms the better maintainability of such automation codes. An implementation of the Page Object Model can be achieved by separating the test object, the test scripts and externalization of data.

The process of the framework can be divided into the following steps. First step will be separating data from the test code. Data should be kept in separate file like Excel, Property Files or any type of file which can be varied from project to project. Once the data separation is completed, test automation can proceed further on creating the base page class where all the initializations are to be performed. This is flowed by creating page class corresponding to each web page. All the functions/methods relating to each page is written in the corresponding page class (this avoids duplication of code). So now is the time for test execution.

Test Execution is performed with the help of JUnit or TestNG. Each test case is taken into consideration then methods from the dependant page classes are called and assert method is invoked to decide if the test case is a pass/fail. This is the overall picture for the POM. For overall test case execution, we could even use build tools like ANT or Maven. Test Report for the entire test cycle can be generated using ‘XSLT Reports’ which provides complete test results.