Assertions in selenium
In Selenium, assertions are used to validate whether certain conditions are true during test execution. They are crucial for ensuring the correctness and reliability of automated tests. Assertions help verify that the expected behavior of a web application matches the actual behavior encountered during testing.
Assert Equals — assertEquals, assertNotEquals.
Assert Boolean — assertTrue, assertFalse.
Assert None — assertNull, assertNotNull.
Assert Identical — assertSame, assertNotSame.
public void step4() {
String expectedErrorMessage = “Invalid login details. Please check your username and password.”;
String actualErrorMessage = loginPage.getErrorMessageText();
boolean condition = actualErrorMessage.equals(expectedErrorMessage);
Assert.assertTrue(condition, “The actual text is not as expected. Expected: ” + expectedErrorMessage
+ “, Actual: ” + actualErrorMessage);
System.out.println(“Page contains text: ” + actualErrorMessage);
}