What is POM?
POM is a design pattern which is commonly used in Selenium for Automating the Test Cases. This design pattern can be used with any kind of framework like keyword-driven, Data-driven, hybrid framework, etc.
The Page object is an object-oriented class which acts as an interface for the page of your Application under test. Page class contains web elements and methods to interact with web elements. While Automating the test cases, we create the object of these Page Classes and interact with web elements by calling the methods of these classes.
Page Object Model Design Pattern
Uses of Page Object Model (POM):
This Design Pattern is used in Selenium where web pages are represented by a corresponding class and web elements are represented by the variables of the class and all interactions are possible through the methods or say functions of the class.
Advantages of POM model:
- Reusability: We can reuse the page class if required in different test cases which means we don’t need to write code for identifying the web elements and methods to interact with them for every test case.
- Maintainability: As we can see from the above picture test case and page class are different from each other which means we can easily update the code if any new web element is added or existing one updated.
- Readability: As we can see in the above picture page code is separated form test code which helps to improve code readability.
Implementation of Page Object Model:
Here I’m taking the example of Gmail application to show the implementation of POM.
The Project Hierarchy of my Maven Project is shown below:
In this class we create the object of WebDriver class, maximize the browser, launching Url etc.
In this class, we identify the web elements of Gmail Login Page and methods to interact with these web elements.
Similarly, we write the code for Gmail Home Page.
In this class we test the login page of Gmail.
- How to display search result of another page on same page using ajax in JSP?
- How to redirect a page to another page in HTML ?
- How to show Page Loading div until the page has finished loading?
- Introduction to Model View View Model (MVVM)
- PHP | Type Casting and Conversion of an Object to an Object of other class
- CSS | @page rule
- ES6 | Page Redirect
- Refresh a page using PHP
- ES6 | Page Printing
- Download web page using Java
- CSS page-break-before Property
- How to get the title of an HTML page ?
- How to refresh a page using jQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.