Chapter 7. The Page Object Model (POM)
A design pattern is a reusable solution to a recurring problem in software engineering. This chapter presents the Page Object Model (POM), a popular design pattern used to develop Selenium WebDriver tests. The use of POM has different benefits, such as improving reusability and avoiding code duplication. POM is based on creating page classes for modeling the SUT UI in a single repository, which is later used from the test logic.
Motivation
Some of the biggest challenges of developing end-to-end tests with Selenium WebDriver are maintainability and flakiness. Regarding the former, the problem might happen during the development or evolution of the SUT. The changes made in the UI can cause existing end-to-end tests to break. The maintenance costs for fixing these tests can be relevant when having a large test suite in which code duplication exists in several tests cases (e.g., when the same locators are used repeatedly in different tests).
Concerning flakiness (i.e., lack of reliability), a test is flaky when it has inconsistent behavior, i.e., it both passes and fails periodically under the same conditions (test logic, input data, setup, etc.). There are two major causes of test flakiness in Selenium WebDriver tests. First, the root of the problem might be the SUT. For instance, a bug in the server-side logic (e.g., a race condition) can expose erratic behavior in end-to-end tests. In this case, developers and testers should work together ...
Get Hands-On Selenium WebDriver with Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.