Assert in Selenium

Assert is to compare the expected with actual.

Fails i.e if expected != actual, then test execution stops with exception: java.lang.AssertionError
Else, Program continues normal flow after checking the Assert

Assert.assertTrue: is to evaluate a condition

Best example is login, if logged then continue else stop executing rest of the test case.
To check if a table exist or not, if not present, then no need to loop through the content..

Let’s see the implementation of Assert.

Assert.assertEquals statement:


To avoid skipping the rest of code if Assert fails, then catch the exception and fail the testcase, then continue to the next test case (mostly in framework)
Example of handling the assertionError using try catch block
Let’s look into a +ve scenario, where Assert passes….





Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *