org.testng.ISuiteResult Java Examples

The following examples show how to use org.testng.ISuiteResult. 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: ExtentIReporterSuiteClassListenerAdapter.java    From extentreports-testng-adapter with Apache License 2.0 7 votes vote down vote up
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
    ExtentService.getInstance().setReportUsesManualConfiguration(true);
    ExtentService.getInstance().setAnalysisStrategy(AnalysisStrategy.SUITE);

    for (ISuite suite : suites) {
        Map<String, ISuiteResult> result = suite.getResults();

        for (ISuiteResult r : result.values()) {
            ITestContext context = r.getTestContext();

            ExtentTest suiteTest = ExtentService.getInstance().createTest(r.getTestContext().getSuite().getName());
            buildTestNodes(suiteTest, context.getFailedTests(), Status.FAIL);
            buildTestNodes(suiteTest, context.getSkippedTests(), Status.SKIP);
            buildTestNodes(suiteTest, context.getPassedTests(), Status.PASS);
        }
    }

    for (String s : Reporter.getOutput()) {
        ExtentService.getInstance().setTestRunnerOutput(s);
    }

    ExtentService.getInstance().flush();
}
 
Example #2
Source File: ExtentIReporterSuiteListenerAdapter.java    From extentreports-testng-adapter with Apache License 2.0 6 votes vote down vote up
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
    ExtentService.getInstance().setReportUsesManualConfiguration(true);
    ExtentService.getInstance().setAnalysisStrategy(AnalysisStrategy.SUITE);

    for (ISuite suite : suites) {
        Map<String, ISuiteResult> result = suite.getResults();

        for (ISuiteResult r : result.values()) {
            ITestContext context = r.getTestContext();

            ExtentTest suiteTest = ExtentService.getInstance().createTest(r.getTestContext().getSuite().getName());
            buildTestNodes(suiteTest, context.getFailedTests(), Status.FAIL);
            buildTestNodes(suiteTest, context.getSkippedTests(), Status.SKIP);
            buildTestNodes(suiteTest, context.getPassedTests(), Status.PASS);
        }
    }

    for (String s : Reporter.getOutput()) {
        ExtentService.getInstance().setTestRunnerOutput(s);
    }

    ExtentService.getInstance().flush();
}
 
Example #3
Source File: PowerEmailableReporter.java    From WebAndAppUITesting with GNU General Public License v3.0 6 votes vote down vote up
/** Creates a section showing known results for each method */
protected void generateMethodDetailReport(List<ISuite> suites) {
	for (ISuite suite : suites) {
		Map<String, ISuiteResult> r = suite.getResults();
		for (ISuiteResult r2 : r.values()) {
			ITestContext testContext = r2.getTestContext();
			if (r.values().size() > 0) {
				m_out.println("<h1>" + testContext.getName() + "</h1>");
			}
			resultDetail(testContext.getFailedConfigurations());
			resultDetail(testContext.getFailedTests());
			resultDetail(testContext.getSkippedConfigurations());
			resultDetail(testContext.getSkippedTests());
			resultDetail(testContext.getPassedTests());
		}
	}
}
 
Example #4
Source File: GatekeeperBehaviour.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    if (!isThisSuiteListener(testResult)) {
        return;
    }
    if (method.isTestMethod()) {
        ITestNGMethod thisMethod = method.getTestMethod();
        ITestNGMethod[] allTestMethods = testResult.getTestContext().getAllTestMethods();
        ITestNGMethod firstMethod = allTestMethods[0];

        if (thisMethod.equals(firstMethod)) {
            Map<String, ISuiteResult> results = testResult.getTestContext().getSuite().getResults();
            if (hasFailedGatekeeperTest(results)) {
                throw new GatekeeperException(SKIP_MESSAGE);
            }
        } else {
            IResultMap skippedTests = testResult.getTestContext().getSkippedTests();
            if (anyTestsSkippedBecauseOfGatekeeper(skippedTests)) {
                throw new GatekeeperException(SKIP_MESSAGE);
            }
        }
    }
}
 
Example #5
Source File: TestRunSummary.java    From teamengine with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the test results and extracts summary information. Each entry in
 * the results corresponds to a test set (conformance class).
 * 
 * @param results
 *            The results for all test sets that were executed.
 */
void summarizeResults(Map<String, ISuiteResult> results) {
    Date earliestStartDate = new Date();
    Date latestEndDate = new Date();
    for (Map.Entry<String, ISuiteResult> entry : results.entrySet()) {
        ITestContext testContext = entry.getValue().getTestContext();
        this.totalPassed += testContext.getPassedTests().size();
        this.totalFailed += testContext.getFailedTests().size();
        this.totalSkipped += testContext.getSkippedTests().size();
        Date startDate = testContext.getStartDate();
        if (earliestStartDate.after(startDate)) {
            earliestStartDate = startDate;
        }
        Date endDate = testContext.getEndDate();
        if (latestEndDate.before(endDate)) {
            latestEndDate = (endDate != null) ? endDate : startDate;
        }
    }
    this.totalDuration = Duration.between(earliestStartDate.toInstant(), latestEndDate.toInstant());
}
 
Example #6
Source File: CustomAutomationReport.java    From pxf with Apache License 2.0 5 votes vote down vote up
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {

	StringBuilder sBuilder = new StringBuilder();

	// Iterating over each suite
	for (ISuite suite : suites) {

		// Getting the results for the each suite
		Map<String, ISuiteResult> suiteResults = suite.getResults();
		for (ISuiteResult sr : suiteResults.values()) {
			// get context for result
			ITestContext tc = sr.getTestContext();
			// go over all cases
			for (ITestNGMethod method : tc.getAllTestMethods()) {
				// if a case has "ExpectedFaiGPDBWritable.javalure" annotation, insert to sBuilder

				if (method.getConstructorOrMethod().getMethod().getAnnotation(ExpectedFailure.class) != null) {
					sBuilder.append(method.getInstance().getClass().getName() + "/" + method.getMethodName()).append(System.lineSeparator());
				}
			}
		}
	}

	// write results to file
	try {
		FileUtils.writeStringToFile(new File(outputDirectory + "/automation_expected_failures.txt"), sBuilder.toString(), false);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #7
Source File: PowerEmailableReporter.java    From WebAndAppUITesting with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a table showing the highlights of each test method with links to
 * the method details
 */
protected void generateMethodSummaryReport(List<ISuite> suites) {
	startResultSummaryTable("methodOverview");
	int testIndex = 1;
	for (ISuite suite : suites) {
		if (suites.size() > 1) {
			titleRow(suite.getName(), 5);
		}
		Map<String, ISuiteResult> r = suite.getResults();
		for (ISuiteResult r2 : r.values()) {
			ITestContext testContext = r2.getTestContext();
			String testName = testContext.getName();
			m_testIndex = testIndex;

			// resultSummary(suite, testContext.getSkippedConfigurations(),
			// testName, "skipped",
			// " (configuration methods)");
			resultSummary(suite, testContext.getSkippedTests(), testName, "skipped", "");
			// resultSummary(suite, testContext.getFailedConfigurations(),
			// testName, "failed",
			// " (configuration methods)");
			resultSummary(suite, testContext.getFailedTests(), testName, "failed", "");
			resultSummary(suite, testContext.getPassedTests(), testName, "passed", "");

			testIndex++;
		}
	}
	m_out.println("</table>");
}
 
Example #8
Source File: TestReport.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory)
{
	List<ITestResult> list = new ArrayList<ITestResult>();
	for (ISuite suite : suites) {
		Map<String, ISuiteResult> suiteResults = suite.getResults();
		for (ISuiteResult suiteResult : suiteResults.values()) {
			ITestContext testContext = suiteResult.getTestContext();
			IResultMap passedTests = testContext.getPassedTests();
			IResultMap failedTests = testContext.getFailedTests();
			IResultMap skippedTests = testContext.getSkippedTests();
			IResultMap failedConfig = testContext.getFailedConfigurations();
			list.addAll(this.listTestResult(passedTests));
			list.addAll(this.listTestResult(failedTests));
			list.addAll(this.listTestResult(skippedTests));
			//list.addAll(this.listTestResult(failedConfig));
		}
	}
	CopyReportResources reportReource=new CopyReportResources();

	try {
		reportReource.copyResources();
	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}
	this.sort(list);
	this.outputResult(list, outputDirectory+"/report.html");


}
 
Example #9
Source File: CustomHTMLReporter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void createCustomResults(List<ISuite> suites, File outputDirectory,
        boolean onlyShowFailures) {
    AtomicInteger suiteIndex = new AtomicInteger(1);
    suites.stream().forEach(suite -> {
        AtomicInteger testIndex = new AtomicInteger(1);
        Consumer<ISuiteResult> resultConsumer = getSuiteResultConsumer(outputDirectory, onlyShowFailures,
                suiteIndex, testIndex);
        suite.getResults().values().stream().forEach(resultConsumer);
        suiteIndex.incrementAndGet();
    });
}
 
Example #10
Source File: CustomHTMLReporter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Consumer<ISuiteResult> getSuiteResultConsumer(File outputDirectory, boolean onlyShowFailures,
        AtomicInteger suiteIndex, AtomicInteger testIndex) {
    return result -> {
        generateResultFile(outputDirectory, onlyShowFailures,
                suiteIndex.get(), testIndex.get(), result);
        testIndex.incrementAndGet();
    };
}
 
Example #11
Source File: CustomHTMLReporter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void generateResultFile(File outputDirectory, boolean onlyShowFailures,
        int suiteIndex, int testIndex, ISuiteResult result) {
    try {
        boolean failuresExist = result.getTestContext().getFailedTests().size() > 0
                || result.getTestContext().getFailedConfigurations().size() > 0;
        if (!onlyShowFailures || failuresExist) {
            VelocityContext context = createContext();
            context.put(RESULT_KEY, result);
            context.put(FAILED_CONFIG_KEY, sortByTestClass(result.getTestContext().getFailedConfigurations()));
            context.put(SKIPPED_CONFIG_KEY, sortByTestClass(result.getTestContext().getSkippedConfigurations()));
            context.put(FAILED_TESTS_KEY, sortByTestClass(result.getTestContext().getFailedTests()));
            context.put(SKIPPED_TESTS_KEY, sortByTestClass(result.getTestContext().getSkippedTests()));
            context.put(PASSED_TESTS_KEY, sortByTestClass(result.getTestContext().getPassedTests()));
            Measure measures = Util.collectMeasurements(result.getTestContext());
            Util.writeToFile(measures, outputDirectory.getPath() + System.getProperty("file.separator") + "measures.csv");
            KeyPerformanceIndicator keyIndicators = Util.getKeyPerformance(measures);
            if (keyIndicators != null) {
                context.put(Util.KEY_PERFORMANCE_INDICATOR, keyIndicators);
            }
            String fileName = String.format("suite%d_test%d_%s", suiteIndex, testIndex, RESULTS_FILE);
            File file = new File(outputDirectory, fileName);
            FileUtils.deleteQuietly(file);
            generateFile(file, "custom." + RESULTS_FILE + TEMPLATE_EXTENSION, context);
        }
    } catch (Exception e) {
        LOGGER.error("Error during result report generation: ", e);
    }
}
 
Example #12
Source File: EarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
/**
 * Creates EARL statements for the entire collection of test suite results.
 * Each test subset is defined by a {@literal <test>} tag in the suite
 * definition; these correspond to earl:TestRequirement resources in the
 * model.
 * 
 * @param model
 *            An RDF Model containing EARL statements.
 * @param results
 *            A Map containing the actual test results, where the key is the
 *            name of a test subset (conformance class).
 */
void processSuiteResults(Model model, Map<String, ISuiteResult> results) {
    for (Map.Entry<String, ISuiteResult> entry : results.entrySet()) {
        String testName = entry.getKey();
        String testReqName = testName.replaceAll("\\s", "-");
        // can return existing resource in model
        Resource testReq = model.createResource(testReqName);
        ITestContext testContext = entry.getValue().getTestContext();
        int nPassed = testContext.getPassedTests().size();
        int nSkipped = testContext.getSkippedTests().size();
        int nFailed = testContext.getFailedTests().size();
        testReq.addLiteral(CITE.testsPassed, new Integer(nPassed));
        testReq.addLiteral(CITE.testsFailed, new Integer(nFailed));
        testReq.addLiteral(CITE.testsSkipped, new Integer(nSkipped));
        if (nPassed + nFailed == 0) {
            testReq.addProperty(DCTerms.description,
                    "A precondition was not met. All tests in this set were skipped.");
        }
        if(isBasicConformanceClass(testName)){
          if(nFailed > 0){
            areCoreConformanceClassesPassed = false;
          }              
        }
        processTestResults(model, testContext.getFailedTests());
        processTestResults(model, testContext.getSkippedTests());
        processTestResults(model, testContext.getPassedTests());
    }
}
 
Example #13
Source File: PowerEmailableReporter.java    From WebAndAppUITesting with GNU General Public License v3.0 4 votes vote down vote up
public void generateSuiteSummaryReport(List<ISuite> suites) {
	tableStart("testOverview", null);
	m_out.print("<tr>");
	tableColumnStart("Test");
	tableColumnStart("Methods<br/>Passed");
	tableColumnStart("Scenarios<br/>Passed");
	tableColumnStart("# skipped");
	tableColumnStart("# failed");
	tableColumnStart("Total<br/>Time");
	tableColumnStart("Included<br/>Groups");
	tableColumnStart("Excluded<br/>Groups");
	m_out.println("</tr>");
	NumberFormat formatter = new DecimalFormat("#,##0.0");
	int qty_tests = 0;
	int qty_pass_m = 0;
	int qty_pass_s = 0;
	int qty_skip = 0;
	int qty_fail = 0;
	long time_start = Long.MAX_VALUE;
	long time_end = Long.MIN_VALUE;
	m_testIndex = 1;
	for (ISuite suite : suites) {
		if (suites.size() > 1) {
			titleRow(suite.getName(), 8);
		}
		Map<String, ISuiteResult> tests = suite.getResults();
		for (ISuiteResult r : tests.values()) {
			qty_tests += 1;
			ITestContext overview = r.getTestContext();
			startSummaryRow(overview.getName());

			getAllTestIds(overview, suite);
			int q = getMethodSet(overview.getPassedTests(), suite).size();
			qty_pass_m += q;
			summaryCell(q, Integer.MAX_VALUE);
			q = overview.getPassedTests().size();
			qty_pass_s += q;
			summaryCell(q, Integer.MAX_VALUE);

			q = getMethodSet(overview.getSkippedTests(), suite).size();
			qty_skip += q;
			summaryCell(q, 0);

			q = getMethodSet(overview.getFailedTests(), suite).size();
			qty_fail += q;
			summaryCell(q, 0);

			time_start = Math.min(overview.getStartDate().getTime(), time_start);
			time_end = Math.max(overview.getEndDate().getTime(), time_end);
			summaryCell(
					formatter.format((overview.getEndDate().getTime() - overview.getStartDate().getTime()) / 1000.)
							+ " seconds",
					true);
			summaryCell(overview.getIncludedGroups());
			summaryCell(overview.getExcludedGroups());
			m_out.println("</tr>");
			m_testIndex++;
		}
	}
	if (qty_tests > 1) {
		m_out.println("<tr class=\"total\"><td>Total</td>");
		summaryCell(qty_pass_m, Integer.MAX_VALUE);
		summaryCell(qty_pass_s, Integer.MAX_VALUE);
		summaryCell(qty_skip, 0);
		summaryCell(qty_fail, 0);
		summaryCell(formatter.format((time_end - time_start) / 1000.) + " seconds", true);
		m_out.println("<td colspan=\"2\">&nbsp;</td></tr>");
	}
	m_out.println("</table>");
}
 
Example #14
Source File: GatekeeperBehaviour.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private boolean hasFailedGatekeeperTest(Map<String, ISuiteResult> results) {
    return results.values().stream().anyMatch(iSuiteResult -> {
        return iSuiteResult.getTestContext().getFailedTests().size() != 0
                && Objects.equals(iSuiteResult.getTestContext().getCurrentXmlTest().getParameter(IS_GATEKEEPER), TRUE);
    });
}
 
Example #15
Source File: ReportLog.java    From teamengine with Apache License 2.0 4 votes vote down vote up
/**
 * Creates report logs that consists of test statics by extracting information from 
 * the Test suite results. These Report logs are then printed in the TestNG HTML reports.
 * 
 * @param suite is the test suite from which you want to extract test results information.
 */
public void generateLogs(ISuite suite) {
    Reporter.clear(); // clear output from previous test runs
    Reporter.log("The result of the test is-\n\n");

    //Following code gets the suite name
    String suiteName = suite.getName();
    //Getting the results for the said suite
    Map<String, ISuiteResult> suiteResults = suite.getResults();
    String input = null;
    String result;
    String failReport = null;
    String failReportConformance2=",";
    int passedTest = 0;
    int failedTest = 0;
    int skippedTest = 0;
    int finalPassedTest=0;
    int finalSkippedTest=0;
    int finalFailedTest=0;
    int count = 0;
    String date = null;
    for (ISuiteResult sr : suiteResults.values()) {
        count++;
        ITestContext tc = sr.getTestContext();
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        if (count == 1) {
            date = dateFormat.format(cal.getTime());
            input = tc.getAttribute("Input").toString();
            failReport = tc.getAttribute("TestResultReport").toString();
            passedTest = tc.getPassedTests().getAllResults().size();
            skippedTest = tc.getSkippedTests().getAllResults().size();
            failedTest = tc.getFailedTests().getAllResults().size();

        } else {
            int no_of_failedTest = tc.getFailedTests().getAllResults().size();
            int no_of_skippedTest = tc.getSkippedTests().getAllResults().size();
            int no_of_passedTest = tc.getPassedTests().getAllResults().size();
            if(no_of_failedTest!=0 || no_of_passedTest !=0)
            {
                if (no_of_failedTest == 0 && no_of_passedTest !=0 ) {
                failReportConformance2 = failReportConformance2+", "+input + " conform to the clause A." + count + " of "+suiteName;
            } else {
                    failReportConformance2 = failReportConformance2+", "+input + " does not conform to the clause A." + count + " of "+suiteName;
                
            }
            finalPassedTest = finalPassedTest + no_of_passedTest;
            finalSkippedTest = finalSkippedTest + no_of_skippedTest;
            finalFailedTest = finalFailedTest + no_of_failedTest;
        }
        }

    }
    failedTest+=finalFailedTest;
    skippedTest+=finalSkippedTest;
    passedTest+=finalPassedTest;
    if(failedTest>0){
      result="Fail";
    }else{
      result="Pass";
    }
    Reporter.log("**RESULT: " + result);
    Reporter.log("**INPUT: " + input);
    Reporter.log("**TEST NAME AND VERSION    :" + suiteName);
    Reporter.log("**DATE AND TIME PERFORMED  :" + date);
    Reporter.log("Passed tests for suite '" + suiteName
            + "' is:" + passedTest);

    Reporter.log("Failed tests for suite '" + suiteName
            + "' is:"
            + failedTest);

    Reporter.log("Skipped tests for suite '" + suiteName
            + "' is:"
            + skippedTest);
    Reporter.log("\nREASON:\n\n");
    Reporter.log(failReport);
    Reporter.log(failReportConformance2);

}