What is the difference between Assert and Verify in Selenium

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 );

}

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox
Scroll to Top
0
Would love your thoughts, please comment.x
()
x