Please post your Web Driver questions in official Web Driver forum

Monday, November 21, 2016

What else should page object test?

As we know that objective of page object is to provide services offered by page (or part of it). In its true sense page object does not advocate asserting page condition in page object class. Except the page object constructor which can check if control is on right page on it, like following -

Screenshot from 2016-06-06 15:12:12.png

But this is not the only use case of a check on page object. When returning data set from page object one could also check if data set is empty, for ex following method checks if collection of webelement is empty using Preconditions.checkState() method before returning it’s content -

Screenshot from 2016-06-06 15:16:36.png

In the above code snippet, if element list is empty then page object method would throw IllegalStateException exception. This check could also be carried out on test method which receives the member name list. But I prefer to keep such checks on page object method and focus on assertion on test method. What do you think of this approach? Do you also have such checks in your page object methods?
Fork me on GitHub