Soft & Hard Assert in Selenium Automation
package com.selenium.test;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class Assertion2 {
//Soft Assertion: If any validation fails,
//it will continue the rest of the script and once script completes,
//then it fails the test.
@Test
public void testSoft() {
SoftAssert assertion = new SoftAssert();
System.out.println("TestCase Started- testSoft");
assertion.assertEquals(12, 13, "Value doesn't match");
System.out.println("TestCase Completed- testSoft");
//this will be displayed even if above step is failed
assertion.assertAll();
// A mandatory step. must be written at the end.
}
//Hard Assertion: If any validation fails,
//it will not continue the rest of the script.
@Test
public void testHard() {
System.out.println("TestCase Started- testHard");
Assert.assertEquals(12, 13);
System.out.println("TestCase Completed- testHard");
//this will be displayed only if above step is passed
}
}