Report Error in TestNG without Halting the Execution
Note:
- Extend your class with "SeleneseTestBase"
- Declare a member varibale of type "StringBuffer".
Class abc extends SeleneseTestBase{
StringBuffer verificationErrors=new StringBuffer();
@Test
----------
----------
----------
}
Code Here :
@Test
public void test1() throws InterruptedException {
try{
driver.findElement(By.xpath("//*[@id='containerrrr']/div[2]/h2"));
}catch(Throwable t)
{
verificationErrors.append(t.getMessage());
Reporter.log("test1: object not found"+"<br>");
}
String fail_reason=verificationErrors.toString();
clearVerificationErrors();
if (!"".equals(fail_reason))
fail(fail_reason);
}
public void test1() throws InterruptedException {
try{
driver.findElement(By.xpath("//*[@id='containerrrr']/div[2]/h2"));
}catch(Throwable t)
{
verificationErrors.append(t.getMessage());
Reporter.log("test1: object not found"+"<br>");
}
String fail_reason=verificationErrors.toString();
clearVerificationErrors();
if (!"".equals(fail_reason))
fail(fail_reason);
}