Monday 16 November 2020

Difference between Soft Assert and hard Assert in selenium?

     Soft Assert vs Hard Assert


A soft assert will run the test and not throw an exception if the assert failed, while a hard assert will throw the exception immediately, and then continue with the testing process.


@Test
public void softAssertion(){
SoftAssert softAssertion= new SoftAssert();
System.out.println("softAssert");
softAssertion.assertTrue(false);
softAssertion.assertAll(); 
}
@Test
public void hardAssertion(){
System.out.println("hardAssert");
Assert.assertTrue(false);
System.out.println("hardAssert");
}
 
Soft Assertions are the type of assertions that do not throw an exception when an assertion fails and continue with the next step after the assert statement. This is used when the test requires multiple assertions to be executed and we want all of the assertions/codes to be executed before failing/skipping the tests. 
 
Hard Assert is a type of TestNG assetion which throws Exception Immediately if the assert statement fails and move to the next testcase and if there is any code in the current test case after assert statement it will not execute that statement.
 

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...