Search in sources :

Example 11 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project testcases by coheigea.

the class OIDCTest method login.

private static HtmlPage login(String url, WebClient webClient) throws IOException {
    webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage idpPage = webClient.getPage(url);
    webClient.getOptions().setJavaScriptEnabled(true);
    Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
    // Test the SAML Version here
    DomNodeList<DomElement> results = idpPage.getElementsByTagName("input");
    String wresult = null;
    for (DomElement result : results) {
        if ("wresult".equals(result.getAttributeNS(null, "name"))) {
            wresult = result.getAttributeNS(null, "value");
            break;
        }
    }
    Assert.assertTrue(wresult != null && wresult.contains("urn:oasis:names:tc:SAML:2.0:cm:bearer"));
    final HtmlForm form = idpPage.getFormByName("signinresponseform");
    final HtmlSubmitInput button = form.getInputByName("_eventId_submit");
    return button.click();
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)

Example 12 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project testcases by coheigea.

the class FederationTest method login.

private static String login(String url, String user, String password, String idpPort) throws IOException {
    final WebClient webClient = new WebClient();
    webClient.getOptions().setUseInsecureSSL(true);
    webClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", Integer.parseInt(idpPort)), new UsernamePasswordCredentials(user, password));
    webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage idpPage = webClient.getPage(url);
    webClient.getOptions().setJavaScriptEnabled(true);
    Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
    final HtmlForm form = idpPage.getFormByName("signinresponseform");
    final HtmlSubmitInput button = form.getInputByName("_eventId_submit");
    final XmlPage rpPage = button.click();
    return rpPage.asXml();
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) AuthScope(org.apache.http.auth.AuthScope) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 13 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project workflow-cps-plugin by jenkinsci.

the class ReplayActionTest method rebuild.

@Issue("JENKINS-47339")
@Test
public void rebuild() throws Exception {
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            story.j.jenkins.setSecurityRealm(story.j.createDummySecurityRealm());
            GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
            gmas.add(Jenkins.READ, "dev3");
            gmas.add(Item.BUILD, "dev3");
            gmas.add(Item.READ, "dev3");
            story.j.jenkins.setAuthorizationStrategy(gmas);
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition("echo 'script to rebuild'", true));
            WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
            story.j.assertLogContains("script to rebuild", b1);
            WorkflowRun b2;
            {
                // First time around, verify that UI elements are present and functional.
                ReplayAction a = b1.getAction(ReplayAction.class);
                assertNotNull(a);
                assertFalse(canReplay(b1, "dev3"));
                assertTrue(canRebuild(b1, "dev3"));
                JenkinsRule.WebClient wc = story.j.createWebClient();
                wc.login("dev3");
                HtmlPage page = wc.getPage(b1, a.getUrlName());
                WebAssert.assertFormNotPresent(page, "config");
                HtmlForm form = page.getFormByName("rebuild");
                HtmlPage redirect = story.j.submit(form);
                assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString());
                story.j.waitUntilNoActivity();
                b2 = p.getBuildByNumber(2);
                assertNotNull(b2);
            }
            story.j.assertLogContains("script to rebuild", story.j.assertBuildStatusSuccess(b2));
            ReplayCause cause = b2.getCause(ReplayCause.class);
            assertNotNull(cause);
            assertEquals(1, cause.getOriginalNumber());
            assertEquals(b1, cause.getOriginal());
            assertEquals(b2, cause.getRun());
        }
    });
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Statement(org.junit.runners.model.Statement) RestartableJenkinsRule(org.jvnet.hudson.test.RestartableJenkinsRule) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 14 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project workflow-cps-plugin by jenkinsci.

the class ReplayActionTest method editSimpleDefinition.

@Test
public void editSimpleDefinition() throws Exception {
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition("echo 'first script'", false));
            // Start off with a simple run of the first script.
            WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
            story.j.assertLogContains("first script", b1);
            // Now will replay with a second script.
            WorkflowRun b2;
            {
                // First time around, verify that UI elements are present and functional.
                ReplayAction a = b1.getAction(ReplayAction.class);
                assertNotNull(a);
                assertTrue(a.isEnabled());
                HtmlPage page = story.j.createWebClient().getPage(b1, a.getUrlName());
                HtmlForm form = page.getFormByName("config");
                HtmlTextArea text = form.getTextAreaByName("_.mainScript");
                assertEquals("echo 'first script'", text.getText());
                text.setText("echo 'second script'");
                // TODO loaded scripts
                HtmlPage redirect = story.j.submit(form);
                assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString());
                story.j.waitUntilNoActivity();
                b2 = p.getBuildByNumber(2);
                assertNotNull(b2);
            }
            // Subsequently can use the faster whitebox method.
            story.j.assertLogContains("second script", story.j.assertBuildStatusSuccess(b2));
            ReplayCause cause = b2.getCause(ReplayCause.class);
            assertNotNull(cause);
            assertEquals(1, cause.getOriginalNumber());
            assertEquals(b1, cause.getOriginal());
            assertEquals(b2, cause.getRun());
            // Replay #2 as #3. Note that the diff is going to be from #1 → #3, not #2 → #3.
            WorkflowRun b3 = (WorkflowRun) b2.getAction(ReplayAction.class).run("echo 'third script'", Collections.<String, String>emptyMap()).get();
            story.j.assertLogContains("third script", story.j.assertBuildStatusSuccess(b3));
            String diff = b3.getAction(ReplayAction.class).getDiff();
            assertThat(diff, containsString("-echo 'first script'"));
            assertThat(diff, containsString("+echo 'third script'"));
            System.out.println(diff);
            // Make a persistent edit to the script and run, just to make sure there is no lingering effect.
            p.setDefinition(new CpsFlowDefinition("echo 'fourth script'", false));
            story.j.assertLogContains("fourth script", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
        }
    });
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Statement(org.junit.runners.model.Statement) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) HtmlTextArea(com.gargoylesoftware.htmlunit.html.HtmlTextArea) Test(org.junit.Test)

Example 15 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project workflow-job-plugin by jenkinsci.

the class WorkflowJobTest method disabled.

@Issue("JENKINS-27299")
@Test
public void disabled() throws Exception {
    WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
    assertFalse(p.isDisabled());
    assertTrue(p.isBuildable());
    JenkinsRule.WebClient wc = j.createWebClient();
    j.submit(wc.getPage(p).<HtmlForm>getHtmlElementById("disable-project"));
    assertTrue(p.isDisabled());
    assertFalse(p.isBuildable());
    HtmlForm form = wc.getPage(p, "configure").getFormByName("config");
    HtmlCheckBoxInput checkbox = form.getInputByName("disable");
    assertTrue(checkbox.isChecked());
    checkbox.setChecked(false);
    j.submit(form);
    assertFalse(p.isDisabled());
    wc.getPage(new WebRequest(wc.createCrumbedUrl(p.getUrl() + "disable"), HttpMethod.POST));
    assertTrue(p.isDisabled());
    assertNull(p.scheduleBuild2(0));
    assertThat(new CLICommandInvoker(j, "enable-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
    assertFalse(p.isDisabled());
}
Also used : HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) CLICommandInvoker(hudson.cli.CLICommandInvoker) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)21 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)20 Test (org.junit.Test)14 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)7 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)5 WebClient (com.gargoylesoftware.htmlunit.WebClient)4 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)4 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)4 Page (com.gargoylesoftware.htmlunit.Page)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 Descriptor (hudson.model.Descriptor)3 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)3 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)3 Issue (org.jvnet.hudson.test.Issue)3 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)2 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)2 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)2