Should assertions conditions be done in the page Objects, or in the Test classes?

I do multiple things, basically trying to stay DRY (Don’t repeat yourself - so I do not have multiple places to refactor or fix):

  • very basic and reoccurring actions and checks related to that page I do either in the Page Object class or in a utility class named similar.
  • for more complex reoccurring actions and checks, sometimes covering multiple pages, I create dedicated utility classes. E.g. one for login.
  • in the test class I call this other methods and add just what is unique to it.

e.g. I need to check a drop-down menu having different content at different test cases. Then I develop a utility method at a common place which does all the necessary interaction with component(s) and have as parameter only the list of entries to check for.
(sometimes it needs multiple actions on a page to get to that drop-down menu. e.g. opening “closed” elements)

Know your code, give it good structure and good names to methods.
Then you can “hide” many things behind methods.

I’m here not a friend for “black vs white” and academic fights which approach is better. It is grey at best and you need sometimes this approach and sometimes that approach.
Every problem needs an context depended solution.

2 Likes