Book Image

Learning Behavior-driven development with Javascript

Book Image

Learning Behavior-driven development with Javascript

Overview of this book

Table of Contents (17 chapters)
Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing the Page Object pattern


If we have a look at the code we have written, we will realize that the tests are a bit ugly. The tests are not very readable because there is a lot of references to the WebDriver API that is a bit low-level. Furthermore, there are many CSS selectors throughout all the tests. This produces two main problems:

  • Excessive verbosity and a lack of readability in the tests due to all these references to CSS selectors and the WebDriver API.

  • Difficult maintenance. A change in the structure of the HTML can break our tests, because the specified CSS selectors are no longer valid. The problem is not the fact that the tests get broken, but that we need to review all the tests, looking for the selectors that we need to fix. This is because the same CSS selector can be referenced in several tests that depend on the same element.

The Page Object pattern intends to solve these problems by encapsulating the details of accessing the elements of a page and interacting with it...