Package com.gargoylesoftware.htmlunit.html

Examples of com.gargoylesoftware.htmlunit.html.HtmlForm


    return fHtmlId;
  }

  public void doExecute() throws IOException {
    if (getName() != null) {
      final HtmlForm form = findForm();
      if (form == null) {
        throw new StepFailedException("No suitable form found having field named \"" + getName() + "\"", this);
      }
      verifyField(AbstractSetFieldStep.selectField(findFields(form), getFieldIndex(), this));
    }
View Full Code Here


   * @return the exception
   */
  private StepFailedException buildNoButtonFoundException() {
    final StepFailedException e = new StepFailedException("No button found", this);

    final HtmlForm currentForm = getContext().getCurrentForm();
    final StringBuffer msg = new StringBuffer();
    if (currentForm != null) {
      msg.append("In current form:\n");
      msg.append(getButtonsDescription(currentForm));
    }

    final Iterator formsIterator = getContext().getCurrentHtmlResponse(this).getForms().iterator();
    while (formsIterator.hasNext()) {
      final HtmlForm form = (HtmlForm) formsIterator.next();
      if (form != currentForm)
      {
        if (msg.length() != 0)
          msg.append("\n\n");
        msg.append("In " + form + ":\n");
View Full Code Here

    {

        Iterator forms = page.getForms().iterator();
        while (forms.hasNext())
        {
            HtmlForm form = (HtmlForm) forms.next();
            if (id.equals(form.getAttributeValue("id")))
            {
                return (form);
            }
        }
        return (null);
View Full Code Here

    {

        Iterator forms = page.getForms().iterator();
        while (forms.hasNext())
        {
            HtmlForm form = (HtmlForm) forms.next();
            if (id.equals(form.getAttributeValue("id")))
            {
                return (form);
            }
        }
        return (null);
View Full Code Here

    @Test
    public void testIconUrlLoading() throws Exception {
        WebClient wc = startWebClient();
        HtmlPage page = goToModifyPage(wc);

        HtmlForm form = page.getHtmlElementById("modifyCardForm");
        assertTrue(form.getInputByName("iconUrl").getValueAttribute().contains("google"));
        assertTrue(getDisplayedCardIconSrc(page).contains("google"));

        form.getInputByName("url").type("foo");
        form.getInputByName("url").blur();
        assertEquals("", form.getInputByName("iconUrl").getValueAttribute());
        assertEquals("/img/card.png", getDisplayedCardIconSrc(page));

        ((HtmlTextInput) form.getInputByName("url")).select();
        form.getInputByName("url").type("http://www.google.com");
        form.getInputByName("url").blur();
        assertTrue(form.getInputByName("iconUrl").getValueAttribute().contains("google"));
        assertTrue(getDisplayedCardIconSrc(page).contains("google"));

        ((HtmlTextInput) form.getInputByName("url")).select();
        form.getInputByName("url").type("http://www.googlesjdkfhksjdfhksjdhfkjh.com");
        form.getInputByName("url").blur();
        assertEquals("/img/card.png", getDisplayedCardIconSrc(page));
        testErrorExists(page, "An error occurred while getting the icon of the web site. The default icon will be used.");
    }
View Full Code Here

    @Test
    public void testCancel() throws Exception {
        WebClient wc = startWebClient();
        HtmlPage page = goToModifyPage(wc);

        HtmlForm form = page.getHtmlElementById("modifyCardForm");
        form.getInputByName("name").setValueAttribute("");
        form.getInputByValue("Cancel").click();
        testElementNotPresent(page, "modifyCardForm");
        WebAssert.assertTextPresent(page, "Create a new card");
        assertEquals(3, page.getHtmlElementById("cards")
                            .getElementsByAttribute("div", "class", "card").size());
    }
View Full Code Here

    private void testCancel(boolean withJavascript) throws Exception {
        WebClient wc = startWebClient(false);
        wc.setJavaScriptEnabled(withJavascript);
        HtmlPage page = goToChangePreferredLocalePage(wc);
        HtmlForm form = page.getHtmlElementById("changePreferredLocaleForm");
        page = form.getInputByValue("Cancel").click();
        wc.waitForBackgroundJavaScript(10000L);
        WebAssert.assertElementNotPresent(page, "changePreferredLocaleForm");
        testTitle(page, "Preferences");
    }
View Full Code Here

    @Test
    public void testFormSubmission() throws Exception {
        WebClient wc = startWebClient();
        HtmlPage page = goToModifyPage(wc);

        HtmlForm form = page.getHtmlElementById("modifyCardForm");
        form.getInputByName("name").setValueAttribute("card4");
        form.getInputByName("login").setValueAttribute("login4");
        form.getInputByName("password").setValueAttribute("password4");
        form.getInputByValue("Modify card").click();

        testMessageExists(page, "The card \"card4\" has been modified.");
        HtmlDivision cardsDiv = page.getHtmlElementById("cards");
        List<HtmlDivision> cardDivs = cardsDiv.getElementsByAttribute("div", "class", "card");
        assertEquals(3, cardDivs.size());
View Full Code Here

    public void testFormSubmission(boolean withJavascript) throws Exception {
        WebClient wc = startWebClient(false);
        wc.setJavaScriptEnabled(withJavascript);
        HtmlPage page = goToChangePreferredLocalePage(wc);
        HtmlForm form = page.getHtmlElementById("changePreferredLocaleForm");
        assertEquals("None (automatic detection)", form.getSelectByName("locale").asText());
        form.getSelectByName("locale").setSelectedAttribute("fr", true);
        page = form.getInputByValue("Choose").click();
        wc.waitForBackgroundJavaScript(10000L);
        testTitle(page, "Pr\u00e9f\u00e9rences");
        testMessageExists(page, "La langue pr\u00e9f\u00e9r\u00e9e a \u00e9t\u00e9 modifi\u00e9e.");
        WebAssert.assertElementNotPresent(page, "changePreferredLocaleForm");

        page = page.getAnchorByText("Choisir votre langue pr\u00e9f\u00e9r\u00e9e").click();
        wc.waitForBackgroundJavaScript(10000L);
        form = page.getHtmlElementById("changePreferredLocaleForm");
        assertEquals("fran\u00e7ais", form.getSelectByName("locale").asText());
        form.getSelectByName("locale").setSelectedAttribute("", true);
        page = form.getInputByValue("Choisir").click();
        wc.waitForBackgroundJavaScript(10000L);
        testTitle(page, "Preferences");
        testMessageExists(page, "The preferred language has been changed.");
    }
View Full Code Here

    public void testValidationWithoutJavascript() throws Exception {
        WebClient wc = startWebClient();
        wc.setJavaScriptEnabled(false);
        HtmlPage page = goToModifyPage(wc);

        HtmlForm form = page.getHtmlElementById("modifyCardForm");
        form.getInputByName("name").setValueAttribute("");
        page = form.getInputByValue("Modify card").click();
        testTitle(page, "Modify a card");
        HtmlDivision cardsDiv = page.getHtmlElementById("cards");
        List<HtmlDivision> cardDivs = cardsDiv.getElementsByAttribute("div", "class", "card");
        assertEquals(3, cardDivs.size());

        // test that an error is triggered when checking the change password checkbox is checked and
        // the password is empty
        form = page.getHtmlElementById("modifyCardForm");
        form.getInputByName("changePassword").setChecked(true);
        form.getInputByName("password").setValueAttribute("");
        page = form.getInputByValue("Modify card").click();
        testTitle(page, "Modify a card");
        testErrorExists(page, "Password is a required field");

        // test that no error is triggered when not checking the change password checkbox
        // and the password is empty
        form = page.getHtmlElementById("modifyCardForm");
        form.getInputByName("changePassword").setChecked(false);
        form.getInputByName("password").setValueAttribute("");
        page = form.getInputByValue("Modify card").click();
        testTitle(page, "Modify a card");
        assertFalse(page.getHtmlElementById("messages").asXml().contains("Password is a required field"));


    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.html.HtmlForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.