Search in sources :

Example 26 with WebClient

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

the class ClientConversationContextTest method testLockingIssue.

@Test
public void testLockingIssue() throws Exception {
    /*
        * click start
        * click redirect
        * click dummy
        * refresh browser or retry url.
        */
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = client.getPage(getPath("/locking-issue.jsf"));
    assertEquals("Gavin", getFirstMatchingElement(page, HtmlSpan.class, "name").getTextContent());
    page = getFirstMatchingElement(page, HtmlSubmitInput.class, "start").click();
    assertEquals("Pete", getFirstMatchingElement(page, HtmlSpan.class, "name").getTextContent());
    String cid = getCid(page);
    getFirstMatchingElement(page, HtmlSubmitInput.class, "dummy").click();
    page = client.getPage(getPath("/locking-issue.jsf?cid=" + cid));
    assertEquals("Pete", getFirstMatchingElement(page, HtmlSpan.class, "name").getTextContent());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 27 with WebClient

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

the class ClientConversationContextTest method testSuppressedConversationPropagation.

@Test
public void testSuppressedConversationPropagation() throws Exception {
    WebClient client = new WebClient();
    // Access the start page
    HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
    assertEquals(Cloud.NAME, getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent());
    // Now start a conversation and check the cloud name changes
    HtmlPage page1 = getFirstMatchingElement(cloud, HtmlSubmitInput.class, Cloud.CUMULUS).click();
    assertEquals(Cloud.CUMULUS, getFirstMatchingElement(page1, HtmlSpan.class, "cloudName").getTextContent());
    String cid = getCid(page1);
    // Activate the conversation from a GET request
    HtmlPage page2 = client.getPage(getPath("/cloud.jsf", cid));
    assertEquals(Cloud.CUMULUS, getFirstMatchingElement(page2, HtmlSpan.class, "cloudName").getTextContent());
    // Send a GET request with the "cid" parameter and suppressed conversation propagation (using conversationPropagation=none)
    HtmlPage page3 = client.getPage(getPath("/cloud.jsf", cid) + "&conversationPropagation=none");
    assertEquals(Cloud.NAME, getFirstMatchingElement(page3, HtmlSpan.class, "cloudName").getTextContent());
    // Test again using the proprietary "nocid" parameter (kept for backwards compatibility)
    HtmlPage page4 = client.getPage(getPath("/cloud.jsf", cid) + "&nocid=true");
    assertEquals(Cloud.NAME, getFirstMatchingElement(page4, HtmlSpan.class, "cloudName").getTextContent());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 28 with WebClient

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

the class ClientConversationContextTest method testConversationNotPropagatedByHLink.

@Test
public void testConversationNotPropagatedByHLink() throws Exception {
    WebClient client = new WebClient();
    // Access the start page
    HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
    String cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals(Cloud.NAME, cloudName);
    // Now start a conversation and check the cloud name changes
    HtmlPage blizzard = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "blizzard").click();
    cloudName = getFirstMatchingElement(blizzard, HtmlSpan.class, "cloudName").getTextContent();
    assertEquals("henry", cloudName);
    // Now use the h:link to navigate back and check the conversation isn't propagated
    cloud = getFirstMatchingElement(blizzard, HtmlAnchor.class, "cloud-link").click();
    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) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 29 with WebClient

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

the class ClientConversationContextTest method testEndAndBeginInSameRequestsKeepsSameCid.

// WELD-755
@Test
public void testEndAndBeginInSameRequestsKeepsSameCid() throws Exception {
    WebClient client = new WebClient();
    HtmlPage page = client.getPage(getPath("/tornado.jsf"));
    String name = getFirstMatchingElement(page, HtmlSpan.class, "tornadoName").getTextContent();
    assertEquals("Pete", name);
    page = getFirstMatchingElement(page, HtmlSubmitInput.class, "beginConversation").click();
    name = getFirstMatchingElement(page, HtmlSpan.class, "tornadoName").getTextContent();
    assertEquals("Shane", name);
    page = getFirstMatchingElement(page, HtmlSubmitInput.class, "endAndBeginConversation").click();
    name = getFirstMatchingElement(page, HtmlSpan.class, "tornadoName").getTextContent();
    assertEquals("Shane", name);
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 30 with WebClient

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

the class ServletBeansTest method testHttpServletRequest.

@Test
public void testHttpServletRequest() throws Exception {
    WebClient client = new WebClient();
    client.getPage(url + "/request?foo=bar");
}
Also used : 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