Extent report is not giving proper report on parallel execution

前端 未结 2 675
[愿得一人]
[愿得一人] 2021-01-15 22:58

ReporterClass.Java:

package POM_Classes;

import com.aventstack.extentreports.AnalysisStrategy;
import com.aventstack.extentreports.ExtentReports;
import com         


        
2条回答
  •  庸人自扰
    2021-01-15 23:11

    //Add below class in your Project. First you need to add the respective object and 
    //call them respectively. Declaring Extent and Driver as static is a big problem in 
    //Parallel/execution.
    //Avoid using static as far as possible by using the below class.
    
    import java.util.ArrayList;
    import java.util.List;
    import org.openqa.selenium.WebDriver;
    import com.aventstack.extentreports.ExtentReports;
    import com.aventstack.extentreports.ExtentTest;
    
    public class WebDriverFactory {
    
    private static ThreadLocal drivers=new ThreadLocal<>();
    private static List storeDrivers=new ArrayList();
    private static List extent=new ArrayList();
    private static ThreadLocal reports=new ThreadLocal();
    
    static 
    {
        Runtime.getRuntime().addShutdownHook(new Thread(){
            public void run()
            {
                storeDrivers.stream().forEach(WebDriver::quit);
            }
        });
     }
    
    
    public static WebDriver getDriver() 
    {
     return drivers.get();
     }
     public static ExtentTest getextentReportObject()   
     {
       return reports.get();
     }
    
     public static void addDriver(WebDriver driver) 
     {
    
        storeDrivers.add(driver);
       drivers.set(driver);
     }
    
     public static void addExtentReportObject(ExtentTest report)    
     {
    
       extent.add(report);
       reports.set(report);
      }
    
      public static void removeDriver()
     {
      storeDrivers.remove(drivers.get());
      drivers.remove();
    
      }
      }
    //Add and Invoke the object in the following way
    
    
      /*** Add and invoke the object in the below fashion **/
    
        WebDriverFactory.addExtentReportObject(extent.createTest("Monitor Scenario 
       ").createNode("Monitor Page Validation"));
       WebDriverFactory.getextentReportObject().assignCategory("@SmokeTest");   
    

提交回复
热议问题