Search in sources :

Example 81 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage 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 82 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project microservices by pwillhan.

the class UserVehicleControllerHtmlUnitTest method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("donald")).willReturn(new VehicleDetails("Honda", "Civic"));
    HtmlPage page = this.webClient.getPage("/donald/vehicle.html");
    assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) VehicleDetails(demo.service.VehicleDetails) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 83 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project core by weld.

the class JsfTest method testELWithParameters.

@Test
public void testELWithParameters(@ArquillianResource URL baseURL) throws Exception {
    WebClient client = new WebClient();
    HtmlPage page = client.getPage(new URL(baseURL, "charlie.jsf"));
    page.asXml();
    HtmlSpan oldel = getFirstMatchingElement(page, HtmlSpan.class, "oldel");
    assertNotNull(oldel);
    final String charlie = "Charlie";
    assertEquals(charlie, oldel.asText());
    HtmlSpan newel = getFirstMatchingElement(page, HtmlSpan.class, "newel");
    assertNotNull(newel);
    assertEquals(charlie, newel.asText());
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 84 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project core by weld.

the class InvalidateSessionTest method testInvalidateSessionCalled.

/*
    * description = "WELD-380, WELD-403"
    */
@Test
public void testInvalidateSessionCalled() throws Exception {
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(true);
    HtmlPage page = client.getPage(getPath("/storm.jsf"));
    HtmlSubmitInput invalidateSessionButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "invalidateSessionButton");
    page = invalidateSessionButton.click();
    HtmlInput inputField = getFirstMatchingElement(page, HtmlInput.class, "prop");
    Assert.assertEquals(Storm.PROPERTY_VALUE, inputField.getValueAttribute());
    // Make another request to verify that the session bean value is not the
    // one from the previous invalidated session.
    page = client.getPage(getPath("/storm.jsf"));
    inputField = getFirstMatchingElement(page, HtmlInput.class, "prop");
    Assert.assertEquals(SomeBean.DEFAULT_PROPERTY_VALUE, inputField.getValueAttribute());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) Test(org.junit.Test)

Example 85 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project core by weld.

the class InvalidateSessionTest method testNoDoubleDestructionOnExternalRedirect.

/*
    * description = "WELD-461"
    */
@Test
public void testNoDoubleDestructionOnExternalRedirect() throws Exception {
    WebClient client = new WebClient();
    HtmlPage page = client.getPage(getPath("/storm.jsf"));
    HtmlSubmitInput button = getFirstMatchingElement(page, HtmlSubmitInput.class, "redirectButton");
    button.click();
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Aggregations

HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)159 Test (org.junit.Test)114 WebClient (com.gargoylesoftware.htmlunit.WebClient)51 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)25 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)23 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)21 File (java.io.File)17 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)15 Matchers.containsString (org.hamcrest.Matchers.containsString)13 IOException (java.io.IOException)11 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)10 FreeStyleProject (hudson.model.FreeStyleProject)9 URL (java.net.URL)9 Page (com.gargoylesoftware.htmlunit.Page)8 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)7 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)6 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)5 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)5 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)5