/**
   * 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++;
    }
  }
  @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));
  }
  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);
        }
      }
    }
  }
 /**
  * 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");
     }
   }
 }
 @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");
       }
     }
   }
 }