Search in sources :

Example 36 with HtmlPage

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

the class ServletConversationTest method testPost.

@Test
public void testPost() throws Exception {
    WebClient client = new WebClient();
    // begin conversation
    TextPage initialPage = client.getPage(getPath("/begin", null));
    String content = initialPage.getContent();
    assertTrue(content.contains("message: Hello"));
    assertTrue(content.contains("transient: false"));
    String cid = getCid(content);
    // submit a form
    {
        HtmlPage form = client.getPage(url.toString() + "/message.html");
        getFirstMatchingElement(form, HtmlTextInput.class, "message").setValueAttribute("Hola!");
        getFirstMatchingElement(form, HtmlTextInput.class, "cid").setValueAttribute(cid);
        TextPage page = getFirstMatchingElement(form, HtmlSubmitInput.class, "submit").click();
        assertTrue(page.getContent().contains("message: Hola!"));
        assertTrue(page.getContent().contains("cid: [" + cid + "]"));
        assertTrue(page.getContent().contains("transient: false"));
    }
    // verify conversation state
    {
        TextPage page = client.getPage(getPath("/display", cid));
        assertTrue(page.getContent().contains("message: Hola!"));
        assertTrue(page.getContent().contains("cid: [" + cid + "]"));
        assertTrue(page.getContent().contains("transient: false"));
    }
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 37 with HtmlPage

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

the class Weld1262Test method testConversationNotPropagatedByFacesRedirect.

@Test
public void testConversationNotPropagatedByFacesRedirect() throws Exception {
    HtmlPage main = startConversation();
    HtmlPage road = getFirstMatchingElement(main, HtmlSubmitInput.class, "redirect").click();
    assertEquals("Guide is not active", getFirstMatchingElement(road, HtmlSpan.class, "guideMessage").getTextContent());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) Test(org.junit.Test)

Example 38 with HtmlPage

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

the class Weld1262Test method startConversation.

public HtmlPage startConversation() throws Exception {
    WebClient client = new WebClient();
    HtmlPage main = client.getPage(url.toString().concat("crossroad.jsf"));
    main = getFirstMatchingElement(main, HtmlSubmitInput.class, "begin").click();
    String cid = getFirstMatchingElement(main, HtmlSpan.class, "cid").getTextContent();
    assertTrue(Integer.valueOf(cid) > 0);
    return main;
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 39 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project joynr by bmwcarit.

the class ChannelServiceTestUtils method getChannelIdsOnChannelsHtml.

/**
 * Returns a list of channel IDs that are displayed on the channels.html page for the bounce proxy.
 *
 * @param webClient
 * @param url
 * @return
 * @throws Exception
 */
public static List<String> getChannelIdsOnChannelsHtml(WebClient webClient, String url) throws Exception {
    HtmlPage page = webClient.getPage(url);
    webClient.waitForBackgroundJavaScript(2000);
    DomElement channelsTable = page.getElementById("channels");
    List<String> channelIds = new LinkedList<String>();
    for (DomElement channelsTableRows : channelsTable.getChildElements()) {
        if (channelsTableRows.getTagName().equals("tbody")) {
            for (DomElement channelRows : channelsTableRows.getChildElements()) {
                String channelId = channelRows.getChildNodes().get(0).getTextContent();
                if (isProperChannelId(channelId)) {
                    channelIds.add(channelId);
                }
            }
        }
    }
    return channelIds;
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) LinkedList(java.util.LinkedList)

Example 40 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project shiro by apache.

the class ContainerIntegrationIT method logIn.

@Test
public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
    HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
    HtmlForm form = page.getFormByName("loginform");
    form.<HtmlInput>getInputByName("username").setValueAttribute("root");
    form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
    page = form.<HtmlInput>getInputByName("submit").click();
    // This'll throw an expection if not logged in
    page.getAnchorByHref("/logout");
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) 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