Whenever the discussion for Automation Frameworks arises, one name comes up in an instant - Page Object Model (POM). There was a lot of hype on POM when it arrived, due to its multiple advantages.
But, is it really that advantageous?
The page object model is the most popular and widely used framework for automating any web application.
According to Selenium, "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. It reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place."
The Page Object model is useful to achieve modularity in our code. Code reusability will be increased. If there is a change in the UI in the future, we can easily update our business method concerning the new change if we follow the page object model.
In the page object model, we can define all the locators and functions(actions) of a web page in a separate Js file. Let's say we have a login page that is our page under test. We write all the elements(Login field, Password Field, Sign In button, etc..) and operations(enter a username, enter the password, click sign in, getLoginPageTitle, etc..) in a single js file(login.po.js).
Advantages of the 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: In the POM, 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: In the POM, page code is separated from the test code, which helps to improve code readability.