Selenium Page Object Model


The Page Object Model is a design pattern to create an object model for Web UI elements, you can map every page to one-page object model class, the elements which are on the page are going to be properties of the class the main advantage of this is you can re-use this object model, the page object model makes your code reusable and avoids code duplication

Let me take simple scenario, the home page of my blog has search functionality and the category page also has search functionality, I want to test search functionality on home page and on category page


here, what I am going to do is creating an object model for search functionalities and re-use it on different test cases, check the below code, I have created page object model only once and that is for search elements and re-using it in multiple test cases

Another advantage is we don’t need to touch test cases if something changes in page object models, there is a clear separation between models and test cases, check the below screenshot, there are different package’s for models and test cases


Download code