Prerequisite – Selenium
Actual result is compared with expected result with the help of Assertion. It means verification is done to check if state of the application is same to what we are expecting or not. For creating assertion we are going to use Assert class provided by TestNG.
There are two types of Assertion:-
- Hard Assertions.
- Soft assertions.
These are explained as following below.
1. Hard Assertions :
When any assert statement fails this type of assertion throws an exception immediately and continues with the next test in the test suite.
Hard Assertion can be of following types:-
- assertEquals –
This is used to compare expected and actual values in selenium webdriver. The assertion passes with no exception whenever the expected and actual values are same. But, if the actual and expected values are not same then assert fails with an exception and the test is marked as failed.
- assertNotEquals –
This is just opposite to the assertEquals. The assertion passes with no exception whenever the expected and actual values are not same. But, if the actual and expected values are same then assert fails with an exception and the test is marked as failed.
Assert.assertNotEquals(actual, expected, message);
- assertTrue –
This type of assertion is used when you are checking if condition is true. That is when we are dealing with boolean values this assertion is used. Whenever test case passes it returns true and if condition is false then it skips the current method and jumps to next.
- assertFalse –
It checks if value returned is false or not. Whenever test case passses it aborts the method and gives an exception.
- assertNull –
This assertion checks if the object is null or not. It aborts the test if object is null and gives an exception.
- assertNotNull –
This assertion checks if object is null or not. It aborts the test if object is not null that is if object is having any value and gives an exception.
2. Soft Assertion :
These types of Assertions are the type of assertions do not throw an exception when an assertion fails and continues with the next step after the assert statement.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Find Web Elements using Selenium WebDriver
- Features of Selenium WebDriver
- Limitations of Selenium Webdriver
- Applications and Uses of Selenium WebDriver
- Difference between JUnit and TestNG
- Browser Automation Using Selenium
- Python | SMS Bomber using Selenium
- Non blocking wait in selenium using Python
- Python | Automating Happy Birthday post on Facebook using Selenium
- How to access popup login window in selenium using Python
- How to click a button on webpage using selenium ?
- Search Google Using Python Selenium
- Writing Tests using Selenium Python
- Navigating links using get method - Selenium Python
- How to move back and forward in History using Selenium Python ?
- Cloud-based Automation using Selenium in Python and BrowserStack
- Selenium Python Tricks
- Software Engineering | Selenium: An Automation tool
- Difference between Cucumber Testing and Selenium Testing
- Python - find_element_by_id() method in Selenium
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.