Thursday, January 30, 2014

Selenium : Report Error in TestNG without Halting the Execution

 Report Error in TestNG without Halting the Execution

 

 

Note:

  1. Extend your class with "SeleneseTestBase"
  2. Declare a member varibale of type "StringBuffer".
Ex: 
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);  
    }

No comments:

Post a Comment