Search in sources :

Example 31 with HtmlPage

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

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

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

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

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

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