Java Code Examples for org.testng.ITestResult#FAILURE

The following examples show how to use org.testng.ITestResult#FAILURE . 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: AppiumParallelTestListener.java    From AppiumTestDistribution with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
    JSONObject json = new JSONObject();
    json.put("id", AppiumDeviceManager.getAppiumDevice().getDevice().getUdid());
    json.put("version", new AppiumDeviceManager().getDeviceVersion());
    json.put("platform", AppiumDeviceManager.getMobilePlatform());
    json.put("model", new AppiumDeviceManager().getDeviceModel());
    try {
        if (testResult.getStatus() == ITestResult.SUCCESS
            || testResult.getStatus() == ITestResult.FAILURE) {
            HashMap<String, String> logs = testLogger.endLogging(testResult,
                AppiumDeviceManager.getAppiumDevice().getDevice().getDeviceModel());
            if (atdHost.isPresent() && atdPort.isPresent()) {
                String postTestResults = "http://" + atdHost.get() + ":" + atdPort.get() + "/testresults";
                sendResultsToAtdService(testResult, "Completed", postTestResults, logs);
            }
        }
        if (method.isTestMethod()) {
            appiumDriverManager.stopAppiumDriver();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    SessionContext.remove(Thread.currentThread().getId());
    queueAfterInvocationListener(method, testResult, iTestNGListeners);
}
 
Example 2
Source File: BrowserTest.java    From coteafs-selenium with Apache License 2.0 6 votes vote down vote up
/**
 * @param result test result
 * @author wasiqb
 * @since Mar 21, 2019 6:46:47 PM
 */
@AfterMethod (alwaysRun = true)
public void teardownMethod (final ITestResult result) {
    final ScreenshotSetting screenshotSetting = appSetting ().getPlayback ()
        .getScreenshot ();
    final boolean screenshotOnError = screenshotSetting.isCaptureOnError ();
    final boolean captureAll = screenshotSetting.isCaptureAll ();
    if (captureAll || screenshotOnError && result.getStatus () == ITestResult.FAILURE && this.browser.isRunning ()) {
        final File screenshot = this.browser.perform ()
            .saveScreenshot ();
        final Throwable cause = result.getThrowable ();
        if (cause != null) {
            log (LogLevel.ERROR, screenshot, "Test Failed");
        } else {
            log (LogLevel.INFO, screenshot, "Screenshot captured.");
        }
    }
}
 
Example 3
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 6 votes vote down vote up
protected static void writeTestCase(Writer out, TestCase result) throws IOException {
    long time=result.stop_time - result.start_time;
    // StringBuilder sb=new StringBuilder();
    out.write("\n    <testcase classname=\"" + result.classname);
    out.write("\"  name=\"" + result.name + "\" time=\"" + (time / 1000.0) + "\">");

    switch(result.status) {
        case ITestResult.FAILURE:
            String failure=writeFailure("failure", result.failure_type, result.failure_msg, result.stack_trace);
            if(failure != null)
                out.write(failure);
            break;
        case ITestResult.SKIP:
            failure=writeFailure("error", result.failure_type, result.failure_msg, result.stack_trace);
            if(failure != null)
                out.write(failure);
            break;
    }
    out.write("\n    </testcase>\n");
}
 
Example 4
Source File: TestHarness.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void printError(ITestResult result) {
    if (result.getStatus() == ITestResult.FAILURE) {
        String clsName = result.getTestClass().getName();
        clsName = clsName.substring(clsName.lastIndexOf(".") + 1);
        System.out.println("Test " + clsName + "." +
                           result.getName() + " FAILED");
    }
}
 
Example 5
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private static int getFailures(List<ITestResult> results) {
    int retval = 0;
    for (ITestResult result : results) {
        if (result != null && result.getStatus() == ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 6
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 5 votes vote down vote up
private static int getErrors(List<ITestResult> results) {
    int retval = 0;
    for (ITestResult result : results) {
        if (result != null && result.getStatus() != ITestResult.SUCCESS && result.getStatus() != ITestResult.SUCCESS_PERCENTAGE_FAILURE
                && result.getStatus() != ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 7
Source File: Helpers.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
protected String getStatus(ITestResult result) {
    switch (result.getStatus()) {
        case ITestResult.SUCCESS:
            return "Pass";
        case ITestResult.FAILURE:
            return "Fail";
        case ITestResult.SKIP:
            return "Skip";
        default:
            return "Unknown";
    }
}
 
Example 8
Source File: FDSeparateCompilationTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void printCaseError(ITestResult result) {
    if (result.getStatus() == ITestResult.FAILURE) {
        Hierarchy hs = (Hierarchy)result.getParameters()[0];
        System.out.println("Separate compilation case " + hs);
        printCaseDetails(hs);
    }
}
 
Example 9
Source File: FDSeparateCompilationTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void printCaseError(ITestResult result) {
    if (result.getStatus() == ITestResult.FAILURE) {
        Hierarchy hs = (Hierarchy)result.getParameters()[0];
        System.out.println("Separate compilation case " + hs);
        printCaseDetails(hs);
    }
}
 
Example 10
Source File: APITestRunner.java    From frameworkium-bdd with Apache License 2.0 5 votes vote down vote up
private void logResult(ITestResult result) {
    switch (result.getStatus()) {
        case ITestResult.FAILURE:
            logger.error("FAIL  {}", scenarioName.get());
            break;
        case ITestResult.SKIP:
            logger.warn("SKIP  {}", scenarioName.get());
            break;
        case ITestResult.SUCCESS:
            logger.info("PASS  {}", scenarioName.get());
            break;
        default:
            logger.warn("Unexpected result status: {}", result.getStatus());
    }
}
 
Example 11
Source File: TestHarness.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void printError(ITestResult result) {
    if (result.getStatus() == ITestResult.FAILURE) {
        String clsName = result.getTestClass().getName();
        clsName = clsName.substring(clsName.lastIndexOf(".") + 1);
        System.out.println("Test " + clsName + "." +
                           result.getName() + " FAILED");
    }
}
 
Example 12
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
public static int getFailures(Collection<TestCase> results) {
    int retval=0;
    for(TestCase result: results) {
        if(result != null && result.status == ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 13
Source File: CustomAutomationLogger.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * alert result of test case to the console in the following format:<br>
 * <test name prefix>...<event message>
 * 
 * @param testResult
 */
private void alertEvent(ITestResult testResult, boolean expectedToFail) {
	String eventMessage = "";
	// put the right event message to eventMessage according to testResult.getStatus()
	switch (testResult.getStatus()) {
		case ITestResult.SUCCESS:
			eventMessage = "OK";
			break;
		case ITestResult.FAILURE:
			// if case expected to fail, sign as "EXPECTED FAILURE"
			if (!expectedToFail) {
				eventMessage = "FAILED";
			} else {
				eventMessage = "EXPECTED FAILURE";
			}
			break;
		case ITestResult.SKIP:
			eventMessage = "SKIPPED";
			break;
		default:
			break;
	}

	// redirect System.out back to original stream
	revertStdoutStream();
	// alert event to console
	System.out.println(getTestNamePrefix(testResult) + "..." + eventMessage);
}
 
Example 14
Source File: JUnitXMLReporter.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
public static int getErrors(Collection<TestCase> results) {
    int retval=0;
    for(TestCase result: results) {
        if(result != null && result.status != ITestResult.SUCCESS
          && result.status != ITestResult.SUCCESS_PERCENTAGE_FAILURE
          && result.status != ITestResult.FAILURE)
            retval++;
    }
    return retval;
}
 
Example 15
Source File: FDSeparateCompilationTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void printCaseError(ITestResult result) {
    if (result.getStatus() == ITestResult.FAILURE) {
        Hierarchy hs = (Hierarchy)result.getParameters()[0];
        System.out.println("Separate compilation case " + hs);
        printCaseDetails(hs);
    }
}
 
Example 16
Source File: TestHarness.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void printError(ITestResult result) {
    if (result.getStatus() == ITestResult.FAILURE) {
        String clsName = result.getTestClass().getName();
        clsName = clsName.substring(clsName.lastIndexOf(".") + 1);
        System.out.println("Test " + clsName + "." +
                           result.getName() + " FAILED");
    }
}
 
Example 17
Source File: QAFTestNGListener.java    From qaf with MIT License 4 votes vote down vote up
protected void processResult(ITestResult tr, ITestContext context) {
	QAFTestBase stb = TestBaseProvider.instance().get();

	if ((stb.getVerificationErrors() > 0)
			&& (tr.getStatus() == ITestResult.SUCCESS)) {
		setFailure(tr, context);
	}

	if (tr.getStatus() == ITestResult.FAILURE) {
		String failiremsg = getFailureMessage(tr.getThrowable());
		CheckpointResultBean lastFailedChkPoint =
				getLastFailedCheckpointResultBean(stb.getCheckPointResults());

		// not an assertion of verification failure
		if (null != lastFailedChkPoint) {
			// ensure last failed check-point has screenshot

			if (StringUtil.isBlank(lastFailedChkPoint.getScreenshot())) {
				// get last failed sub-checkpoint
				CheckpointResultBean lastFailedSubChkPoint =
						getLastFailedCheckpointResultBean(
								lastFailedChkPoint.getSubCheckPoints());

				if (lastFailedSubChkPoint != null && StringUtil
						.isNotBlank(lastFailedSubChkPoint.getScreenshot())) {
					lastFailedChkPoint
							.setScreenshot(lastFailedSubChkPoint.getScreenshot());

				} else {
					stb.takeScreenShot();
					lastFailedChkPoint.setScreenshot(stb.getLastCapturedScreenShot());
				}
			}
		} else if (StringUtil.isNotBlank(failiremsg)) {
			logger.error(tr.getThrowable());

			// stb.addAssertionLogWithScreenShot(failiremsg,
			// MessageTypes.Fail);
			stb.takeScreenShot();
			CheckpointResultBean stepResultBean = new CheckpointResultBean();
			stepResultBean.setMessage(failiremsg);
			stepResultBean.setType(MessageTypes.Fail);
			stepResultBean.setScreenshot(stb.getLastCapturedScreenShot());
			stb.getCheckPointResults().add(stepResultBean);

		}
		// discontinue support for "selenium.wait.failure.setskip". Use QAS
		// listener instead
		// if ((tr.getThrowable() instanceof WaitTimedOutException)
		// && (getBundle().getBoolean("selenium.wait.failure.setskip"))) {
		// setSkip(tr, context);
		// }
	}
}
 
Example 18
Source File: JUnitXMLReporter.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * generate the XML report given what we know from all the test results
 */
protected void generateReport() throws IOException {
    for (Map.Entry<Class, List<ITestResult>> entry : classes.entrySet()) {
        Class clazz = entry.getKey();
        List<ITestResult> results = entry.getValue();

        int num_failures = getFailures(results);
        int num_skips = getSkips(results);
        int num_errors = getErrors(results);
        long total_time = getTotalTime(results);

        String file_name = output_dir + File.separator + "TEST-" + clazz.getName();
        if (suffix != null)
            file_name = file_name + "-" + suffix;
        file_name = file_name + ".xml";
        FileWriter out = new FileWriter(file_name, false); // don't append, overwrite
        try {
            out.write(XML_DEF + "\n");

            out.write("\n<testsuite " + " failures=\"" + num_failures + "\" errors=\"" + num_errors + "\" skips=\"" + num_skips + "\" name=\"" + clazz.getName());
            if (suffix != null)
                out.write(" (" + suffix + ")");
            out.write("\" tests=\"" + results.size() + "\" time=\"" + (total_time / 1000.0) + "\">");

            out.write("\n<properties>");
            Properties props = System.getProperties();

            for (Map.Entry<Object, Object> tmp : props.entrySet()) {
                out.write("\n    <property name=\"" + tmp.getKey() + "\"" + " value=\"" + tmp.getValue() + "\"/>");
            }
            out.write("\n</properties>\n");

            for (ITestResult result : results) {
                if (result == null)
                    continue;
                long time = result.getEndMillis() - result.getStartMillis();
                out.write("\n    <testcase classname=\"" + clazz.getName());
                if (suffix != null)
                    out.write(" (" + suffix + ")");
                out.write("\" name=\"" + result.getMethod().getMethodName() + "\" time=\"" + (time / 1000.0) + "\">");

                Throwable ex = result.getThrowable();

                switch (result.getStatus()) {
                case ITestResult.SUCCESS:
                case ITestResult.SUCCESS_PERCENTAGE_FAILURE:
                    break;
                case ITestResult.FAILURE:
                    writeFailure("failure", result.getMethod().getMethod(), ex, "exception", out);
                    break;
                case ITestResult.SKIP:
                    writeFailure("error", result.getMethod().getMethod(), ex, "SKIPPED", out);
                    break;
                default:
                    writeFailure("error", result.getMethod().getMethod(), ex, "exception", out);
                }

                out.write("\n</testcase>");
            }

            Tuple<ByteArrayOutputStream, ByteArrayOutputStream> stdout = outputs.get(clazz);
            if (stdout != null) {
                ByteArrayOutputStream system_out = stdout.getVal1();
                ByteArrayOutputStream system_err = stdout.getVal2();
                writeOutput(out, system_out.toString(), 1);
                out.write("\n");
                writeOutput(out, system_err.toString(), 2);
            }

            out.write("\n</testsuite>\n");
        } finally {
            out.close();
        }
    }

}
 
Example 19
Source File: TestLogger.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
protected HashMap<String, String> endLogging(ITestResult result, String deviceModel)
        throws Exception {
    HashMap<String, String> logs = new HashMap<>();
    String className = result.getInstance().getClass().getSimpleName();
    stopViewRecording(result, className);
    if (isNativeAndroid()) {
        String adbPath = System.getProperty("user.dir") + FileLocations.ADB_LOGS_DIRECTORY
                + AppiumDeviceManager.getAppiumDevice().getDevice().getUdid()
                + "__" + result.getMethod().getMethodName() + ".txt";
        logs.put("adbLogs", adbPath);
        logEntries.get().forEach(logEntry -> {
            log_file_writer.get().println(logEntry);
        });
        log_file_writer.get().close();
        ReportPortal.emitLog("ADB Logs", "DEBUG", new Date(), new File(adbPath));
    }
    /*
     * Failure Block
     */
    handleTestFailure(result, className, deviceModel);
    String baseHostUrl = "http://" + getHostMachineIpAddress() + ":"
            + getRemoteAppiumManagerPort(AppiumDeviceManager
            .getAppiumDevice().getHostName());
    if ("true".equalsIgnoreCase(System.getenv("VIDEO_LOGS"))) {
        setVideoPath("screenshot/" + AppiumDeviceManager.getMobilePlatform()
                .toString().toLowerCase()
                + "/" + AppiumDeviceManager.getAppiumDevice().getDevice().getUdid()
                + "/" + className + "/" + result.getMethod()
                .getMethodName() + "/" + result.getMethod().getMethodName() + ".mp4");

        String videoPath = System.getProperty("user.dir")
                + FileLocations.OUTPUT_DIRECTORY + getVideoPath();
        if (new File(videoPath).exists()) {
            ReportPortal.emitLog("Video Logs", "Trace", new Date(), new File(videoPath));
            logs.put("videoLogs", baseHostUrl + "/" + getVideoPath());
        }
    }
    String failedScreen = screenShotManager.getFailedScreen();
    String framedFailureScreen = screenShotManager.getFramedFailedScreen();

    if (result.getStatus() == ITestResult.FAILURE) {
        String screenShotFailure = null;
        try {
            screenShotFailure = baseHostUrl;
        } catch (Exception e) {
            e.printStackTrace();
        }
        String screenFailure = System.getProperty("user.dir")
                + FileLocations.OUTPUT_DIRECTORY + failedScreen;
        if (new File(screenFailure).exists()) {
            screenShotFailure = screenShotFailure
                    + "/" + failedScreen;
            logs.put("screenShotFailure", screenShotFailure);
        } else {
            String framedScreenFailure = System.getProperty("user.dir")
                    + FileLocations.OUTPUT_DIRECTORY + framedFailureScreen;
            if (new File(framedScreenFailure).exists()) {
                screenShotFailure = screenShotFailure
                        + "/" + framedScreenFailure;
                logs.put("screenShotFailure", screenShotFailure);
            }
        }
    }
    return logs;
}
 
Example 20
Source File: SeleniumTestHandler.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
/** Is invoked when test or configuration is finished. */
private void onTestFinish(ITestResult result) {
  // do not treat SeleniumTestHandler error as test failure
  if (testsWithFailure.containsKey(result.getTestClass().getRealClass().getName())
      && testsWithFailure
          .get(result.getTestClass().getRealClass().getName())
          .getMethod()
          .equals(result.getMethod())
      && result.getMethod().getCurrentInvocationCount() == 1) {
    // restore initial test exception
    result.setThrowable(
        testsWithFailure.get(result.getTestClass().getRealClass().getName()).getThrowable());
    return;
  }

  if (result.getStatus() == ITestResult.FAILURE || result.getStatus() == ITestResult.SKIP) {
    switch (result.getStatus()) {
      case ITestResult.FAILURE:
        if (result.getMethod().isTest()) {
          String errorDetails =
              result.getThrowable() != null
                  ? " Error: " + result.getThrowable().getLocalizedMessage()
                  : "";

          LOG.error("Test {} failed.{}", getCompletedTestLabel(result.getMethod()), errorDetails);
          LOG.debug(result.getThrowable().getLocalizedMessage(), result.getThrowable());

          testsWithFailure.put(result.getTestClass().getRealClass().getName(), result);
        }

        captureWebDriver(result);
        captureTestWorkspaceLogs(result);

        break;

      case ITestResult.SKIP:
        String skipReasonDetails =
            result.getThrowable() != null
                ? " The reason: " + result.getThrowable().getLocalizedMessage()
                : "";
        if (result.getMethod().isTest()) {
          LOG.warn(
              "Test {} skipped.{}", getCompletedTestLabel(result.getMethod()), skipReasonDetails);
        }

        // don't capture test data if test is skipped because of previous test with higher
        // priority failed
        if (testsWithFailure.containsKey(result.getMethod().getInstance().getClass().getName())) {
          return;
        }

        break;

      default:
    }
  }
}