Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlFormUtil#submit()

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlFormUtil#submit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiIntegrationTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReplaceCloudForNodesAfterConfigurationSave() throws Exception {
    EC2FleetCloud cloud = new EC2FleetCloud(null, null, null, null, null, null, null,
            null, null, null, false, false,
            0, 0, 0, 0, false, false,
            false, 0, 0, false,
            10, false);
    j.jenkins.clouds.add(cloud);

    j.jenkins.addNode(new EC2FleetNode("mock", "", "", 1,
            Node.Mode.EXCLUSIVE, "", new ArrayList<NodeProperty<?>>(), cloud,
            j.createComputerLauncher(null)));

    HtmlPage page = j.createWebClient().goTo("configure");
    HtmlForm form = page.getFormByName("config");

    ((HtmlTextInput) getElementsByNameWithoutJdk(page, "_.name").get(0)).setText("a");

    HtmlFormUtil.submit(form);

    final Cloud newCloud = j.jenkins.clouds.get(0);
    assertNotSame(cloud, newCloud);

    assertSame(newCloud, ((EC2FleetNode) j.jenkins.getNode("mock")).getCloud());
}
 
Example 2
Source File: UiIntegrationTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUpdateProperCloudWhenMultiple() throws IOException, SAXException {
    EC2FleetCloud cloud1 = new EC2FleetCloud(null, null, null, null, null, null,
            null, null, null, null, false, false,
            0, 0, 0, 0, false, false,
            false, 0, 0, false,
            10, false);
    j.jenkins.clouds.add(cloud1);

    EC2FleetCloud cloud2 = new EC2FleetCloud(null, null, null, null, null, null,
            null, null, null, null, false, false,
            0, 0, 0, 0, false, false,
            false, 0, 0, false,
            10, false);
    j.jenkins.clouds.add(cloud2);

    HtmlPage page = j.createWebClient().goTo("configure");
    HtmlForm form = page.getFormByName("config");

    ((HtmlTextInput) getElementsByNameWithoutJdk(page, "_.name").get(0)).setText("a");

    HtmlFormUtil.submit(form);

    assertEquals("a", j.jenkins.clouds.get(0).name);
    assertEquals("FleetCloud", j.jenkins.clouds.get(1).name);
}
 
Example 3
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Submit the supplied {@link HtmlForm}. Locates the submit element/button on the form.
 *
 * @param form
 *         the {@link HtmlForm}
 */
protected void submit(final HtmlForm form) {
    try {
        HtmlFormUtil.submit(form);
    }
    catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example 4
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Submits the form by clicking the submit button of the given name.
 *
 * @param name
 *      This corresponds to the @name of {@code <f:submit />}
 */
public HtmlPage submit(HtmlForm form, String name) throws Exception {
    for( HtmlElement e : form.getElementsByTagName("button")) {
        HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();                        
        if (p.getAttribute("name").equals(name) && HtmlElementUtil.hasClassName(p, "yui-submit-button")) {
            // For YUI handled submit buttons, just do a click.
            return (HtmlPage) HtmlElementUtil.click(e);
        } else if (e.getAttribute("name").equals(name)) {
            return (HtmlPage) HtmlFormUtil.submit(form, e);
        }
    }
    throw new AssertionError("No such submit button with the name "+name);
}
 
Example 5
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Submits the form by clicking the submit button of the given name.
 *
 * @param name
 *      This corresponds to the @name of {@code <f:submit />}
 */
public HtmlPage submit(HtmlForm form, String name) throws Exception {
    for( HtmlElement e : form.getElementsByTagName("button")) {
        HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();
        if (e instanceof HtmlButton && p.getAttribute("name").equals(name)) {
            return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e);
        }
    }
    throw new AssertionError("No such submit button with the name "+name);
}
 
Example 6
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Logs in to Jenkins.
 */
public WebClient login(String username, String password) throws Exception {
    HtmlPage page = goTo("/login");

    HtmlForm form = page.getFormByName("login");
    form.getInputByName("j_username").setValueAttribute(username);
    form.getInputByName("j_password").setValueAttribute(password);
    HtmlFormUtil.submit(form, null);
    return this;
}
 
Example 7
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 2 votes vote down vote up
/**
 * Submits the form.
 *
 * Plain {@link HtmlForm#submit(com.gargoylesoftware.htmlunit.html.SubmittableElement)} doesn't work correctly due to the use of YUI in Hudson.
 */
public HtmlPage submit(HtmlForm form) throws Exception {
    return (HtmlPage) HtmlFormUtil.submit(form);
}
 
Example 8
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 2 votes vote down vote up
/**
 * Submits the form.
 *
 * Plain {@link HtmlForm#submit(com.gargoylesoftware.htmlunit.html.SubmittableElement)} doesn't work correctly due to the use of YUI in Hudson.
 */
public HtmlPage submit(HtmlForm form) throws Exception {
    return (HtmlPage) HtmlFormUtil.submit(form, last(form.getElementsByTagName("button")));
}