Search in sources :

Example 86 with HtmlPage

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

the class ErrorPageTest method testActionMethodExceptionDoesNotDestroyContext.

@Test
public void testActionMethodExceptionDoesNotDestroyContext() throws Exception {
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = client.getPage(getPath("/storm.jsf"));
    HtmlSubmitInput disasterButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "disasterButton");
    HtmlTextInput strength = getFirstMatchingElement(page, HtmlTextInput.class, "stormStrength");
    strength.setValueAttribute("10");
    page = disasterButton.click();
    Assert.assertEquals("Application Error", page.getTitleText());
    HtmlDivision conversationValue = getFirstMatchingElement(page, HtmlDivision.class, "conversation");
    Assert.assertEquals("10", conversationValue.asText());
    HtmlDivision requestValue = getFirstMatchingElement(page, HtmlDivision.class, "request");
    Assert.assertEquals("medium", requestValue.asText());
}
Also used : HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 87 with HtmlPage

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

the class ClientConversationContextTest method testInvalidateCallsPreDestroy.

@Test
public void testInvalidateCallsPreDestroy() throws Exception {
    WebClient client = new WebClient();
    // Now start a conversation
    HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
    cloud = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "hurricane").click();
    // Invalidate the session
    cloud = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "invalidateSession").click();
    String cloudDestroyed = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudDestroyed").getTextContent();
    assertEquals("true", cloudDestroyed);
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 88 with HtmlPage

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

the class ClientConversationContextTest method testExceptionInPreDestroy.

@Test
public void testExceptionInPreDestroy() throws Exception {
    WebClient client = new WebClient();
    // First, try a transient conversation
    // Access a page that throws an exception
    client.getPage(getPath("/thunderstorm.jsf"));
    // Then access another page that doesn't and check the contexts are ok
    HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
    String cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals(Cloud.NAME, cloudName);
    // Now start a conversation and access the page that throws an exception
    // again
    HtmlPage thunderstorm = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "beginConversation").click();
    String thunderstormName = getFirstMatchingElement(thunderstorm, HtmlSpan.class, "thunderstormName").getTextContent();
    assertEquals(Thunderstorm.NAME, thunderstormName);
    cloud = getFirstMatchingElement(thunderstorm, HtmlSubmitInput.class, "cloud").click();
    // And navigate to another page, checking the conversation exists by
    // verifying that state is maintained
    cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals("bob", cloudName);
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 89 with HtmlPage

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

the class ClientConversationContextTest method testInvalidateThenRedirect.

@Test
public void testInvalidateThenRedirect() throws Exception {
    WebClient client = new WebClient();
    // Now start a conversation
    HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
    cloud = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "hurricane").click();
    // Now invalidate the session and redirect
    cloud = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "sleet").click();
    // Check that we are still working by verifying the page rendered
    String cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals(Cloud.NAME, cloudName);
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 90 with HtmlPage

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

the class ClientConversationContextTest method testExceptionInPostConstruct.

@Test
public void testExceptionInPostConstruct() throws Exception {
    WebClient client = new WebClient();
    // First, try a transient conversation
    client.setThrowExceptionOnFailingStatusCode(false);
    // Access a page that throws an exception
    client.getPage(getPath("/hailstorm.jsf"));
    // Then access another page that doesn't and check the contexts are ok
    HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
    String cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals(Cloud.NAME, cloudName);
    // Now start a conversation and access the page that throws an exception
    // again
    Page hailstorm = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "hail").click();
    String cid = getCid(hailstorm);
    cloud = client.getPage(getPath("/cloud.jsf", cid));
    // And navigate to another page, checking the conversation exists by
    // verifying that state is maintained
    cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals("gavin", cloudName);
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) 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