The Question:
What is the canonical way to define nested Page Objects in Protractor?
Use Case:
We have a complicated page that consists of multiple parts: a filter panel, a grid, a summary part, a control panel on a side. Putting all the element and method definitions into a single file and a single page object does not work and scale - it is becoming a mess which is difficult to maintain.
The idea is define the Page Object as a package - directory with
index.js
as an entry point. The parent page object would act as a container for child page objects which in this case have a "part of a screen" meaning.The parent page object would be defined inside the
index.js
and it would contain all the child page object definitions, for example:The child Page Object would look like this:
Now, it would be quite convenient to use this kind of page object. You simply require the parent page object and use the dot notation to get access to the sub page objects:
Sample nested page object directory structure from one of our test automation projects: