Software Development and QA Tips By QASource Experts

Why Do We Use Assert in Selenium?

Written by Timothy Joseph | Apr 26, 2021 4:00:00 PM

Assertions are validations or checkpoints for an application and are used to indicate if an application's behavior is working as expected. They also help testers know if their test cases have passed or failed.

The reason why assertion is implemented with an automation framework or tool is to verify whether the given condition is fulfilled or not. If the condition is not completely met, then assertion(s) allow the user to simply terminate the current test case and move the execution pointer to the next text case.

Usually, Selenium does not provide any interface or class to handle the assertion, so QA engineers use TestNG to fulfill these. TestNG contains a class named "Assert" which provides a series of methods to apply assertions.

Below are some of the commonly used methods:

  • AssertTrue
  • AssertFalse
  • Fail
  • AssertEquals