0

If a button is optionally shown on a page (or part of page), does it qualify that part to be represented as two different PageObjects, where one PageObject provides methods to interact with the button while other PageObject does not? Or, should it be one page with a method which can throw an exception when the Button is not rendered.

What will be a maintainable solution - because in future releases the button may start appearing in both cases or the functionality may totally change.

Asad Iqbal
  • 3,241
  • 4
  • 32
  • 52
  • 1
    If the button takes you to a new page then the button should return an instance of that new page object otherwise its part of the current page object. At least that my understanding. – bcar Oct 23 '14 at 02:34
  • @bcar My question is not about what the button should return. I am asking if a page shows a button depending on some user action, should I have two pageobjects for the same page, one with button functionality and the other without button. – Asad Iqbal Oct 23 '14 at 05:53

1 Answers1

2

In this case

the button may start appearing in both cases or the functionality may totally change

possible solution can be - Transporter design pattern. It's basically - navigation that aggregates reused page objects in one external object. Also centralizes the navigation control in the tested system according to the test requirements. This object encapsulates logic associated with the implementation of navigation within the tested system. Thus the problem of business logic does not interfere with the navigation within the system.

I think that Composite Page Object is acceptable and

maintainable solution

in both cases. Since It will allow you to structure your Page objects in a more “object-oriented” way by separating sub objects that can be reused on different pages and include them into the parent object. Consider this example:

enter image description here

Further reading about GUI automation patterns.

ekostadinov
  • 6,880
  • 3
  • 29
  • 47