Page Object Model (or POM), is a design pattern in Selenium in which we create an object repository for storing and organizing the web elements and objects. It is a potent design pattern used in Web/Mobile automation across the globe to reduce code redundancy and test script maintenance.
Doing automation using the Selenium web driver is not a tough job, we just need to locate the exact web element using the different locators in Selenium.
From the above screenshot,
Since the script is small, maintenance is easy. But with time the suite will become more complex and more lines of code will be included hence the code maintenance will be difficult.
Let's discuss some challenges seen with such a practice.
The POM model or Page Object Model is a design pattern or framework in which we will split the Test classes, page classes, and base classes into different packages. The basic idea of the POM model is like, different pages will be separated into different classes and the selectors for those classes can also be separated into different classes.
The below figure shows the sample structure of POM, in which we do have a Base package containing a common class in which the reusable methods are scripted. We do have a Page package and Selector package in which the actions to be performed are wrapped up in methods, and the selectors used for those pages are written under different classes from the Page selector package. And finally, we have the Test package in which different test classes are used to run the test scripts.
Building a test framework is always a cumbersome process, but once you build those frameworks the maintenance of the code will become easier. As we discussed, implementing such practices will reduce code redundancy and promote the reusability of the code hence the optimization. The setting up of a framework may vary from project to project and also will depend on the tester’s easiness, However, the basic concept behind the POM model will remain the same. As automation testers, we should be aware of such frameworks to make our coding practice smoother and easier.
Happy Learning!!