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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations