Testing in Selenium is incomplete if we don't have a way to verify our test results. The TestNG framework provides the Assert class, using which we can do validations and verifications in TestNG. We can use assertions to verify text on screen, do validations, and so on.
The most common methods in the Assert class are given here:
- assertTrue(condition, message): Takes two arguments, which are condition and message. A check is done to see whether the Condition is true or not. If the Condition is evaluated as false, then it fails and the message gets printed. The message is optional.
- assertFalse(condition, message): Takes two arguments, which are condition and message. A check is done to see whether the Condition is false or not. If the Condition is evaluated as true, then it fails and the message gets printed. The message is optional.
- assertNull(object...