/** * Before invocation. * * @param methodtest the methodtest * @param result the result * @see org.testng.IInvokedMethodListener#beforeInvocation(org.testng.IInvokedMethod, * org.testng.ITestResult) */ @Override public final void beforeInvocation(final IInvokedMethod methodtest, final ITestResult result) { if (methodtest.isTestMethod()) { String dataProvider = ""; Method method = methodtest.getTestMethod().getConstructorOrMethod().getMethod(); Annotation[] testAnnot = method.getAnnotations(); for (Annotation annot : testAnnot) { if (annot instanceof Test) { Test tAnnot = (Test) annot; dataProvider = tAnnot.dataProvider(); if ("".equalsIgnoreCase(prevDataProvider) || !(prevDataProvider.equalsIgnoreCase(dataProvider))) { dataIteration = 0; prevDataProvider = dataProvider; } } } dataIteration++; } }
public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) { TestNG tn = new TestNG(); tn.setDefaultTestName(returnMethodName(arg0.getTestMethod())); String textMsg = "About to begin executing " + returnMethodName(arg0.getTestMethod()); method = returnMethodName(arg0.getTestMethod()); Reporter.log(textMsg, true); }
public void afterInvocation(IInvokedMethod method, ITestResult result) { resultT = result; String textMsg = "Completed executing " + returnMethodName(method.getTestMethod()); Reporter.log(textMsg, true); Reporter.setCurrentTestResult(result); if (method.isTestMethod()) { List<Throwable> verificationFailures = TestBase.getVerificationFailures(); // if there are verification failures... if (verificationFailures.size() > 0) { // set the test to failed result.setStatus(ITestResult.FAILURE); // if there is an assertion failure add it to verificationFailures if (result.getThrowable() != null) { verificationFailures.add(result.getThrowable()); } int size = verificationFailures.size(); // if there's only one failure just set that if (size == 1) { result.setThrowable(verificationFailures.get(0)); } else { // create a failure message with all failures and stack traces (except last failure) StringBuffer failureMessage = new StringBuffer("Multiple failures (").append(size).append("):\n\n"); for (int i = 0; i < size - 1; i++) { failureMessage .append("Failure ") .append(i + 1) .append(" of ") .append(size) .append(":\n"); Throwable t = verificationFailures.get(i); String fullStackTrace = Utils.stackTrace(t, false)[1]; failureMessage.append(fullStackTrace).append("\n\n"); } // final failure Throwable last = verificationFailures.get(size - 1); failureMessage.append("Failure ").append(size).append(" of ").append(size).append(":\n"); failureMessage.append(last.toString()); // set merged throwable Throwable merged = new Throwable(failureMessage.toString()); merged.setStackTrace(last.getStackTrace()); result.setThrowable(merged); } } } }
/** Arranges methods by classname and method name */ public int compare(IInvokedMethod o1, IInvokedMethod o2) { // System.out.println("Comparing " + o1.getMethodName() + " " + // o1.getDate() // + " and " + o2.getMethodName() + " " + o2.getDate()); return (int) (o1.getDate() - o2.getDate()); // int r = ((T) o1).getTestClass().getName().compareTo(((T) // o2).getTestClass().getName()); // if (r == 0) { // r = ((T) o1).getMethodName().compareTo(((T) o2).getMethodName()); // } // return r; }
/** * Get All tests id by class + method + parameters hash code. * * @param context * @param suite * @author kevinkong */ private void getAllTestIds(ITestContext context, ISuite suite) { IResultMap passTests = context.getPassedTests(); IResultMap failTests = context.getFailedTests(); List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods(); for (IInvokedMethod im : invokedMethods) { if (passTests.getAllMethods().contains(im.getTestMethod()) || failTests.getAllMethods().contains(im.getTestMethod())) { int testId = getId(im.getTestResult()); // m_out.println("ALLtestid=" + testId); allRunTestIds.add(testId); } } }
public void beforeInvocation(IInvokedMethod invokedMethod, ITestResult testResult) { if (!methodConfigured) { if (isAfterConfiguration(invokedMethod.getTestMethod())) { return; } if (invokedMethod.getTestMethod().isBeforeSuiteConfiguration()) { return; } configureMethod(testResult); methodConfigured = true; } }
@Override public void beforeInvocation( IInvokedMethod method, ITestResult testResult, ITestContext context) { int failed = findFailed(context); if (failed > 0) { LOG.error("Masking will not proceed. {} Configurations have failed", failed); return; } Method rmethod = method.getTestMethod().getConstructorOrMethod().getMethod(); if (rmethod.getAnnotation(Test.class) != null || rmethod.getAnnotation(BeforeClass.class) != null || rmethod.getAnnotation(BeforeTest.class) != null) { if (rmethod.getAnnotation(RunsWithController.class) != null || rmethod.getDeclaringClass().getAnnotation(RunsWithController.class) != null) { LOG.warn("Method or Class of {} asks Controller to be masked", rmethod.getName()); AnnotationsHelper p = SteviaContext.getSpringContext().getBean(AnnotationsHelper.class); try { p.maskExistingController(rmethod); masked = true; } catch (Throwable e) { throw new IllegalStateException("failed to replace controller", e); } } } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (!method.isTestMethod()) return; if (testResult.getThrowable() != null) log.errorf( testResult.getThrowable(), "Method %s threw an exception", getTestDesc(testResult)); }
/** * After invocation. * * @param method the method * @param result the result * @see org.testng.IInvokedMethodListener#afterInvocation(org.testng.IInvokedMethod, * org.testng.ITestResult) */ @Override public final void afterInvocation(final IInvokedMethod method, final ITestResult result) { if (method.isTestMethod()) { if (result.getStatus() == ITestResult.SKIP) { endTestReporting("skipped"); } else if (result.getStatus() == ITestResult.FAILURE) { endTestReporting("failed"); } else if (result.getStatus() == ITestResult.SUCCESS) { endTestReporting("passed"); } } }
/** * Since the methods will be sorted chronologically, we want to return the ITestNGMethod from the * invoked methods. */ private Collection<ITestNGMethod> getMethodSet(IResultMap tests, ISuite suite) { List<IInvokedMethod> r = Lists.newArrayList(); List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods(); // Eliminate the repeat retry methods for (IInvokedMethod im : invokedMethods) { if (tests.getAllMethods().contains(im.getTestMethod())) { int testId = getId(im.getTestResult()); if (!testIds.contains(testId)) { testIds.add(testId); r.add(im); } } } Arrays.sort(r.toArray(new IInvokedMethod[r.size()]), new TestSorter()); List<ITestNGMethod> result = Lists.newArrayList(); // Add all the invoked methods for (IInvokedMethod m : r) { result.add(m.getTestMethod()); } // Add all the methods that weren't invoked (e.g. skipped) that we // haven't added yet // for (ITestNGMethod m : tests.getAllMethods()) { // if (!result.contains(m)) { // result.add(m); // } // } for (ITestResult allResult : tests.getAllResults()) { int testId = getId(allResult); if (!testIds.contains(testId)) { result.add(allResult.getMethod()); } } return result; }
@Override public void afterInvocation(IInvokedMethod method, ITestResult result) { Throwable throwable = result.getThrowable(); if (throwable != null) { TestBase.setFailed(throwable.getMessage()); } super.afterInvocation(method, result); if (method.isTestMethod()) { if (!TestBase.getPassed()) { logBusinessScreenshot("Error Occurred!"); } else { if (TestBaseWebDriver.takePassedScreenshot) { logBusinessScreenshot("Test Passed"); } } } }