SoftAssert.fail(msg); | Selenium Forum
M
mallikarjun524 Posted on 22/08/2022

package testbase;

import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.asserts.SoftAssert;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;

import reports.ExtentManager;

public class TestBase {
public ExtentReports rep;
public ExtentTest test;
public SoftAssert softAssert=null;

@BeforeMethod(alwaysRun=true)
public void init(ITestResult result)
{

System.out.println("-----------@@BeforeMethod-----------");
//System.out.println(result.getMethod().getMethodName().toUpperCase());
rep=ExtentManager.getReports();
test=rep.createTest(result.getMethod().getMethodName().toUpperCase());
result.setAttribute("reporter", test);
}
@AfterMethod
public void quit()
{
rep.flush();
}

public void log(String msg)
{

//System.out.println("-------------entering log function---------");
System.out.println(msg);
test.log(Status.INFO, msg);

}
public void logFailure(String msg) {// only fails in extent reports
//System.out.println("-------------entering logFailure function---------");

System.out.println(msg);
test.log(Status.FAIL, msg);
}

public void failAndStopTest(String msg) {//fail in testng as well as extent - but stop

logFailure(msg);// fail in extent reports
softAssert.fail(msg); // fail in testng;
softAssert.assertAll();//stop
}

public void softAssert(String msg) {//fail in testng as well as extent - but continue

System.out.println("-------------entering logFailure function---------");

logFailure(msg);// fail in extent reports
softAssert.fail(msg); // fail in testng;
// take screenshot as well - put in reports
}

}