Skip to content

Page Objects

Marcus Kaufmann edited this page Jan 19, 2018 · 9 revisions

Page Objects are a pattern that describes how to wrap functionality of a web page. Page Objects simplify web pages to simple objects and reduce the amount of duplicated code. In order to reuse once written code even more we introduce the concept of Components to implement functionality that is shared between different pages at on place.

Table of Content

Introduction

Page Objects are described at different places e.g. Selenium PageObjects or Martin Fowler PageObject. Since we use Selenide for scripting we also use their way of handling them Selenide Page Objects.

Page Objects objectives:

  • be stateless
  • act as API to wrap the functionality of the web page
  • prevent code duplication
  • hide the selectors from the test cases

Components

A lot of pages of a web site share elements with the same functionality e.g a search field, a mini cart, a navigation or a user menu. In fact are those elements products of one implementation in a normal web development environment. So why should we duplicate our code to interact with those for each Page Object? We wanted to use a concept that follows the same objectives as Page Objects. We thought about it and came up with Components.

They help to separate code into maintainable amounts since most of the components have a small set of interactions. We use them to build different kinds of Basic Page Objects that share mostly the same functionality and differ only in their site specific code. E.g. a search result page, a product list page and a product page share the same header and footer and differ in the main content. So we implement the header and the footer as components that can be used within the pages while the page object classes just implement the interactions and validation of their specific content.

Clone this wiki locally