com.gargoylesoftware.htmlunit.html.HtmlFormUtil Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlFormUtil. 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: KubernetesCloudTest.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void defaultWorkspaceVolume() throws Exception {
    KubernetesCloud cloud = new KubernetesCloud("kubernetes");
    j.jenkins.clouds.add(cloud);
    j.jenkins.save();
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage p = wc.goTo("configureClouds/");
    HtmlForm f = p.getFormByName("config");
    HtmlButton buttonExtends = HtmlFormUtil.getButtonByCaption(f, "Pod Templates...");
    buttonExtends.click();
    HtmlButton buttonAdd = HtmlFormUtil.getButtonByCaption(f, "Add Pod Template");
    buttonAdd.click();
    HtmlButton buttonDetails = HtmlFormUtil.getButtonByCaption(f, "Pod Template details...");
    buttonDetails.click();
    DomElement templates = p.getElementByName("templates");
    HtmlInput templateName = getInputByName(templates, "_.name");
    templateName.setValueAttribute("default-workspace-volume");
    j.submit(f);
    cloud = j.jenkins.clouds.get(KubernetesCloud.class);
    PodTemplate podTemplate = cloud.getTemplates().get(0);
    assertEquals("default-workspace-volume", podTemplate.getName());
    assertEquals(WorkspaceVolume.getDefault(), podTemplate.getWorkspaceVolume());
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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")));
}
 
Example #10
Source File: GitHubPRTriggerTest.java    From github-integration-plugin with MIT License 2 votes vote down vote up
@LocalData
@Test
public void buildButtonsPerms() throws Exception {
    j.getInstance().setNumExecutors(0);

    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    ProjectMatrixAuthorizationStrategy auth = new ProjectMatrixAuthorizationStrategy();
    auth.add(Jenkins.READ, "alice");
    auth.add(Computer.BUILD, "alice");

    auth.add(Jenkins.ADMINISTER, "admin");

    auth.add(Jenkins.READ, "bob");
    auth.add(Computer.BUILD, "bob");

    j.jenkins.setAuthorizationStrategy(auth);

    final FreeStyleProject project =  (FreeStyleProject) j.getInstance().getItem("project");

    Map<Permission,Set<String>> perms = new HashMap<>();

    HashSet<String> users = new HashSet<>();
    users.add("alice");
    users.add("bob");

    perms.put(Item.READ, users);

    perms.put(Item.BUILD, Collections.singleton("bob"));

    project.addProperty(new AuthorizationMatrixProperty(perms));


    JenkinsRule.WebClient webClient = j.createWebClient();
    webClient = webClient.login("bob", "bob");

    HtmlPage repoPage = webClient.getPage(project, "github-pullrequest");
    HtmlForm form = repoPage.getFormByName("rebuildAllFailed");
    HtmlFormUtil.getButtonByCaption(form, "Rebuild all failed builds").click();
    HtmlPage page = (HtmlPage) submit(form);

    Queue.Item[] items = j.getInstance().getQueue().getItems();
    assertThat(items, arrayWithSize(0));
}
 
Example #11
Source File: GitHubBranchTriggerTest.java    From github-integration-plugin with MIT License 2 votes vote down vote up
@LocalData
@Test
public void buildButtonsPerms() throws Exception {
    jRule.getInstance().setNumExecutors(0);

    jRule.jenkins.setSecurityRealm(jRule.createDummySecurityRealm());
    ProjectMatrixAuthorizationStrategy auth = new ProjectMatrixAuthorizationStrategy();
    auth.add(Jenkins.READ, "alice");
    auth.add(Computer.BUILD, "alice");

    auth.add(Jenkins.ADMINISTER, "admin");

    auth.add(Jenkins.READ, "bob");
    auth.add(Computer.BUILD, "bob");

    jRule.jenkins.setAuthorizationStrategy(auth);

    final FreeStyleProject project = (FreeStyleProject) jRule.getInstance().getItem("project");

    Map<Permission, Set<String>> perms = new HashMap<>();

    HashSet<String> users = new HashSet<>();
    users.add("alice");
    users.add("bob");

    perms.put(Item.READ, users);

    perms.put(Item.BUILD, Collections.singleton("bob"));

    project.addProperty(new AuthorizationMatrixProperty(perms));


    JenkinsRule.WebClient webClient = jRule.createWebClient();
    webClient = webClient.login("bob", "bob");

    HtmlPage repoPage = webClient.getPage(project, "github-branch");
    HtmlForm form = repoPage.getFormByName("rebuildAllFailed");
    HtmlFormUtil.getButtonByCaption(form, "Rebuild all failed builds").click();
    HtmlPage page = (HtmlPage) submit(form);

    Queue.Item[] items = jRule.getInstance().getQueue().getItems();
    assertThat(items, arrayWithSize(0));

}