2

I am writing a script in Selenium and TestNG to automate Add User profile pages.

Now, when I land on every new page, then do I need to write Assert.equals("add user profile", driver.gettitle()); on every page. Is it a bad design if I don't do this?

2 Answers 2

2

NO, don't litter tests with loads of asserts.

Have one test that you have reached the correct page.

Other tests should navigate to the page and then perform additional actions which are tested. If navigating to the page actually fails the tests that do that in order to reach their pages or elements will fail.

Ideally whatever pre-conditions are required are set up in the test itself to avoid needing to navigate and perform other actions to set up the test. However this kind of setup ('grey box testing') is usually much harder than just navigating to the page and takes a much more mature testing model

Another example is authentication. Hundreds of tests may require authentication, but if auth fails you don't want to have hundreds of failures. This is usualky the place when grey box testing starts, for example coming up witha method to provide an dummy auth token that can be used for the test.

5
  • Thanks for your answer. So writing lot of Assert statements is considered Grey box testing 🤔
    – Nitin67
    Sep 11, 2021 at 11:37
  • 1
    No. Grey box testing is setting up the conditions yiou need using code instead of using the UI to navigate and set up the conditions. It will require heavy involvement from the application development team who will need to partner with you. This needs senior management buy-in to get off the ground and be supported. Head of application development and head of quality need to both be on board. It's going to require a lot of work and a lot of time. The investment is huge and the pyayoff is huge. Sep 11, 2021 at 11:40
  • Addressing authentication is frequently where you will start this journey, providing a backend solution to this need and not using the UI to login. And not storing usernames and passwords to be used in login screens thru UI automation. Sep 11, 2021 at 11:42
  • Okay got it...Thanks
    – Nitin67
    Sep 11, 2021 at 11:42
  • No problem. Feel free to upvote and/or accept the answer if you find it useful. Sep 11, 2021 at 11:44
0

Verify page title in base page constructor only once

I think the right way is to create a constructor which verifies page title automatically on each page object initiation.

This approach will be DRY as you will be creating constructor function in base class only once therefore you don't need a separate function in each page object class to verify title and page load .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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