Creating a Page Objects framework
Now that we have a theoretical knowledge of Page Objects, let's put it to use. When building a new Page
class, we can take multiple approaches to implement. We can use any tool that our OOP language provides for us. For this example, we will be using the inheritance as a way to quickly create new Page
classes.
Note
Inheritance is a feature of OOP languages, which allows new classes to be based on another class, creating a subclass. The newly created subclass inherits all of the functionality of the parent class.
The majority of the web pages on our site follow a similar pattern of display: header, body, sidebar, and footer. This means we can create a generic Page
class that will provide us with access to different sections of the page.
Creating a page super class
The first step of the implementation is to create a page.rb
file that will host our class. The code inside will look like this:
This class will provide us with access to different parts of every page...