Skip to Content
Hands-On Selenium WebDriver with Java
book

Hands-On Selenium WebDriver with Java

by Boni Garcia
March 2022
Intermediate to advanced
419 pages
9h 59m
English
O'Reilly Media, Inc.
Content preview from Hands-On Selenium WebDriver with Java

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learn Selenium WebDriver with Java

Learn Selenium WebDriver with Java

Mayur Deshmukh

Publisher Resources

ISBN: 9781098109998Errata Page