本文整理匯總了Java中org.testng.ITestResult.getThrowable方法的典型用法代碼示例。如果您正苦於以下問題:Java ITestResult.getThrowable方法的具體用法?Java ITestResult.getThrowable怎麽用?Java ITestResult.getThrowable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.testng.ITestResult
的用法示例。
在下文中一共展示了ITestResult.getThrowable方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.testng.ITestResult; //導入方法依賴的package包/類
@Override
public void run(IHookCallBack callBack, ITestResult testResult) {
super.run(callBack, testResult);
if (testResult.getThrowable() != null) {
try {
final Throwable testResultThrowable = testResult.getThrowable();
String message = testResultThrowable.getMessage() != null ? testResultThrowable.getMessage() :
testResultThrowable.getCause().getMessage();
if (message == null) {
message = "Test failed";
}
new Screenshoter().takeScreenshot(message, TestUtils.getTestName(testResult));
} catch (Exception e) {
log("Couldn't take screenshot. Error: " + e.getMessage());
}
}
}
示例2: onTestFailure
import org.testng.ITestResult; //導入方法依賴的package包/類
@Override
public void onTestFailure(final ITestResult result) {
Current current = currentTestResult.get();
if (current.isAfter()) {
current = refreshContext();
}
//if testng has failed without any setup
if (!current.isStarted()) {
createTestResultForTestWithoutSetup(result);
}
current.after();
final Throwable throwable = result.getThrowable();
final Status status = getStatus(throwable);
final StatusDetails details = getStatusDetails(throwable).orElse(null);
getLifecycle().updateTestCase(current.getUuid(), setStatus(status, details));
getLifecycle().stopTestCase(current.getUuid());
getLifecycle().writeTestCase(current.getUuid());
}
示例3: configurationError
import org.testng.ITestResult; //導入方法依賴的package包/類
private boolean configurationError( ITestContext context ) {
// check if this is a configuration issue
List<ITestResult> failedConfigurations = Arrays.asList(context.getFailedConfigurations()
.getAllResults()
.toArray(new ITestResult[context.getFailedConfigurations()
.getAllResults()
.size()]));
for (ITestResult failedResult : failedConfigurations) {
if (failedResult.getThrowable() != null) {
logger.fatal("Configuration failed!", failedResult.getThrowable());
return true;
}
}
return false;
}
示例4: setFailedTcAttribute
import org.testng.ITestResult; //導入方法依賴的package包/類
private void setFailedTcAttribute(XMLStringBuffer doc, ITestResult failedTestCase) {
Properties attributesFailedTestSuites = new Properties();
String tcName = ((HashMap<String, String>) failedTestCase.getParameters()[0]).get(PROP_TEST_ID);
attributesFailedTestSuites.setProperty(XMLConstants.ATTR_NAME, tcName);
long elapsedTimeMillis = failedTestCase.getEndMillis() - failedTestCase.getStartMillis();
testRunningTotalTime += elapsedTimeMillis;
Throwable t = failedTestCase.getThrowable();
doc.push(XMLConstants.TESTCASE, attributesFailedTestSuites);
if (t != null) {
attributesFailedTestSuites.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());
String message = t.getMessage();
if ((message != null) && (message.length() > 0)) {
attributesFailedTestSuites.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE
}
doc.push(XMLConstants.FAILURE, attributesFailedTestSuites);
doc.addCDATA(Utils.stackTrace(t, false)[0]);
doc.pop();
} else {
doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR
}
doc.pop();
}
示例5: onTestFailure
import org.testng.ITestResult; //導入方法依賴的package包/類
@Override
public void onTestFailure( ITestResult testResult ) {
try {
//Check if the test was successfully started, if not - make it started and then end it with failure
String testName = testResult.getMethod().toString();
if (!testName.equals(lastTestName)) {
onTestStart(testResult);
}
sendTestEndEventToAgents();
// if this is an assertion error, we need to log it
Throwable failureException = testResult.getThrowable();
if (failureException instanceof AssertionError) {
if (failureException.getMessage() != null) {
logger.error(failureException.getMessage());
} else {
logger.error("Received java.lang.AssertionError with null message");
}
} else {
logger.error(MSG__TEST_FAILED, testResult.getThrowable());
}
// end test case
logger.endTestcase(TestCaseResult.FAILED);
} catch (Exception e) {
logger.fatal("UNEXPECTED EXCEPTION IN [email protected]", e);
}
super.onTestFailure(testResult);
}
示例6: configurationError
import org.testng.ITestResult; //導入方法依賴的package包/類
private boolean configurationError() {
// check if this is a configuration issue
List<ITestResult> failedConfigurations = getConfigurationFailures();
for (ITestResult failedResult : failedConfigurations) {
if (failedResult.getThrowable() != null) {
logger.fatal("Configuration failed!", failedResult.getThrowable());
return true;
}
}
return false;
}
示例7: endTestcaseWithFailureStatus
import org.testng.ITestResult; //導入方法依賴的package包/類
private void endTestcaseWithFailureStatus( ITestResult testResult ) {
try {
//Check if the test was successfully started, if not - make it started and then end it with failure
String testName = testResult.getMethod().toString();
if (!testName.equals(currentTestcaseName)) {
startTestcase(testResult);
}
sendTestEndEventToAgents();
// if this is an assertion error, we need to log it
Throwable failureException = testResult.getThrowable();
if (failureException instanceof AssertionError) {
if (failureException.getMessage() != null) {
logger.error(ExceptionUtils.getExceptionMsg(failureException));
} else {
logger.error("Received java.lang.AssertionError with null message");
}
} else {
logger.error(MSG__TEST_FAILED, testResult.getThrowable());
}
currentTestcaseName = null;
lastTestcaseResult = TestCaseResult.FAILED.toInt();
// end test case
logger.endTestcase(TestCaseResult.FAILED);
} catch (Exception e) {
logger.fatal("UNEXPECTED EXCEPTION IN [email protected]", e);
}
}
示例8: setLog
import org.testng.ITestResult; //導入方法依賴的package包/類
private void setLog(ITestResult tr) {
StringWriter exception = new StringWriter();
if (tr.getThrowable() != null) {
tr.getThrowable().printStackTrace(new PrintWriter(exception));
}
tr.setAttribute("log", MTLogBuffer.getStringLog() + exception);
}
示例9: generateForResult
import org.testng.ITestResult; //導入方法依賴的package包/類
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>");
}
}
示例10: afterInvocation
import org.testng.ITestResult; //導入方法依賴的package包/類
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
if(shouldBeInvoked(testResult.getInstance().getClass(), FastFailListener.class) &&
testResult.getThrowable() != null && !failedClasses.containsKey(testResult.getInstance()))
failedClasses.put(testResult.getInstance(), method);
}