Hiya testers! Gazing into the crystal ball, I see there is a great need for assertion and verification in our day-to-day testing lives. So here we are, in the middle of nothing, dedicating one complete blog to this very topic for more brilliance.
While testing web applications, we keep expecting a lot of things to happen in a certain way. And if they don’t, then we declare the test as failed and either abort execution or log that particular exception for further analysis and continue with the testing activity. So, these two decisions result in two different sets of commands in Selenium – Assert and Verify.
Major difference between the two is, Assert will fail the test and abort the execution of the current test case whereas, Verify will fail the test but continue to run the test case.
You may wish to check if a particular text is available on the fifth paragraph of the page. What is the use of performing such a check if the navigated page itself is wrong? In such case, it is advisable to assert the page URL and then verify if the text is present as expected.
You may wish to check the availability of more than one attribute on a page. This can be accomplished by verifying the presence of each attribute as the test case will not be aborted on encountering the first failure. This will help you to review all the failures of the page at the same time and take required action.
Time to play! Let us assert the title of the page Gmail and make a text, back arrow and hyperlink verifications.
Firstly, let us consider an all positives scenario. We navigate to the right page, the Title is Gmail, upon entering the email and clicking next there is a text “One account. All of Google.”, a back arrow and a hyperlink to “Sign in with a different account” present as expected. The test case is a success.
Secondly, let us try to an assert failure scenario. We will open google page and assert its title to be “selenium – Google Search”. This will fail and abort the test case as the current page title will be “Google”.
Finally, we will fail a verify statement and make sure the test case continues to execute even after logging an error and failing the test case as a whole. Open google page, assert its title to be ‘Google’, verify the button ‘Google Search’, verify the hyperlink ‘Gmail’ with value ‘Gmail’ and verify the presence of google apps icon.
By changing the value of the hyperlink to ‘Gmail11’ instead of ‘Gmail’, the verify command will fail but the test case continues executing logging the error.
Watch out! You might bump into “Element Not Found” error. It gets weirder:
Even if the command is just a verify and the element we are trying to verify is not present on the page, then the consecutive steps are not executed and the test case is failed. Since verify is usually used to check the presence of the text and if the element itself is not found, then a bug is expected to be present in the app which needs immediate addressing to. Hence the result.
Time for some break fellas! Practice few scenarios and deepen your knowledge as assert and verify will sooner or later become an important part of your life in SeleniumVille. See you again in another post!
Have a great day ahead!