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
  /**
   * Type a value in the select2 and then simulate the enter key.
   *
   * @since 6.0
   */
  public SearchPage typeValueAndTypeEnter(String value) {
    clickSelect2Field();

    WebElement suggestInput = getSuggestInput();

    suggestInput.sendKeys(value);
    try {
      waitSelect2();
    } catch (TimeoutException e) {
      log.warn("Suggestion timed out with input : " + value + ". Let's try with next letter.");
    }
    suggestInput.sendKeys(Keys.RETURN);

    return AbstractTest.asPage(SearchPage.class);
  }
Exemplo n.º 3
0
  /**
   * Type a value in the select2 and return the suggested entries.
   *
   * @param value The value to type in the select2.
   * @return The suggested values for the parameter.
   * @since 6.0
   */
  public List<WebElement> typeAndGetResult(final String value) {

    clickSelect2Field();

    WebElement suggestInput = getSuggestInput();

    suggestInput.sendKeys(value);
    try {
      waitSelect2();
    } catch (TimeoutException e) {
      log.warn("Suggestion timed out with input : " + value + ". Let's try with next letter.");
    }

    return getSuggestedEntries();
  }