The right way to implement Page Objects
I will not venture a claim that the implementation of the Page Objects in this chapter is the right and only way to do it. Just like there are many programming languages and different ways to write code, there are multiple ways to implement Page Objects. Choosing the right approach will be one of the first and most difficult tasks to figure out. I'd like to spend this section talking about different approaches we could have taken when writing our framework.
Making pages smarter than tests
In the framework we implemented, the @selenium
instance is passed between different Page
objects as the test progresses. For example, after we have created an instance of Firefox browser with WebDriver, we pass it into each class like this:
This approach is good because it is clear to see the order of progression from page to page. It's clear to see that @selenium
moves first to the home page and hands off itself to the HomePage
object. Then, the test adds a product...