范围报告:添加类名称方法名称以进行失败测试

时间:2018-04-10 03:41:47

标签: cucumber-jvm extentreports

我在我的测试项目中运行了Cucumber selenium extent报告。我想知道如何在通过/失败测试结果的范围报告中添加类名+方法名。下面是我的代码:

    @CucumberOptions(
        features = "src/Feature",
        glue = {"Step_Definitions"},
        plugin = {
                "pretty",
                "html:target/cucumber-reports/cucumber-pretty",
                "json:target/cucumber-reports/CucumberTestReport.json",
                "rerun:target/cucumber-reports/rerun.txt"
    })

        public class TestRunner {
            private TestNGCucumberRunner testNGCucumberRunner;
            private ExtentHtmlReporter htmlReporter;
            private ExtentReports extent;
            private ExtentTest logger;

    @BeforeTest(alwaysRun = true)
    public void setUp() throws Exception {
        testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());

        htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/report/Test-Report.html");
        extent = new ExtentReports ();
        extent.attachReporter(htmlReporter);
        extent.setSystemInfo("Host Name", "MyTest");
        extent.setSystemInfo("Environment", "SIT");
        extent.setSystemInfo("User Name", "Peter Wong");

        htmlReporter.config().setDocumentTitle("Test Report");
        htmlReporter.config().setReportName("Test Report");
        htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        htmlReporter.config().setTheme(Theme.STANDARD);
    }

    @Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "dataProvider")
    public void feature(CucumberFeatureWrapper cucumberFeature) {
        testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
    }
  /*  
    @Test
    public void passTest(){
        logger = extent.createTest("passTest");
        Assert.assertTrue(true);
        logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is passTest", ExtentColor.GREEN));

         try {
            logger.fail("Pass Details", MediaEntityBuilder.createScreenCaptureFromPath("screenshot.png").build());
        } catch (IOException ex) {
            LogManager.logger.log(Level.INFO, "Exception: " + ex.getMessage());
        }
    }

  */

    @AfterMethod
    public void getResult(ITestResult result){
        if(result.getStatus() == ITestResult.FAILURE) {
            logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " - Test Case Failed", ExtentColor.RED));
            logger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED));
        }
        else if(result.getStatus() == ITestResult.SKIP) {
            logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " - Test Case Skipped", ExtentColor.ORANGE)); 
        }
    }

    @AfterTest(alwaysRun = true)
    public void tearDown() throws Exception {
        extent.flush();
        testNGCucumberRunner.finish();
    }
}

问题:

  1. 是否在@Test添加捕获方法名称?如何使用黄瓜 为达到这个?
    1. 将范围报告与Cucumber跑步者班级相结合的最佳设计方法是什么?
  2. 请帮忙。希望能够真正帮助我的人。

    enter image description here

0 个答案:

没有答案