Exemplo n.º 1
0
  /**
   * Select given value, waiting for JSF ajax requests or not, and typing the whole suggestion or
   * not (use false speed up selection when exactly one suggestion is found, use true when creating
   * new suggestions).
   *
   * @param value string typed in the suggest box
   * @param wait4A4J use true if request is triggering JSF ajax calls
   * @param typeAll use false speed up selection when exactly one suggestion is found, use true when
   *     creating new suggestions.
   * @since 7.10
   */
  public void selectValue(final String value, final boolean wait4A4J, final boolean typeAll) {
    clickSelect2Field();

    WebElement suggestInput = getSuggestInput();

    int nbSuggested = Integer.MAX_VALUE;
    char c;
    for (int i = 0; i < value.length(); i++) {
      c = value.charAt(i);
      suggestInput.sendKeys(c + "");
      waitSelect2();
      if (i >= 2) {
        if (getSuggestedEntries().size() > nbSuggested) {
          throw new IllegalArgumentException(
              "More suggestions than expected for " + element.getAttribute("id"));
        }
        nbSuggested = getSuggestedEntries().size();
        if (!typeAll && nbSuggested == 1) {
          break;
        }
      }
    }

    waitSelect2();

    List<WebElement> suggestions = getSuggestedEntries();
    if (suggestions == null || suggestions.isEmpty()) {
      log.warn("Suggestion for element " + element.getAttribute("id") + " returned no result.");
      return;
    }
    WebElement suggestion = suggestions.get(0);
    if (suggestions.size() > 1) {
      log.warn(
          "Suggestion for element "
              + element.getAttribute("id")
              + " returned more than 1 result, the first suggestion will be selected : "
              + suggestion.getText());
    }

    AjaxRequestManager arm = new AjaxRequestManager(driver);
    if (wait4A4J) {
      arm.watchAjaxRequests();
    }
    try {
      suggestion.click();
    } catch (StaleElementReferenceException e) {
      suggestion = driver.findElement(By.xpath(S2_SUGGEST_RESULT_XPATH));
      suggestion.click();
    }
    if (wait4A4J) {
      arm.waitForAjaxRequests();
    }
  }
Exemplo n.º 2
0
  /** Removes all documents visible on current page. */
  public TrashSubPage purgeAllDocuments() {
    TrashSubPage page = asPage(TrashSubPage.class);
    By locator = By.id(SELECT_ALL_BUTTON_ID);
    if (!hasElement(locator)) {
      // no documents to remove
      return page;
    }
    AjaxRequestManager arm = new AjaxRequestManager(driver);
    arm.begin();
    findElementWaitUntilEnabledAndClick(By.id(SELECT_ALL_BUTTON_ID));
    arm.end();

    deleteSelectedDocuments();

    return asPage(TrashSubPage.class);
  }