3

As the question title says: If you're putting a test together and you need to wait for an item to be displayed (as an example), is it best to put the explicit wait within the test or against the page?

Any particular reason why one option may be chosen over the other?

Thanks,

3

The choice of such design lies mainly on the product under test, tool, and the language you use.

My personal preference is to:

  1. Add it in Page objects if it's being reused many times
  2. If it's just for 1 test case then, have it in the test suite itself.

The reason for following the practice of not having assertions in page objects was to promote easy debugging. If something fails the engineer knows at which file the assertion was thrown. But nowadays there are tools and highly precise stack traces that point out to the exact line and file at which execution failed.

So do whatever that makes your code clean and easy to read and maintain, there are no hard rules.

But if you really want to, then return a true if wait pass else catch the timeout exception and return a false, and validate it in the test scripts. But I prefer to have it as it is in page object and letting it fail with a custom message.

| improve this answer | |
2

In my experience, it is best to put the waits in the Page Objects. The purpose of the waits are to wait for an element to be displayed or to have the page finished loading, etc (depending on the wait you are using). Using POM, all your elements are in the page object and you write methods that utilize those elements also in the page object. Given this, you put your waits in those methods within the page objects.

The tests themselves should contain the page object class instantiation as well as the asserts.

The main idea of POM is to separate your test logic from your page logic. Waits are considered page logic.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.