Java Code Examples for org.testng.ITestResult#SUCCESS
The following examples show how to use
org.testng.ITestResult#SUCCESS .
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: MobileSetupManager.java From functional-tests-core with Apache License 2.0 | 6 votes |
/** * Log test results. * * @param previousTestStatus Outcome of the test. * @param testCase Test name. */ public void logTestResult(int previousTestStatus, String testCase) { if (previousTestStatus == ITestResult.SUCCESS) { if (this.context.settings.takeScreenShotAfterTest) { this.context.log.logScreen(testCase + "_pass", "Screenshot after " + testCase); } this.log.info("=> Test " + testCase + " passed!"); } else if (previousTestStatus == ITestResult.FAILURE) { if (this.context.device == null) { LOGGER_BASE.error("The device is null"); } else { try { this.context.device.writeConsoleLogToFile(testCase); } catch (IOException e) { e.printStackTrace(); } } this.context.log.logScreen(testCase + "_fail", "Screenshot after " + testCase); this.context.log.saveXmlTree(testCase + "_VisualTree.xml"); this.log.error("=> Test " + testCase + " failed!"); } else if (this.context.lastTestResult == ITestResult.SKIP) { this.context.log.logScreen(testCase + "_skip", "Screenshot after " + testCase); this.log.error("=> Test " + testCase + " skipped!"); } }
Example 2
Source File: AppiumParallelTestListener.java From AppiumTestDistribution with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: APITestRunner.java From frameworkium-bdd with Apache License 2.0 | 5 votes |
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 4
Source File: JUnitXMLReporter.java From jgroups-raft with Apache License 2.0 | 5 votes |
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 5
Source File: ImageValidatorE2ETest.java From cloudbreak with Apache License 2.0 | 5 votes |
@AfterMethod public void setImageId(Object[] data, ITestResult result) { TestContext testContext = (TestContext) data[0]; if (result.getStatus() == ITestResult.SUCCESS) { LOG.info("The test was successful with this image: " + getImageId(testContext)); writeImageIdToFile(testContext); } }
Example 6
Source File: JUnitXMLReporter.java From olat with Apache License 2.0 | 5 votes |
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: JUnitXMLReporter.java From olat with Apache License 2.0 | 5 votes |
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 8
Source File: Helpers.java From AppiumTestDistribution with GNU General Public License v3.0 | 5 votes |
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 9
Source File: Execution.java From frameworkium-core with Apache License 2.0 | 5 votes |
/** * Gets the ZAPI status of the TestNG status. * * @return ZAPI execution status from the ITestResult status */ public static int getZAPIStatus(int status) { switch (status) { case ITestResult.SUCCESS: return JiraConfig.ZapiStatus.ZAPI_STATUS_PASS; case ITestResult.FAILURE: return JiraConfig.ZapiStatus.ZAPI_STATUS_FAIL; case ITestResult.SKIP: return JiraConfig.ZapiStatus.ZAPI_STATUS_BLOCKED; default: return JiraConfig.ZapiStatus.ZAPI_STATUS_FAIL; } }
Example 10
Source File: CustomAutomationLogger.java From pxf with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: UITestRunner.java From frameworkium-bdd with Apache License 2.0 | 5 votes |
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 12
Source File: ReporterUtil.java From qaf with MIT License | 5 votes |
private static String getResult(int res) { switch (res) { case ITestResult.SUCCESS : return "pass"; case ITestResult.FAILURE : return "fail"; case ITestResult.SKIP : return "skip"; case ITestResult.SUCCESS_PERCENTAGE_FAILURE : return "pass"; default : return ""; } }
Example 13
Source File: JUnitXMLReporter.java From jgroups-raft with Apache License 2.0 | 5 votes |
protected static String statusToString(int status) { switch(status) { case ITestResult.SUCCESS: case ITestResult.SUCCESS_PERCENTAGE_FAILURE: return "OK"; case ITestResult.FAILURE: return "FAIL"; case ITestResult.SKIP: return "SKIP"; default: return "N/A"; } }
Example 14
Source File: QAFTestNGListener2.java From qaf with MIT License | 4 votes |
@SuppressWarnings("unchecked") private void deployResult(ITestResult tr) { try { if (ResultUpdator.getResultUpdatorsCnt()>0 && (tr.getMethod() instanceof TestNGScenario) && ((tr.getStatus() == ITestResult.FAILURE) || (tr.getStatus() == ITestResult.SUCCESS || tr.getStatus() == ITestResult.SKIP))) { TestCaseRunResult.Status status = tr.getStatus() == ITestResult.SUCCESS ? TestCaseRunResult.Status.PASS : tr.getStatus() == ITestResult.FAILURE ? TestCaseRunResult.Status.FAIL : TestCaseRunResult.Status.SKIPPED; TestNGScenario scenario = (TestNGScenario) tr.getMethod(); Map<String, Object> params = new HashMap<String, Object>(scenario.getMetaData()); params.put("duration", tr.getEndMillis() - tr.getStartMillis()); Map<String, Object> executionInfo = new HashMap<String, Object>(); executionInfo.put("testName", tr.getTestContext().getCurrentXmlTest().getName()); executionInfo.put("suiteName", tr.getTestContext().getSuite().getName()); Map<String, Object> runPrams = new HashMap<String, Object>( tr.getTestContext().getCurrentXmlTest().getAllParameters()); runPrams.putAll(ConfigurationConverter.getMap(getBundle().subset("env"))); executionInfo.put("env", runPrams); int retryCount = getBundle().getInt(RetryAnalyzer.RETRY_INVOCATION_COUNT, 0); boolean willRetry = getBundle().getBoolean(RetryAnalyzer.WILL_RETRY, false); getBundle().clearProperty(RetryAnalyzer.WILL_RETRY); if(retryCount>0) { executionInfo.put("retryCount", retryCount); } TestCaseRunResult testCaseRunResult = new TestCaseRunResult(status, scenario.getMetaData(), tr.getParameters(), executionInfo, scenario.getSteps(), tr.getStartMillis(),willRetry,scenario.isTest() ); testCaseRunResult.setClassName(scenario.getClassOrFileName()); if (scenario.getGroups() != null && scenario.getGroups().length > 0) { testCaseRunResult.getMetaData().put("groups", scenario.getGroups()); } testCaseRunResult.getMetaData().put("description",scenario.getDescription()); testCaseRunResult.setThrowable(tr.getThrowable()); ResultUpdator.updateResult(testCaseRunResult); } } catch (Exception e) { logger.warn("Unable to deploy result", e); } }
Example 15
Source File: QAFTestNGListener.java From qaf with MIT License | 4 votes |
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 16
Source File: JUnitXMLReporter.java From olat with Apache License 2.0 | 4 votes |
/** * 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 17
Source File: MobileTest.java From functional-tests-core with Apache License 2.0 | 4 votes |
/** * Executed before each UI Test method. * * @param method TestMethod. * @throws Exception When something fails. */ @BeforeMethod(alwaysRun = true) public void beforeMethodUIBaseTest(Method method) throws Exception { this.context.setTestName(method.getName()); this.log.separator(); this.log.info("Start test: " + method.getName()); // Perform actions when previous test passed. if (this.context.lastTestResult == ITestResult.SUCCESS && this.settings.restartApp && !this.firstTest) { this.context.app.restart(); } // Perform set of actions on test fail. if (this.context.lastTestResult == ITestResult.FAILURE && this.context.shouldRestartAppOnFailure) { try { // Restart app under test this.context.app.restart(); } catch (Exception e) { // Restart might fail if server or client are dead this.mobileSetupManager.restartSession(); } // Reset navigation state manager if (this.context.navigationManager != null && this.context.shouldRestartAppOnFailure) { this.context.navigationManager.resetNavigationToLastOpenedPage(); } else { LOGGER.error("TestStateManager is: " + this.context.navigationManager + " in beforeMethodUIBaseTest!"); } } // First test is already started, so set this.firstTest = false; this.firstTest = false; this.imagesResults = new HashMap<String, Boolean>(); this.imageCounter = 1; if (this.settings.platform == PlatformType.iOS && (this.settings.isRealDevice || this.settings.platformVersion >= 11)) { this.device.getIOSDevice().startIOSDeviceLogWatcher(); } }
Example 18
Source File: JUnitXMLReporter.java From olat with Apache License 2.0 | 4 votes |
/** * 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: MobileSetupManager.java From functional-tests-core with Apache License 2.0 | 4 votes |
/** * Init only once per configuration. * * @return Instance of MobileSetupManager. */ public static MobileSetupManager initTestSetupBasic(boolean shouldStartLog4j) { MobileSetupManager mobileSetupManager; if (MobileSetupManager.initSettings == null) { if (shouldStartLog4j) { LoggerBase.initLog4j(); } MobileSetupManager.initSettings = new HashMap<>(); } if (!MobileSetupManager.initSettings.containsKey(getAppConfig())) { mobileSetupManager = new MobileSetupManager(); mobileSetupManager.settings = new MobileSettings(); mobileSetupManager.log = new Log(); mobileSetupManager.uiElements = new UIElementClass(mobileSetupManager.settings); mobileSetupManager.locators = new Locators(mobileSetupManager.settings); mobileSetupManager.server = new Server(mobileSetupManager.settings); mobileSetupManager.client = new Client(mobileSetupManager.server, mobileSetupManager.settings); mobileSetupManager.device = new Device(mobileSetupManager.client, mobileSetupManager.settings); mobileSetupManager.imageUtils = new ImageUtils(mobileSetupManager.settings, mobileSetupManager.client, mobileSetupManager.device); mobileSetupManager.log = new Log(mobileSetupManager.client, mobileSetupManager.settings); mobileSetupManager.app = new App(mobileSetupManager.device, mobileSetupManager.settings); mobileSetupManager.find = new Find(mobileSetupManager.client, mobileSetupManager.locators, mobileSetupManager.settings); mobileSetupManager.wait = new Wait(mobileSetupManager.client, mobileSetupManager.find, mobileSetupManager.settings); mobileSetupManager.gestures = new Gestures( mobileSetupManager.client, mobileSetupManager.wait, mobileSetupManager.device, mobileSetupManager.locators, mobileSetupManager.settings); mobileSetupManager.context = new MobileContext( mobileSetupManager.settings, mobileSetupManager.log, mobileSetupManager.client, mobileSetupManager.server, mobileSetupManager.device, mobileSetupManager.app, mobileSetupManager.find, mobileSetupManager.gestures, mobileSetupManager.imageUtils, mobileSetupManager.locators, mobileSetupManager.wait, mobileSetupManager.uiElements); mobileSetupManager.context.lastTestResult = ITestResult.SUCCESS; MobileSetupManager.initSettings.put(getAppConfig(), mobileSetupManager); } else { mobileSetupManager = MobileSetupManager.initSettings.get(getAppConfig()); } return mobileSetupManager; }
Example 20
Source File: PowerEmailableReporter.java From WebAndAppUITesting with GNU General Public License v3.0 | 4 votes |
private void generateForResult(ITestResult ans, ITestNGMethod method, int resultSetSize) { Object[] parameters = ans.getParameters(); boolean hasParameters = parameters != null && parameters.length > 0; if (hasParameters) { tableStart("result", null); m_out.print("<tr class=\"param\">"); for (int x = 1; x <= parameters.length; x++) { m_out.print("<th>Parameter #" + x + "</th>"); } m_out.println("</tr>"); m_out.print("<tr class=\"param stripe\">"); for (Object p : parameters) { m_out.println("<td>" + Utils.escapeHtml(p.toString()) + "</td>"); } m_out.println("</tr>"); } List<String> msgs = Reporter.getOutput(ans); boolean hasReporterOutput = msgs.size() > 0; Throwable exception = ans.getThrowable(); boolean hasThrowable = exception != null; if (hasReporterOutput || hasThrowable) { if (hasParameters) { m_out.print("<tr><td"); if (parameters.length > 1) { m_out.print(" colspan=\"" + parameters.length + "\""); } m_out.println(">"); } else { m_out.println("<div>"); } if (hasReporterOutput) { if (hasThrowable) { m_out.println("<h3>Test Messages</h3>"); } for (String line : msgs) { m_out.println(line + "<br/>"); } } if (hasThrowable) { boolean wantsMinimalOutput = ans.getStatus() == ITestResult.SUCCESS; if (hasReporterOutput) { m_out.println("<h3>" + (wantsMinimalOutput ? "Expected Exception" : "Failure") + "</h3>"); } generateExceptionReport(exception, method); } if (hasParameters) { m_out.println("</td></tr>"); } else { m_out.println("</div>"); } } if (hasParameters) { m_out.println("</table>"); } }