Exemplo n.º 1
0
 private void handleUserInteractionFailure(
     SeleniumHolder seleniumHolder, UserInteraction userInteraction, UserInteractionException e) {
   String msg = "Error invoking user interaction: " + userInteraction.toString() + ".";
   if (userInteraction.getElement() instanceof PageElement) {
     PageElement pe = (PageElement) userInteraction.getElement();
     if (pe.getStatus().equals(TestPartStatus.FAIL)) {
       msg += "\n\nPage element " + pe.toString() + " not found.";
     }
     seleniumHolder.addResultByIsNot(pe, TestPartStatus.EXCEPTION, pe.isNot());
   }
   Logger.error(msg, e);
   throw new UserInteractionException(msg);
 }
Exemplo n.º 2
0
  /**
   * Converts a user interactions transition to a list of Selenium commands.
   *
   * @param transition The transition to convert.
   */
  public void handleUserInteractions(
      SeleniumHolder seleniumHolder, UserInteractionsTransition transition) {

    for (UserInteraction userInteraction : transition.getUserInteractions()) {
      IActionElement actionElement = userInteraction.getElement();

      if (actionElement == null) {
        Logger.warn("Action element was null. Skipping user interaction: " + userInteraction);
        continue;
      }

      int waitMillis = seleniumHolder.getNextPageElementTimeout() * 1000;
      int waitIntervalMillis = 100;
      int i = 0;
      while (true) {
        try {
          handleUserInteraction(seleniumHolder, userInteraction);
          break;
        } catch (UserInteractionException e) {
          if (i > waitMillis) {
            handleUserInteractionFailure(seleniumHolder, userInteraction, e);
          }
          try {
            Thread.sleep(waitIntervalMillis);
            i += waitIntervalMillis;
            Logger.warn(
                "Retrying user interaction: "
                    + userInteraction.toString()
                    + " after error: "
                    + ErrorHandler.getCause(e).toString());
          } catch (InterruptedException e2) {
            throw new ExporterException(e2.toString() + " came after " + e.toString(), e);
          }
        }
      }

      // increment the number of steps in test:
      seleniumHolder.addResult(null, TestPartStatus.PASS);
    }

    if (transition.hasCustomTimeout()) {
      seleniumHolder.setNextPageElementTimeout(transition.getSecondsToWaitForResult());
    }
  }