Assert and Verify can be used for verification in Selenium and they have their own differences for execution as follows.
Assert: Assert will throw an exception and execution will be stopped if expected condition does not met. Following is an example of Assertion in Selenium with Java.
Example Code:
String expectedText= “Google”;
WebDriver driver = new ChromeDriver();
driver.get(“https://www.google.com”);
String actualText = driver.getTitle();
Assert.AssertEquals(expectedText,actualText );
Verify: Verify does not stop the execution and selenium test continue to the next step after verify the condition. Following is the example for verify in Selenium with Java.
Example Code:
String expectedText= “Google”;
WebDriver driver = new ChromeDriver();
driver.get(“https://www.google.com”);
String actualText = driver.getTitle();
If(expectedText.Equals(actualText)){
System.out.println(“Title matches with expected value”+expectedText);
}
else{
System.out.println(“Mismatch with title. Expected value”+expectedText+”Actual Value”+actualText );
}