Search in sources :

Example 31 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class ServletBeansTest method testServletContext.

@Test
public void testServletContext() throws Exception {
    WebClient client = new WebClient();
    client.getPage(url + "/context");
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 32 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class UnavailableInterceptedBeanMetadataTest method testMetadataIsNotAvailable.

@Test
public void testMetadataIsNotAvailable() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
    WebClient webClient = new WebClient();
    webClient.setThrowExceptionOnFailingStatusCode(true);
    Page page = webClient.getPage(contextPath + "FooServlet");
    assertEquals("OK", page.getWebResponse().getContentAsString().trim());
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 33 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class AsyncServletTest method test.

@Test
public void test() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
    WebClient client = new WebClient();
    Page page = client.getPage(url.toString() + "/foo");
    String content = page.getWebResponse().getContentAsString();
    assertTrue("Unexpected response, was: " + content, content.contains("BMX"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 34 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class EmptyCidConversationRestorationTest method testEmptyCidDoesNotTriggerConversationRestoration.

@Test
public void testEmptyCidDoesNotTriggerConversationRestoration() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
    WebClient webClient = new WebClient();
    webClient.setThrowExceptionOnFailingStatusCode(true);
    TextPage page = webClient.getPage(contextPath + "echo?say=Hello&cid=");
    assertEquals("Hello", page.getContent());
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 35 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class ClientConversationContextTest method testExceptionPhaseListener.

@Test
public void testExceptionPhaseListener() throws Exception {
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(false);
    // 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
    HtmlPage thunderstorm = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "beginConversation").click();
    String cid = getCid(thunderstorm);
    // and access the page that throws an exception again
    getFirstMatchingElement(cloud, HtmlSubmitInput.class, "thunderstorm").click();
    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) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Aggregations

WebClient (com.gargoylesoftware.htmlunit.WebClient)182 Test (org.junit.Test)110 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)55 Page (com.gargoylesoftware.htmlunit.Page)33 TextPage (com.gargoylesoftware.htmlunit.TextPage)21 Before (org.junit.Before)20 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)17 URL (java.net.URL)14 JsonObject (javax.json.JsonObject)13 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)13 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)12 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)11 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)10 ReadContext (com.jayway.jsonpath.ReadContext)10 File (java.io.File)9 IOException (java.io.IOException)8 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)7 Test (org.junit.jupiter.api.Test)7 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)6 DefaultCredentialsProvider (com.gargoylesoftware.htmlunit.DefaultCredentialsProvider)5