Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Page objects inside page objects? #1610

Closed
hurjup opened this issue Mar 6, 2019 · 1 comment
Closed

Question: Page objects inside page objects? #1610

hurjup opened this issue Mar 6, 2019 · 1 comment
Labels

Comments

@hurjup
Copy link

hurjup commented Mar 6, 2019

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 like

@FindBys({@FindBy(xpath="xpath_to_root_of_tile"), @FindBy(xyz = comment_element_locator)})
public WebElementFacade numberOfComments;

Thank you in advance!

@wakaleo
Copy link
Member

wakaleo commented Mar 6, 2019

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/).

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants