无法从另一个类获取logger.info

时间:2018-03-05 15:33:16

标签: selenium-webdriver extentreports selenium-extent-report

我在html页面中使用范围报告来处理报告。我在这里遇到了一个问题。我需要从另一个类获取logger.info消息。请仔细阅读以下代码,了解问题,如果我错了请纠正我

第1课:报告

package test;

public class Reports {  
public  ExtentReports extent;
public  ExtentTest logger;

@BeforeSuite
public void startReport(){
        extent = new ExtentReports (System.getProperty("user.dir") +"/test-output/STMExtentReport.html", true);

              extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
            System.out.println("statrt report");

}


@AfterMethod
public void getResult(ITestResult result){
    System.out.println("In ITresults : After method");
    if(result.getStatus() == ITestResult.FAILURE){
        logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getName());
        logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getThrowable());
    }else if(result.getStatus() == ITestResult.SKIP){
        logger.log(LogStatus.SKIP, "Test Case Skipped is "+result.getName());
    }

    extent.endTest(logger);
}
@AfterSuite
public void endReport(){        
            extent.flush();               
            extent.close();
}

}

Class2: - NewTest1

package testng;

public class NewTest1 extends Reports {
@Test
public void failTest(){
    System.out.println("NewTest1 --> in Test fail testcase ");
    logger = extent.startTest("failTest");
    Assert.assertTrue(false);
    logger.log(LogStatus.FAIL, "Test Case (failTest) Status is failed");
}

@Test
public void passTest(){
    System.out.println("NewTest1 --> in Test pass testcase ");
    logger = extent.startTest("passtest");
    Assert.assertTrue(true);
    logger.log(LogStatus.PASS, "Test Case (passtest) Status is failed");

   skipTest();

}

Class3: - NewTest2     包testng;

public class NewTest2{
//static ExtentReports extent;
 static ExtentTest logg;


public static void skipTest(){
    System.out.println("NewTest1 --> in Test skip testcase ");  
    logg.log(LogStatus.INFO, "Test case info will come here");    // Getting Nullpointer exception here
    throw new SkipException("Skipping - This is not ready for testing ");
    }

}

0 个答案:

没有答案