Closed hurjup closed 2 years ago
In short, no. But Page Objects are an anti-pattern, and nested Page Objects doubly so. Tests should test user behaviour, not the UI. A better approach is to use Lean Page Objects or Screenplay (see https://johnfergusonsmart.com/page-objects-that-suck-less-tips-for-writing-more-maintainable-page-objects/).
Hi
Web applications today are typically single url ones. So page objects are better representation of "tiles" on the same level of the webUI, instead of being actual pages: menu bar, status bar, editor area, ...
Let's say there is a tile with sub-tiles; just like here (https://github.com/serenity-bdd/serenity-core/issues) the tickets themselves. The "roots" of these tickets have unique xpaths, but under the located webelement(facade) they have similar structure: icon, title, opened-by, number of comments. Which cries for being represented with pageobjects. Even if I think the answer is 'no', I still feel the urge to raise the question: Is there a way to initialize such sub-pageobjects from the parent pageobject? The happiest path would be providing parameters (like the xpath locator) to the constructor, and the rest would be done "on-demand" (upon invocation) through some serenity dependency injection magic.
More detailed, the imaginary usage:
parent-tile.sub-tile("xpath_to_root_of_tile").numberOfComments.getText();
In the sub-tile all the @FindBy methods would look likeThank you in advance!