ExtentTestEventListener

package com.mridul.software.automation.listeners;  
 import com.aventstack.extentreports.ExtentTest;  
 import com.mridul.software.automation.tests.TestEvent;  
 import org.springframework.context.ApplicationListener;  
 import static com.google.common.base.Preconditions.checkNotNull;  
 public class ExtentTestEventListener implements ApplicationListener<TestEvent> {  
   private static final ThreadLocal<ExtentTest> TEST_THREAD_LOCAL = new ThreadLocal<>();  
   public void setExtentTest(ExtentTest test) {  
     TEST_THREAD_LOCAL.set(test);  
   }  
   @Override  
   public void onApplicationEvent(TestEvent event) {  
     ExtentTest test = TEST_THREAD_LOCAL.get();  
     checkNotNull(event, "test event is not received!");  
     checkNotNull(test, "extent test not initialized to receive events!");  
     switch (event.getTestEventType()) {  
       case INFO:  
         test.info(event.getMessage());  
         break;  
       case WARNING:  
         test.warning(event.getMessage());  
         break;  
       case PASS:  
         test.pass(event.getMessage());  
         break;  
       case FAIL:  
         test.fail(event.getMessage());  
         break;  
       default:  
         throw new UnsupportedOperationException(  
             event.getTestEventType().name() + " is yet to be implemented!");  
     }  
   }  
 }  

Comments

Popular posts from this blog

FileSystemUtils

Report

AbstractTestNgBaseTest