简体   繁体   English

当我们使用 TestNG 并行执行运行脚本时,范围报告 output 未正确生成。 (范围报告版本 3.1)

[英]Extent report output is not getting generated properly when we Run the scripts using TestNG parallel execution. (Extent Report Version 3.1)

public class ExtentReports_Basecode {

    static Random rand = new Random();
    static long drand = (long)(rand.nextDouble()*10000000000L);

    public WebDriver dr;
    public static ExtentHtmlReporter htmlReporter;
    public static ExtentReports extent;
    public static  ExtentTest test;

    private static String filePath = "D://" + drand + "ExtentReports_Bindu.html";

    @BeforeSuite
    public void setup()    {

        htmlReporter = new ExtentHtmlReporter(filePath);
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);

        extent.setSystemInfo("OS", "Windows10");
        extent.setSystemInfo("Host Name", "Bindu");
        extent.setSystemInfo("Environment", "rose");
        extent.setSystemInfo("User Name", "1234_ws");

        //htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
        htmlReporter.config().setReportName("Favourite Automation Report");
        htmlReporter.config().setTheme(Theme.DARK);
    }

    @BeforeMethod
    public void startTest(Method m)
    {
        test = extent.createTest(m.getName(),"This is the description of Test" + m.getName());

    }

    @AfterMethod
    public static void getResult(ITestResult result){

        if(result.getStatus()== ITestResult.FAILURE){
            test.log(Status.FAIL,MarkupHelper.createLabel(result.getName() + "Test case FAILED due to below issues:",ExtentColor.RED));
            test.fail(result.getThrowable());
        }
        else if(result.getStatus()== ITestResult.SUCCESS){  
            test.log(Status.PASS,MarkupHelper.createLabel(result.getName() + "Test Case PASSED",ExtentColor.GREEN));

        }
        else{
            test.log(Status.SKIP,MarkupHelper.createLabel(result.getName() + "Test Case Skipped",ExtentColor.YELLOW));
            test.skip(result.getThrowable());
        }

    }


    @AfterSuite
    public void teardown(){
            extent.flush();
    }


}

Script1:脚本1:

public class sc1 extends ExtentReports_Basecode{

    public WebDriver dr;
    public Report report = null;
    String inputSheetPath ="TestData/InputData/DataSheet.xls" ;

    @BeforeTest
    public void launchBrowser() {
        System.out.println("launching Chrome browser"); 
        dr = Driver.getChromeDriver();
    }

    @Test
    private void sc1_95_Fav(){

        System.out.println("sc1"); }
}
}

Script2:
public class sc2 extends ExtentReports_Basecode{

    public WebDriver dr;
    public Report report = null;
        String inputSheetPath ="TestData/InputData/DataSheet.xls" ;

    @BeforeTest
    public void launchBrowser() {
        System.out.println("launching Chrome browser"); 
        dr = Driver.getChromeDriver();
    }

    @Test
    private void sc2_83_Fav() {

                }
}
}

TestNG XML: TestNG XML:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <!--<suite name="Parallel test Suite">-->
    <suite name="My suite" parallel="classes" thread-count="10">
    <test name="name">

        <classes>
    <!-- To Add Any Class  start -->

         <class name="OpenUI.Favourites.sc1"/> 
         <class name="OpenUI.Favourites.sc2"/>

    <!--To Add Any Class  End -->

    </classes>
  </test> 
</suite>

in the extent report I m getting results in 2nd test case.. can someone pls suggest where am I missed out and how to see the output properly using extent report parallel testing using TestNG.在范围报告中,我在第二个测试用例中得到结果..有人可以建议我错过了哪里以及如何使用 TestNG 正确使用范围报告并行测试来查看 output。 As shown in the image the results output of first Test is shown in the second Test, if any thing get failed the Failed output shown in Last Test not in actual failed Test PS: its working fine when I run sequentially one by one using testNG.如图所示,第一个测试的结果 output 显示在第二个测试中,如果有任何事情失败,则最后一个测试中显示的 Failed output 不是实际失败的测试PS:当我使用 Z0FD7DBBF7758CA8429D8 依次运行时,它工作正常

Follow this pattern,Hope your problem will be solved按照这个模式,希望你的问题会得到解决

WebDriver driver;
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;



        @BeforeTest
        public void setUp() {
            // where we need to generate the report

            htmlReporter = new ExtentHtmlReporter("Your report Path");
            extent = new ExtentReports();
            extent.attachReporter(htmlReporter);
            // Set our document title, theme etc..
            htmlReporter.config().setDocumentTitle("Rehomes");
            htmlReporter.config().setReportName("Rehomes Production Testing");
            htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
            htmlReporter.config().setTheme(Theme.DARK);


                        }
       }
        @Test
        public void HomepageLogo() throws Exception {
            test = extent.createTest("rentalhomesHomePage");
            //Your Test

        }

      @AfterMethod
      public void setTestResult(ITestResult result) throws IOException {


          if (result.getStatus() == ITestResult.FAILURE) {
              test.log(Status.FAIL, result.getName());
              test.log(Status.FAIL,result.getThrowable());
              //test.fail("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
          } else if (result.getStatus() == ITestResult.SUCCESS) {
              test.log(Status.PASS, result.getName());
              //test.pass("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
          } else if (result.getStatus() == ITestResult.SKIP) {
              test.skip("Test Case : " + result.getName() + " has been skipped");
          }

          extent.flush();
      driver.close();

        }
    }

Thanks for the reply, but unfortunately the above one dint work and is giving only one test generated as a report if tried in that way.感谢您的回复,但不幸的是,上述一项工作有效,并且如果以这种方式尝试,则仅提供一个生成为报告的测试。 can u suggest any other way to overcome this issue.?你能建议任何其他方法来克服这个问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM