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

Remove All Occurrences of a Given Character using Two Pointer Approach

  - 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 𝗣𝗮𝗰𝗸𝗮𝗴𝗲 𝗳𝗼𝗿 𝗧𝗲𝘀𝘁 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 & 𝗦𝗗𝗘𝗧: https://topmate.io/sidharth_shukla/6053...