![]() |
In Selenium, assertions are used for verification or checkpoints in the test case. If assertion is not used in the test case, it’s not possible to determine whether the test case is passed or failed. Assertion will be used to generate the test execution reports. And if all the test steps present in the test cases passed successfully, then assertion will not impact the test. It will report only when a test case is failed. Types of Assertion States in Selenium1. assert Equal / assert Not EqualassertEqual: Verifies if the expected value matches the actual value or not. If both expected value and actual values are equal then it will pass the test otherwise throws an error. Syntax:
Example: In this example expected value and actual value are equal. It will run the test successfully. Python3
Output: assertNotEqual: Verifies if the expected value does not match the actual value or not. If both expected value and actual values are not equal then it will pass the test otherwise throw’s an error. Syntax:
Example: In the below example both expected value and actual value are equal. assertNotEqual will run the test successfully only if both the values are not equal. It will throw an error. Python3
Output: 2. assertTrue/assertFalseassertTrue: Verifies whether the given condition is true or not. If it is true then it will continue the test otherwise throw’s an error Syntax:
Example: Both actual and expected titles are the same. so it will enter into the if condition and verify the assertion. if it is true, it will run the test. Python3
Output: assertFalse: Verifies whether the given condition is false or not. If it is false then it will continue the test otherwise, an error Syntax:
Example: Both actual and expected titles are the same. so it will enter into the if condition and verify the assertion. if it is false, it will run the test otherwise throw’s an error. Python3
Output: 3. assertIn / assertNotInassertIn: Verifies whether the given element is present in a specified sequence or not. If it is present then it will continue the test otherwise throw’s an error. Syntax:
Example: The word GeeksforGeeks is present in the title It will pass the test Python3
Output: assertNotIn: Verifies whether given element is not present in specified sequence or not. If it is not present then it will continue the test otherwise throw’s an error. Syntax:
Example: The word ‘Example’ is not present in the list. So it will throw an error. Python3
Output: 4. assertIsNone / assertIsNotNoneassertIsNone: Verifies if the value is none or not. If the value is none it will execute the test. Syntax:
Example: The value of the title is not none. so it will throw an error Python3
Output: assertIsNotNone: Verifies if the value is not none or not. If the value is not none it will execute the test. Syntax:
Example: The value of title is not none. so it will pass the test Python3
Output: |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |