Java Code Examples for com.aventstack.extentreports.ExtentTest#createNode()

The following examples show how to use com.aventstack.extentreports.ExtentTest#createNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtentIReporterSuiteListenerAdapter.java    From extentreports-testng-adapter with Apache License 2.0 6 votes vote down vote up
private void buildTestNodes(ExtentTest suiteTest, IResultMap tests, Status status) {
    ExtentTest node;

    if (tests.size() > 0) {
        for (ITestResult result : tests.getAllResults()) {
            node = suiteTest.createNode(result.getMethod().getMethodName(), result.getMethod().getDescription());

            String groups[] = result.getMethod().getGroups();
            ExtentTestCommons.assignGroups(node, groups);

            if (result.getThrowable() != null) {
                node.log(status, result.getThrowable());
            } else {
                node.log(status, "Test " + status.toString().toLowerCase() + "ed");
            }

            node.getModel().getLogContext().getAll().forEach(x -> x.setTimestamp(getTime(result.getEndMillis())));
            node.getModel().setStartTime(getTime(result.getStartMillis()));
            node.getModel().setEndTime(getTime(result.getEndMillis()));
        }
    }
}
 
Example 2
Source File: GherkinKeywordTest.java    From extentreports-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGermanGherkinKeywords() throws ClassNotFoundException, UnsupportedEncodingException {
    ExtentReports extent = extent();
    extent.setGherkinDialect("de");
    
    ExtentTest feature = extent.createTest(new GherkinKeyword("Funktionalität"), "Refund item VM");
    ExtentTest scenario = feature.createNode(new GherkinKeyword("Szenario"), "Jeff returns a faulty microwave");
    ExtentTest given = scenario.createNode(new GherkinKeyword("Angenommen"), "Jeff has bought a microwave for $100").skip("skip");
    ExtentTest and = scenario.createNode(new GherkinKeyword("Und"), "he has a receipt").pass("pass");
    ExtentTest when = scenario.createNode(new GherkinKeyword("Wenn"), "he returns the microwave").pass("pass");
    ExtentTest then = scenario.createNode(new GherkinKeyword("Dann"), "Jeff should be refunded $100").skip("skip");
    
    Assert.assertEquals(feature.getModel().getBddType(), Feature.class);
    Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class);
    Assert.assertEquals(given.getModel().getBddType(), Given.class);
    Assert.assertEquals(and.getModel().getBddType(), And.class);
    Assert.assertEquals(when.getModel().getBddType(), When.class);
    Assert.assertEquals(then.getModel().getBddType(), Then.class);
}
 
Example 3
Source File: GherkinKeywordTest.java    From extentreports-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnglishGherkinKeywords() throws ClassNotFoundException, UnsupportedEncodingException {
    ExtentReports extent = extent();
    extent.setGherkinDialect("en");
    
    ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), "Refund item VM");
    ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Jeff returns a faulty microwave");
    ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Jeff has bought a microwave for $100").skip("skip");
    ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "he has a receipt").pass("pass");
    ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "he returns the microwave").pass("pass");
    ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").skip("skip");
    
    Assert.assertEquals(feature.getModel().getBddType(), Feature.class);
    Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class);
    Assert.assertEquals(given.getModel().getBddType(), Given.class);
    Assert.assertEquals(and.getModel().getBddType(), And.class);
    Assert.assertEquals(when.getModel().getBddType(), When.class);
    Assert.assertEquals(then.getModel().getBddType(), Then.class);
}
 
Example 4
Source File: MyExtentTestNgFormatter.java    From TestHub with MIT License 5 votes vote down vote up
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
    if (iInvokedMethod.isTestMethod()) {
        ITestContext iTestContext = iTestResult.getTestContext();
        ExtentTest testContext = (ExtentTest) iTestContext.getAttribute("testContext");
        ExtentTest test = testContext.createNode(iTestResult.getName(), iInvokedMethod.getTestMethod().getDescription());
        iTestResult.setAttribute("test", test);
    }
}
 
Example 5
Source File: ExtentReportsBuilder.java    From courgette-jvm with MIT License 5 votes vote down vote up
private ExtentTest createGherkinNode(ExtentTest parent, String keyword, String name, boolean appendKeyword) {
    try {
        String nodeName = appendKeyword ? (keyword + " " + name) : name;
        return parent.createNode(new GherkinKeyword(keyword), nodeName);
    } catch (ClassNotFoundException e) {
        throw new CourgetteException(e);
    }
}
 
Example 6
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private synchronized void createTestCase(TestCase testCase) {
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile.get(), testCase.getLine());
    if (astNode != null) {
        ScenarioDefinition scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode);
        ExtentTest parent = scenarioOutlineThreadLocal.get() != null ? scenarioOutlineThreadLocal.get() : featureTestThreadLocal.get();
        ExtentTest t = parent.createNode(com.aventstack.extentreports.gherkin.model.Scenario.class, scenarioDefinition.getName(), scenarioDefinition.getDescription());
        scenarioThreadLocal.set(t);
    }
    if (!testCase.getTags().isEmpty()) {
        testCase.getTags()
 		.stream()
 		.map(PickleTag::getName)
 		.forEach(scenarioThreadLocal.get()::assignCategory);
    }
}
 
Example 7
Source File: ExtentTestManager.java    From extentreports-testng-adapter with Apache License 2.0 5 votes vote down vote up
private static synchronized ExtentTest createTest(ITestResult result, ExtentTest classTest) {
    String methodName = result.getMethod().getMethodName();
    String desc = result.getMethod().getDescription();
    ExtentTest test;
    if (classTest != null) {
        test = classTest.createNode(methodName, desc);
    } else {
        test = ExtentService.getInstance().createTest(methodName, desc);
    }
    methodTest.set(test);
    String[] groups = result.getMethod().getGroups();
    ExtentTestCommons.assignGroups(test, groups);
    return test;
}
 
Example 8
Source File: ExtentIReporterSuiteClassListenerAdapter.java    From extentreports-testng-adapter with Apache License 2.0 5 votes vote down vote up
private void buildTestNodes(ExtentTest suiteTest, IResultMap tests, Status status) {
    ExtentTest testNode;
    ExtentTest classNode;

    if (tests.size() > 0) {
        for (ITestResult result : tests.getAllResults()) {
            String className = result.getInstance().getClass().getSimpleName();

            if (classTestMap.containsKey(className)) {
                classNode = classTestMap.get(className);
            } else {
                classNode = suiteTest.createNode(className);
                classTestMap.put(className, classNode);
            }

            testNode = classNode.createNode(result.getMethod().getMethodName(),
                    result.getMethod().getDescription());

            String[] groups = result.getMethod().getGroups();
            ExtentTestCommons.assignGroups(testNode, groups);
            
            if (result.getThrowable() != null) {
                testNode.log(status, result.getThrowable());
            } else {
                testNode.log(status, "Test " + status.toString().toLowerCase() + "ed");
            }

            testNode.getModel().getLogContext().getAll().forEach(x -> x.setTimestamp(getTime(result.getEndMillis())));
            testNode.getModel().setStartTime(getTime(result.getStartMillis()));
            testNode.getModel().setEndTime(getTime(result.getEndMillis()));
        }
    }
}
 
Example 9
Source File: RawEntityConverter.java    From extentreports-java with Apache License 2.0 5 votes vote down vote up
public void createDomain(Test test, ExtentTest extentTest) throws ClassNotFoundException {
    extentTest.getModel().setStartTime(test.getStartTime());
    extentTest.getModel().setEndTime(test.getEndTime());
    addMedia(test, extentTest);

    // create events
    for (Log log : test.getLogs()) {
        if (log.hasException() && log.hasMedia())
            addMedia(log, extentTest, log.getException().getException());
        else if (log.hasException())
            extentTest.log(log.getStatus(), log.getException().getException());
        else if (log.hasMedia())
            addMedia(log, extentTest, null);
        else
            extentTest.log(log.getStatus(), log.getDetails());
    }

    // assign attributes
    test.getAuthorSet().stream().map(x -> x.getName()).forEach(extentTest::assignAuthor);
    test.getCategorySet().stream().map(x -> x.getName()).forEach(extentTest::assignCategory);
    test.getDeviceSet().stream().map(x -> x.getName()).forEach(extentTest::assignDevice);

    // handle nodes
    for (Test node : test.getChildren()) {
        ExtentTest extentNode = null;
        if (node.getBddType() == null)
            extentNode = extentTest.createNode(node.getName(), node.getDescription());
        else
            extentNode = extentTest.createNode(new GherkinKeyword(node.getBddType().toString()), node.getName(),
                    node.getDescription());
        addMedia(node, extentNode);
        createDomain(node, extentNode);
    }
}
 
Example 10
Source File: MyExtentTestNgFormatter.java    From TestHub with MIT License 5 votes vote down vote up
private void addNewNode(String parent, String nodeName) {
    ITestResult result = Reporter.getCurrentTestResult();
    Preconditions.checkState(result != null);
    ExtentTest parentNode = (ExtentTest) result.getAttribute(parent);
    ExtentTest childNode = parentNode.createNode(nodeName);
    result.setAttribute(nodeName, childNode);
}
 
Example 11
Source File: MyExtentTestNgFormatter.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
      ISuite iSuite = iTestContext.getSuite();
      ExtentTest suite = (ExtentTest) iSuite.getAttribute(SUITE_ATTR);
      ExtentTest testContext = suite.createNode(iTestContext.getName());
// 自定义报告
// 将MyReporter.report 静态引用赋值为 testContext。
// testContext 是 @Test每个测试用例时需要的。report.log可以跟随具体的测试用例。另请查阅源码。
      MyReporter.report = testContext;
      iTestContext.setAttribute("testContext", testContext);
  }
 
Example 12
Source File: MyExtentTestNgFormatter.java    From TestHub with MIT License 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
        ISuite iSuite = iTestContext.getSuite();
        ExtentTest suite = (ExtentTest) iSuite.getAttribute(SUITE_ATTR);
        ExtentTest testContext = suite.createNode(iTestContext.getName());
//        自定义报告
        MyReporter.report = testContext;
        iTestContext.setAttribute("testContext", testContext);
    }
 
Example 13
Source File: MyExtentTestNgFormatter.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
private void addNewNode(String parent, String nodeName) {
    ITestResult result = Reporter.getCurrentTestResult();
    Preconditions.checkState(result != null);
    ExtentTest parentNode = (ExtentTest) result.getAttribute(parent);
    ExtentTest childNode = parentNode.createNode(nodeName);
    result.setAttribute(nodeName, childNode);
}
 
Example 14
Source File: MyExtentTestNgFormatter.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
    if (iInvokedMethod.isTestMethod()) {
        ITestContext iTestContext = iTestResult.getTestContext();
        ExtentTest testContext = (ExtentTest) iTestContext.getAttribute("testContext");
        ExtentTest test = testContext.createNode(iTestResult.getName(), iInvokedMethod.getTestMethod().getDescription());
        iTestResult.setAttribute("test", test);
    }
}
 
Example 15
Source File: MyExtentTestNgFormatter.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
      ISuite iSuite = iTestContext.getSuite();
      ExtentTest suite = (ExtentTest) iSuite.getAttribute(SUITE_ATTR);
      ExtentTest testContext = suite.createNode(iTestContext.getName());
// 自定义报告
// 将MyReporter.report 静态引用赋值为 testContext。
// testContext 是 @Test每个测试用例时需要的。report.log可以跟随具体的测试用例。另请查阅源码。
      MyReporter.report = testContext;
      iTestContext.setAttribute("testContext", testContext);
  }
 
Example 16
Source File: MyExtentTestNgFormatter.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
private void addNewNode(String parent, String nodeName) {
    ITestResult result = Reporter.getCurrentTestResult();
    Preconditions.checkState(result != null);
    ExtentTest parentNode = (ExtentTest) result.getAttribute(parent);
    ExtentTest childNode = parentNode.createNode(nodeName);
    result.setAttribute(nodeName, childNode);
}
 
Example 17
Source File: MyExtentTestNgFormatter.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
    if (iInvokedMethod.isTestMethod()) {
        ITestContext iTestContext = iTestResult.getTestContext();
        ExtentTest testContext = (ExtentTest) iTestContext.getAttribute("testContext");
        ExtentTest test = testContext.createNode(iTestResult.getName(), iInvokedMethod.getTestMethod().getDescription());
        iTestResult.setAttribute("test", test);
    }
}
 
Example 18
Source File: ExtentTestNGIReporterListenerOld.java    From Java-API-Test-Examples with Apache License 2.0 4 votes vote down vote up
@Override
    public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
        init();
        boolean createSuiteNode = false;
        if(suites.size()>1){
            createSuiteNode=true;
        }
        for (ISuite suite : suites) {
            Map<String, ISuiteResult> result = suite.getResults();
            //如果suite里面没有任何用例,直接跳过,不在报告里生成
            if(result.size()==0){
                continue;
            }
            //统计suite下的成功、失败、跳过的总用例数
            int suiteFailSize=0;
            int suitePassSize=0;
            int suiteSkipSize=0;
            ExtentTest suiteTest=null;
            //存在多个suite的情况下,在报告中将同一个一个suite的测试结果归为一类,创建一级节点。
            if(createSuiteNode){
                suiteTest = extent.createTest(suite.getName()).assignCategory(suite.getName());
            }
            boolean createSuiteResultNode = false;
            if(result.size()>1){
                createSuiteResultNode=true;
            }
            for (ISuiteResult r : result.values()) {
                ExtentTest resultNode;
                ITestContext context = r.getTestContext();
                if(createSuiteResultNode){
                    //没有创建suite的情况下,将在SuiteResult的创建为一级节点,否则创建为suite的一个子节点。
                    if( null == suiteTest){
                        resultNode = extent.createTest(r.getTestContext().getName());
                    }else{
                        resultNode = suiteTest.createNode(r.getTestContext().getName());
                    }
                }else{
                    resultNode = suiteTest;
                }
                if(resultNode != null){
                    resultNode.getModel().setName(suite.getName()+" : "+r.getTestContext().getName());
                    if(resultNode.getModel().hasCategory()){
                        resultNode.assignCategory(r.getTestContext().getName());
                    }else{
                        resultNode.assignCategory(suite.getName(),r.getTestContext().getName());
                    }
                    resultNode.getModel().setStartTime(r.getTestContext().getStartDate());
                    resultNode.getModel().setEndTime(r.getTestContext().getEndDate());
                    //统计SuiteResult下的数据
                    int passSize = r.getTestContext().getPassedTests().size();
                    int failSize = r.getTestContext().getFailedTests().size();
                    int skipSize = r.getTestContext().getSkippedTests().size();
                    suitePassSize += passSize;
                    suiteFailSize += failSize;
                    suiteSkipSize += skipSize;
                    if(failSize>0){
                        resultNode.getModel().setStatus(Status.FAIL);
                    }
                    resultNode.getModel().setDescription(String.format("Pass: %s ; Fail: %s ; Skip: %s ;",passSize,failSize,skipSize));
                }
                buildTestNodes(resultNode,context.getFailedTests(), Status.FAIL);
                buildTestNodes(resultNode,context.getSkippedTests(), Status.SKIP);
                buildTestNodes(resultNode,context.getPassedTests(), Status.PASS);
            }
            if(suiteTest!= null){
                suiteTest.getModel().setDescription(String.format("Pass: %s ; Fail: %s ; Skip: %s ;",suitePassSize,suiteFailSize,suiteSkipSize));
                if(suiteFailSize>0){
                    suiteTest.getModel().setStatus(Status.FAIL);
                }
            }

        }
//        for (String s : Reporter.getOutput()) {
//            extent.setTestRunnerOutput(s);
//        }

        extent.flush();
    }
 
Example 19
Source File: ExtentTestNGIReporterListenerOld.java    From Java-API-Test-Examples with Apache License 2.0 4 votes vote down vote up
@Override
    public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
        init();
        boolean createSuiteNode = false;
        if(suites.size()>1){
            createSuiteNode=true;
        }
        for (ISuite suite : suites) {
            Map<String, ISuiteResult> result = suite.getResults();
            //如果suite里面没有任何用例,直接跳过,不在报告里生成
            if(result.size()==0){
                continue;
            }
            //统计suite下的成功、失败、跳过的总用例数
            int suiteFailSize=0;
            int suitePassSize=0;
            int suiteSkipSize=0;
            ExtentTest suiteTest=null;
            //存在多个suite的情况下,在报告中将同一个一个suite的测试结果归为一类,创建一级节点。
            if(createSuiteNode){
                suiteTest = extent.createTest(suite.getName()).assignCategory(suite.getName());
            }
            boolean createSuiteResultNode = false;
            if(result.size()>1){
                createSuiteResultNode=true;
            }
            for (ISuiteResult r : result.values()) {
                ExtentTest resultNode;
                ITestContext context = r.getTestContext();
                if(createSuiteResultNode){
                    //没有创建suite的情况下,将在SuiteResult的创建为一级节点,否则创建为suite的一个子节点。
                    if( null == suiteTest){
                        resultNode = extent.createTest(r.getTestContext().getName());
                    }else{
                        resultNode = suiteTest.createNode(r.getTestContext().getName());
                    }
                }else{
                    resultNode = suiteTest;
                }
                if(resultNode != null){
                    resultNode.getModel().setName(suite.getName()+" : "+r.getTestContext().getName());
                    if(resultNode.getModel().hasCategory()){
                        resultNode.assignCategory(r.getTestContext().getName());
                    }else{
                        resultNode.assignCategory(suite.getName(),r.getTestContext().getName());
                    }
                    resultNode.getModel().setStartTime(r.getTestContext().getStartDate());
                    resultNode.getModel().setEndTime(r.getTestContext().getEndDate());
                    //统计SuiteResult下的数据
                    int passSize = r.getTestContext().getPassedTests().size();
                    int failSize = r.getTestContext().getFailedTests().size();
                    int skipSize = r.getTestContext().getSkippedTests().size();
                    suitePassSize += passSize;
                    suiteFailSize += failSize;
                    suiteSkipSize += skipSize;
                    if(failSize>0){
                        resultNode.getModel().setStatus(Status.FAIL);
                    }
                    resultNode.getModel().setDescription(String.format("Pass: %s ; Fail: %s ; Skip: %s ;",passSize,failSize,skipSize));
                }
                buildTestNodes(resultNode,context.getFailedTests(), Status.FAIL);
                buildTestNodes(resultNode,context.getSkippedTests(), Status.SKIP);
                buildTestNodes(resultNode,context.getPassedTests(), Status.PASS);
            }
            if(suiteTest!= null){
                suiteTest.getModel().setDescription(String.format("Pass: %s ; Fail: %s ; Skip: %s ;",suitePassSize,suiteFailSize,suiteSkipSize));
                if(suiteFailSize>0){
                    suiteTest.getModel().setStatus(Status.FAIL);
                }
            }

        }
//        for (String s : Reporter.getOutput()) {
//            extent.setTestRunnerOutput(s);
//        }

        extent.flush();
    }
 
Example 20
Source File: ExtentTestNGIReporterListenerOld.java    From Java-API-Test-Examples with Apache License 2.0 4 votes vote down vote up
@Override
    public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
        init();
        boolean createSuiteNode = false;
        if(suites.size()>1){
            createSuiteNode=true;
        }
        for (ISuite suite : suites) {
            Map<String, ISuiteResult> result = suite.getResults();
            //如果suite里面没有任何用例,直接跳过,不在报告里生成
            if(result.size()==0){
                continue;
            }
            //统计suite下的成功、失败、跳过的总用例数
            int suiteFailSize=0;
            int suitePassSize=0;
            int suiteSkipSize=0;
            ExtentTest suiteTest=null;
            //存在多个suite的情况下,在报告中将同一个一个suite的测试结果归为一类,创建一级节点。
            if(createSuiteNode){
                suiteTest = extent.createTest(suite.getName()).assignCategory(suite.getName());
            }
            boolean createSuiteResultNode = false;
            if(result.size()>1){
                createSuiteResultNode=true;
            }
            for (ISuiteResult r : result.values()) {
                ExtentTest resultNode;
                ITestContext context = r.getTestContext();
                if(createSuiteResultNode){
                    //没有创建suite的情况下,将在SuiteResult的创建为一级节点,否则创建为suite的一个子节点。
                    if( null == suiteTest){
                        resultNode = extent.createTest(r.getTestContext().getName());
                    }else{
                        resultNode = suiteTest.createNode(r.getTestContext().getName());
                    }
                }else{
                    resultNode = suiteTest;
                }
                if(resultNode != null){
                    resultNode.getModel().setName(suite.getName()+" : "+r.getTestContext().getName());
                    if(resultNode.getModel().hasCategory()){
                        resultNode.assignCategory(r.getTestContext().getName());
                    }else{
                        resultNode.assignCategory(suite.getName(),r.getTestContext().getName());
                    }
                    resultNode.getModel().setStartTime(r.getTestContext().getStartDate());
                    resultNode.getModel().setEndTime(r.getTestContext().getEndDate());
                    //统计SuiteResult下的数据
                    int passSize = r.getTestContext().getPassedTests().size();
                    int failSize = r.getTestContext().getFailedTests().size();
                    int skipSize = r.getTestContext().getSkippedTests().size();
                    suitePassSize += passSize;
                    suiteFailSize += failSize;
                    suiteSkipSize += skipSize;
                    if(failSize>0){
                        resultNode.getModel().setStatus(Status.FAIL);
                    }
                    resultNode.getModel().setDescription(String.format("Pass: %s ; Fail: %s ; Skip: %s ;",passSize,failSize,skipSize));
                }
                buildTestNodes(resultNode,context.getFailedTests(), Status.FAIL);
                buildTestNodes(resultNode,context.getSkippedTests(), Status.SKIP);
                buildTestNodes(resultNode,context.getPassedTests(), Status.PASS);
            }
            if(suiteTest!= null){
                suiteTest.getModel().setDescription(String.format("Pass: %s ; Fail: %s ; Skip: %s ;",suitePassSize,suiteFailSize,suiteSkipSize));
                if(suiteFailSize>0){
                    suiteTest.getModel().setStatus(Status.FAIL);
                }
            }

        }
//        for (String s : Reporter.getOutput()) {
//            extent.setTestRunnerOutput(s);
//        }

        extent.flush();
    }