Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

java - How to work with Extent Report in Parallel Execution

I am using extent reporting in Bdd+Testng for reporting. My requirement is we need to execute feature file in parallel. So when my extent report is generated it gets messed up. I know we need to use some threading concept here but i dont know how to use it. Basically, i need below -

  1. Before every Test Tag I need to generate a separate report.
  2. For every Scenario Node should get created.

Below are my code -

    **Report.class**

public static SoftAssert s_assert = new SoftAssert();
    static String reportName;


    public synchronized static ExtentHtmlReporter StartHtmlIndivdualTCReport(ExtentHtmlReporter htmlReporter, String browserName, String ResultFolder, String SuiteName)
    {   
        reportName  = ResultFolderPath+ SuiteName+"_"+browserName +"_"+ Utilities.DateTimeString() + ".html";
        htmlReporter = new ExtentHtmlReporter(reportName);      
        htmlReporter.config().setDocumentTitle("Automation Test Execution Report");
        htmlReporter.config().setReportName("Automation Test Execution Report");
        htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        htmlReporter.config().setTheme(Theme.STANDARD);
        return htmlReporter;
    }



    public synchronized static ExtentReports StartExtentReport(ExtentHtmlReporter htmlReporter, ExtentReports extent) {
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
        extent.setSystemInfo("OS", System.getProperty("os.name")); 
        extent.setSystemInfo("Browser", Utilities.getProperty("Browser"));
        extent.setSystemInfo("Execution Environment", Utilities.getProperty("ExecutionEnvironment"));       
        return extent;
    }


    public synchronized static ExtentTest testCreate(ExtentReports extent, String Stepdetails) {
        return extent.createTest(Stepdetails, Stepdetails);

    }

BaseClass -

    public static ExtentTest test;
    public static ExtentTest Childtest;
    public static ExtentReports extent;
    public static ExtentHtmlReporter htmlReporter;
    
      public static ThreadLocal<ExtentHtmlReporter> htmlReporter1 = new ThreadLocal<ExtentHtmlReporter>();
      public static ThreadLocal<ExtentReports> extent1 = new ThreadLocal<ExtentReports>();
        public static ThreadLocal<ExtentTest> test1 = new ThreadLocal<ExtentTest>();
        public static ThreadLocal<ExtentTest> Childtest1 = new ThreadLocal<ExtentTest>();

/**
     * Function which calls in BeforeSuite Method (TestRunner.java)
     */
    public void beforeSuite()   {   
        System.out.println("In Function --- " + new Object() {}.getClass().getEnclosingMethod().getName());         
        ResultFolderPath = systemDir + "\ExecutionReports\" + TechnicalComponents.getCurrentYear() + "\";
        CloudResultFolderPath = systemDir + "\CucumberReports\";
        Utilities.CreateFolder(ResultFolderPath);
        ResultFolderPath += TechnicalComponents.getCurrentMonth() + "\";
        Utilities.CreateFolder(ResultFolderPath);
        ResultFolderPath += TechnicalComponents.getCurrentdate_MMDDYYYY() + "\";
        Utilities.CreateFolder(ResultFolderPath);
        TargetCucumberReport = systemDir + "\target\cucumber-JVM-reports\" ;
        ScreenShot_ResultFolderPath = ResultFolderPath + "\ScreenShots";       
        Utilities.CreateFolder(ScreenShot_ResultFolderPath);
        excelReport = ResultFolderPath + "\TestExecutionSummary.xlsx"; 
    }



    /**
     * Function which calls in BeforeTest Method (TestRunner.java)
     */
    
    public void beforeTest(ITestContext ctx) {  
        System.out.println("In Function --- " + new Object() {}.getClass().getEnclosingMethod().getName()); 
        String [] suiteName = ctx.getCurrentXmlTest().getSuite().getName().split("\_");
        String testName = ctx.getCurrentXmlTest().getName();
        System.out.println("********** Test Tag Name - "+testName);
        SuiteName= suiteName[0];    
        htmlReporter = Report.StartHtmlIndivdualTCReport(htmlReporter, executionbrowser,ResultFolderPath, testName);
        htmlReporter1.set(htmlReporter);        
        extent = Report.StartExtentReport(htmlReporter, extent);
        extent1.set(extent);
        browsername = ctx.getCurrentXmlTest().getParameter("browserName");
        if(browsername==null) {
            browsername="chrome";
        }
    }



    /**
     * Function which calls in @Test Method (TestRunner.java)
     */
    public void beforeFeatureFile(CucumberFeatureWrapper cucumberFeature) {
        System.out.println("In Function --- " + new Object() {}.getClass().getEnclosingMethod().getName()); 
        String featurefilename = cucumberFeature.toString();
        System.out.println("Execution of Feature File - "+featurefilename);
        List<Tag> featurefile1 = cucumberFeature.getCucumberFeature().getGherkinFeature().getTags();
        TestSetup.Category = featurefile1.get(0).getName().replaceFirst("@", "");
        test = Report.testCreate(extent,featurefilename);
        test1.set(test);        
        dticount=0;
    }


    

public void afterTest(ITestContext TCName){
        System.out.println("In Function --- " + new Object() {}.getClass().getEnclosingMethod().getName()); 
        Report.endReport();
    }



 
question from:https://stackoverflow.com/questions/65829576/how-to-work-with-extent-report-in-parallel-execution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...