简体   繁体   English

扩展报告:日志被追加到报告中的单个测试用例上

[英]Extent Reports: Logs are Getting Appended on to a Single Test Case in the Report

i am Unable to Have separate Logs/entries for Different Test Cases. 我无法为不同的测试用例设置单独的日志/条目。 ie Logs are Getting Appended on to a Single Test Case in the Extent Report generated. 例如,在生成的扩展报告中,日志被附加到单个测试用例上。 Using Extent Report Version 2.41.1.. 使用范围报告版本2.41.1 ..

The Report Sample: 报告样本: 扩展报告日志已附加到单个测试用例

MY Code Goes like This: 我的代码如下所示:

    Base Class of TestNG:

  public static ExtentReports report;
  public static ExtentTest logger;

  @BeforeSuite
  @Parameters({"BrowserName"})
  public void beforeSuite(@Optional("Firefox") String BrowserName) 
  {
      date = new Date();
      SimpleDateFormat ft = new SimpleDateFormat ("dd-MM-yyyy");
      String TodaysDate = ft.format(date);
      prop = ResourceBundle.getBundle("DataFile");
      Driver = Browser_Factory_FSQA_Class.getBrowser(BrowserName);
      path = "//home//workspace//....//FSQA.ExtentReports//FSQA_ExtentReport_" + TodaysDate;
      File f=new File(path);
      if(!f.exists())
      {
          report = new ExtentReports(path);
      }
  }
  @BeforeTest
  @Parameters({"BrowserName"})
  public void SetUpConfig(@Optional("Firefox") String BrowserName)
  {
     report = new ExtentReports(path, false,DisplayOrder.NEWEST_FIRST);
     report.loadConfig(new File("//home//......//extent-config.xml"));
     report.addSystemInfo("Build-Tag", prop.getString("Build-Tag"))
                .addSystemInfo("Selenium ", prop.getString("SelVer"))
                .assignProject(prop.getString("Application"))
                .addSystemInfo("Envirnoment", prop.getString("AppEnvirnoment"))
                .addSystemInfo("Extent", prop.getString("ExtRpVer"));
     logger = report.startTest(this.getClass().getSimpleName());
     logger.log(LogStatus.INFO,this.getClass().getSimpleName() +" will Run on "+ BrowserName +" Browser");
     Driver.get(prop.getString("URL"));
     Driver.manage().window().maximize();
     Driver.manage().window().maximize();
     Driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
  }
  @AfterMethod(alwaysRun=true)
  public void afterMethod(ITestResult result) throws IOException
  {
    try
    { 
        if(result.getStatus()==ITestResult.FAILURE)
        {
            String res = captureScreenshot(Driver, result.getName());
            String image= logger.addScreenCapture(res);
            System.out.println(image);
            String TestCaseName = this.getClass().getSimpleName() + " Test Case Failure and Title/Boolean Value Failed";
            logger.log(LogStatus.FAIL, TestCaseName  + logger.addScreenCapture(res));
        }
        else if(result.getStatus()==ITestResult.SUCCESS)
        {
            logger.log(LogStatus.PASS, this.getClass().getSimpleName() + " Test Case Success and Title Verified"); 
        }
        else if(result.getStatus()==ITestResult.SKIP)
        {
            logger.log(LogStatus.SKIP, this.getClass().getSimpleName() + " Test Case Skipped");
        }
    }
    catch(Throwable t)
    {
        logger.log(LogStatus.ERROR,t.getMessage());
        }      
      }

  public String captureScreenshot(WebDriver Driver, String TestName)
    {
   try 
    {
            date = new Date();
        SimpleDateFormat ft = new SimpleDateFormat ("dd_MM_yyyy");
        String TodaysDate = ft.format(date);
            TakesScreenshot ts=(TakesScreenshot)Driver;
        File source=ts.getScreenshotAs(OutputType.FILE);
        Sc_Destination = prop.getString("SC_Dest")+TestName+"__"+TodaysDate+".png";
        FileUtils.copyFile(source,new File(Sc_Destination));
        logger.log(LogStatus.FAIL,image, "Title verification");*/
        return Sc_Destination;
    } 
    catch (Exception e)
    {
        System.out.println("Exception while taking screenshot "+e.getMessage());
    } 
  return Sc_Destination;
}

  @AfterTest(alwaysRun=true)
public void AfterTest()
{
    Driver.close();
    report.endTest(logger);
    report.flush();
}

  @AfterSuite
 public void AfterSuite()
{
      report.close();
      Driver.quit();
}

My Tests are Separate Clases which Extends this Base Class: TC1: 我的测试是单独的分类,它扩展了以下基础类:TC1:

public classTC1 extends BaseTestNG
  {
  @Test(groups = {"Happy_Path"} , description="TC1")
public void TestCase1() throws InterruptedException, Exception
  {
      logger.log(LogStatus.INFO, " Test Case2 Block Entered");
      Thread.sleep(4000); 
      ......
              ......
      logger.log(LogStatus.INFO, "Assert Flag Received");
      Thread.sleep(4000); 
      Assert.assertTrue(AssertFlag);        
  }
  }

TC2: TC2:

public classTC2 extends BaseTestNG
  {
  @Test(groups = {"Happy_Path"} , description="TC2")
public void TestCase2() throws InterruptedException, Exception
  {
      logger.log(LogStatus.INFO, " Test Case2 Block Entered");
      Thread.sleep(4000); 
      ......
              ......
       logger.log(LogStatus.INFO, "Assert Flag Received");
      Thread.sleep(4000); 
      Assert.assertTrue(AssertFlag);        
  }
  }

I am Using POM Classes along with TestNG and running the Testcases using testng.xml. 我正在将POM类与TestNG一起使用,并使用testng.xml运行测试用例。

I am able to generate the Extent Report but unable to Differentiate Between TC1 & TC2 Logs ie all test Case logs are getting appended to single TestCase as shown in the Above Screen Shot. 我能够生成范围报告,但无法区分TC1和TC2日志,即所有测试用例日志都将附加到单个TestCase,如上面的屏幕截图所示。

I want each Test Case Logs/Entry in separate rows in the Extent Reports. 我希望每个测试用例日志/条目都在扩展报告中的单独行中。

Can Anyone please rectify the mistake in my code and help me out. 任何人都可以纠正我的代码中的错误并为我提供帮助吗?

Thanks in Advance!!! 提前致谢!!!

I think, you should initialize your logger in BeforeMethod and use report.flush() in AfterMethod. 我认为,您应该在BeforeMethod中初始化记录器 ,并在AfterMethod中使用report.flush()。 That may solve your problem. 那可以解决您的问题。

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

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