コード例 #1
0
 /** Initialize the object. */
 public void initialize() {
   final HtmlSelect htmlSelect = getHtmlSelect();
   htmlSelect.setScriptObject(this);
   if (optionsArray_ == null) {
     optionsArray_ = new HTMLOptionsCollection(this);
     optionsArray_.initialize(htmlSelect);
   }
 }
コード例 #2
0
 private void ensureSelectedIndex() {
   final HtmlSelect select = getHtmlSelect();
   if (select.getOptionSize() == 0) {
     jsxSet_selectedIndex(-1);
   } else if (jsxGet_selectedIndex() == -1) {
     jsxSet_selectedIndex(0);
   }
 }
コード例 #3
0
 /**
  * Returns the actual value of the selected Option.
  *
  * @return the value
  */
 @Override
 public String jsxGet_value() {
   final HtmlSelect htmlSelect = getHtmlSelect();
   final List<HtmlOption> selectedOptions = htmlSelect.getSelectedOptions();
   if (selectedOptions.isEmpty()) {
     return "";
   }
   return ((HTMLOptionElement) selectedOptions.get(0).getScriptObject()).jsxGet_value();
 }
コード例 #4
0
 /**
  * Returns the value of the "selectedIndex" property.
  *
  * @return the selectedIndex property
  */
 public int jsxGet_selectedIndex() {
   final HtmlSelect htmlSelect = getHtmlSelect();
   final List<HtmlOption> selectedOptions = htmlSelect.getSelectedOptions();
   if (selectedOptions.isEmpty()) {
     return -1;
   }
   final List<HtmlOption> allOptions = htmlSelect.getOptions();
   return allOptions.indexOf(selectedOptions.get(0));
 }
コード例 #5
0
 public void testDescriptionsListHiddenAfterClearCondition() throws Exception {
   HtmlSelect select =
       getHtmlPage().getElementByName("ox_OpenXavaTest_Delivery__conditionValue___3");
   String s = select.getAttribute("style");
   assertFalse(s.contains("display: none") || s.contains("display:none"));
   clearCondition("ox_OpenXavaTest_Delivery__xava_clear_condition");
   select = getHtmlPage().getElementByName("ox_OpenXavaTest_Delivery__conditionValue___3");
   s = select.getAttribute("style");
   assertFalse(s.contains("display: none") || s.contains("display:none"));
 }
コード例 #6
0
 /** Verify that the conversion error works for SelectMany */
 public void testSelectManyMismatchValue() throws Exception {
   HtmlPage page = getPage("/faces/jsp/selectManyMismatchValue.jsp");
   List list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class);
   HtmlSubmitInput button = (HtmlSubmitInput) list.get(0);
   list = getAllElementsOfGivenClass(page, null, HtmlSelect.class);
   HtmlSelect options = (HtmlSelect) list.get(0);
   String chosen[] = {"one", "three"};
   options.fakeSelectedAttribute(chosen);
   page = (HtmlPage) button.click();
   assertTrue(-1 != page.asText().indexOf("one three"));
   assertTrue(-1 != page.asText().indexOf("#{test3.selection}"));
 }
コード例 #7
0
  public void testHideNoSelectionOptionIsAValueExpression() throws Exception {
    HtmlSelect select = (HtmlSelect) this.page.getElementById("f:selectItemNoSelectedValue");
    // validate initial page
    assertEquals(4, select.getOptionSize());

    HtmlInput button = (HtmlInput) this.page.getElementById("f:command");
    select.getOptionByValue("Pippin").click();
    this.page = button.click();

    select = (HtmlSelect) this.page.getElementById("f:selectItemNoSelectedValue");
    assertEquals(5, select.getOptionSize());
  }
コード例 #8
0
  public void testSelectManyTypeInts() throws Exception {
    HtmlPage page = getPage("/faces/jsp/selectManyTypeInts.jsp");
    List list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class);
    HtmlSubmitInput button = (HtmlSubmitInput) list.get(0);
    list = getAllElementsOfGivenClass(page, null, HtmlSelect.class);
    HtmlSelect options = (HtmlSelect) list.get(0);

    String chosen[] = {"2", "3"};
    options.fakeSelectedAttribute(chosen);
    page = (HtmlPage) button.click();
    ResourceBundle messages = ResourceBundle.getBundle("javax.faces.Messages");
    String message = messages.getString("javax.faces.component.UISelectMany.INVALID");
    // it does not have a validation message
    assertTrue(-1 == page.asText().indexOf("Validation Error"));
  }
コード例 #9
0
  /**
   * Adds a new item to the list (optionally) at the specified index in IE way.
   *
   * @param newOptionObject the DomNode to insert
   * @param index (optional) the index where the node should be inserted
   */
  protected void add_IE(final HTMLOptionElement newOptionObject, final Object index) {
    final HtmlSelect select = getHtmlSelect();
    final HtmlOption beforeOption;
    if (Context.getUndefinedValue().equals(index)) {
      beforeOption = null;
    } else {
      final int intIndex = ((Integer) Context.jsToJava(index, Integer.class)).intValue();
      if (intIndex >= select.getOptionSize()) {
        beforeOption = null;
      } else {
        beforeOption = select.getOption(intIndex);
      }
    }

    addBefore(newOptionObject, beforeOption);
  }
コード例 #10
0
 @Test
 public void errorDropdownIsPresentAndIsNotEmpty() throws Exception {
   JenkinsRule.WebClient wc = j.createWebClient();
   wc.login("user1", "user1");
   HtmlPage page = wc.goTo("job/x/" + build.getNumber());
   page.getElementById("claim").click();
   HtmlForm form = page.getFormByName("claim");
   HtmlSelect select = form.getSelectByName("_.errors");
   HashSet<String> set = new HashSet<String>();
   for (HtmlOption option : select.getOptions()) {
     set.add(option.getValueAttribute());
   }
   assertTrue(set.contains("Default"));
   assertTrue(set.contains(CAUSE_NAME_2));
   assertTrue(set.contains(CAUSE_NAME_1));
 }
コード例 #11
0
  /**
   * Adds the option (and create the associated DOM node if needed) before the specified one or at
   * the end if the specified one in null.
   *
   * @param newOptionObject the new option to add
   * @param beforeOption the option that should be after the option to add
   */
  protected void addBefore(final HTMLOptionElement newOptionObject, final HtmlOption beforeOption) {
    final HtmlSelect select = getHtmlSelect();

    HtmlOption htmlOption = newOptionObject.getDomNodeOrNull();
    if (htmlOption == null) {
      htmlOption =
          (HtmlOption)
              HTMLParser.getFactory(HtmlOption.TAG_NAME)
                  .createElement(select.getPage(), HtmlOption.TAG_NAME, null);
    }

    if (beforeOption == null) {
      select.appendChild(htmlOption);
    } else {
      beforeOption.insertBefore(htmlOption);
    }
  }
コード例 #12
0
  private ClaimBuildAction applyClaimWithFailureCauseSelected(
      String element, String error, String reason, String description) throws Exception {
    HtmlPage page = whenNavigatingtoClaimPage();
    page.getElementById(element).click();
    HtmlForm form = page.getFormByName("claim");
    form.getTextAreaByName("reason").setText(reason);
    HtmlSelect select = form.getSelectByName("_.errors");
    HtmlOption option = select.getOptionByValue(error);
    select.setSelectedAttribute(option, true);

    assertEquals(description, form.getTextAreaByName("errordesc").getTextContent());

    form.submit((HtmlButton) j.last(form.getHtmlElementsByTagName("button")));

    ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
    return action;
  }
コード例 #13
0
ファイル: HtmlUnitUtil.java プロジェクト: 1eksus/migool
 public static List<String> getOptionTexts(final HtmlSelect select) {
   final List<HtmlOption> options = select.getOptions();
   final List<String> ret = new ArrayList<String>(options.size());
   for (final HtmlOption option : options) {
     ret.add(option.getText());
   }
   return ret;
 }
コード例 #14
0
ファイル: HtmlUnitUtil.java プロジェクト: 1eksus/migool
 /**
  * @param select
  * @param text
  * @return
  */
 public static HtmlOption getOptionByTextValue(final HtmlSelect select, final String text) {
   final List<HtmlOption> options = select.getOptions();
   for (final HtmlOption option : options) {
     if (text.equalsIgnoreCase(option.getText())) {
       return option;
     }
   }
   return null;
 }
コード例 #15
0
  /**
   * On SelectMany, test that the membership test works and doesn't produce spurious
   * ValueChangeEvent instances.
   */
  public void testSelectManyInvalidValue() throws Exception {
    HtmlPage page = getPage("/faces/jsp/selectManyInvalidValue.jsp");
    List list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class);
    HtmlSubmitInput button = (HtmlSubmitInput) list.get(0);
    list = getAllElementsOfGivenClass(page, null, HtmlSelect.class);
    HtmlSelect options = (HtmlSelect) list.get(0);
    Random random = new Random(4143);
    String str = new String((new Float(random.nextFloat())).toString());

    String chosen[] = {
      (new Float(random.nextFloat())).toString(), (new Float(random.nextFloat())).toString()
    };
    options.fakeSelectedAttribute(chosen);
    page = (HtmlPage) button.click();
    ResourceBundle messages = ResourceBundle.getBundle("javax.faces.Messages");
    String message = messages.getString("javax.faces.component.UISelectMany.INVALID");
    // it does have a validation message
    assertTrue(-1 != page.asText().indexOf("Validation Error"));
    // it does not have a value change message
    assertTrue(-1 == page.asText().indexOf("value changed"));
  }
コード例 #16
0
  /**
   * Sets the value of the "selectedIndex" property.
   *
   * @param index the new value
   */
  public void jsxSet_selectedIndex(final int index) {
    final HtmlSelect htmlSelect = getHtmlSelect();

    if (index != 0
        && getBrowserVersion()
            .hasFeature(BrowserVersionFeatures.JS_SELECT_SELECTED_INDEX_THROWS_IF_BAD)
        && (index < -1 || index >= htmlSelect.getOptionSize())) {
      throw Context.reportRuntimeError("Invalid index for select node: " + index);
    }

    for (final HtmlOption itemToUnSelect : htmlSelect.getSelectedOptions()) {
      htmlSelect.setSelectedAttribute(itemToUnSelect, false);
    }
    if (index < 0) {
      return;
    }

    final List<HtmlOption> allOptions = htmlSelect.getOptions();

    if (index < allOptions.size()) {
      final HtmlOption itemToSelect = allOptions.get(index);
      htmlSelect.setSelectedAttribute(itemToSelect, true, false);
    }
  }
コード例 #17
0
 /**
  * Selects the select's option value based on the year value given
  *
  * @param year the new year value to set
  * @return {@link AlbumPage}
  */
 public AlbumPage changeAlbumYear(int year) {
   HtmlSelect albumYearSelectOption = (HtmlSelect) page.getElementById("albumYear");
   HtmlOption yearOption = albumYearSelectOption.getOptionByValue(Integer.toString(year));
   albumYearSelectOption.setSelectedAttribute(yearOption, true);
   return this;
 }