Search in sources :

Example 91 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project testcases by coheigea.

the class FederationTest method login.

private static String login(String url, String user, String password, String idpPort) throws IOException {
    final WebClient webClient = new WebClient();
    webClient.getOptions().setUseInsecureSSL(true);
    webClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", Integer.parseInt(idpPort)), new UsernamePasswordCredentials(user, password));
    webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage idpPage = webClient.getPage(url);
    webClient.getOptions().setJavaScriptEnabled(true);
    Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
    final HtmlForm form = idpPage.getFormByName("signinresponseform");
    final HtmlSubmitInput button = form.getInputByName("_eventId_submit");
    final XmlPage rpPage = button.click();
    return rpPage.asXml();
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) AuthScope(org.apache.http.auth.AuthScope) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 92 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project jackrabbit-oak by apache.

the class TomcatIT method setUp.

protected void setUp() throws Exception {
    File war = null;
    for (File f : new File("target").listFiles()) {
        if (f.isDirectory() && new File(f, "WEB-INF/web.xml").isFile()) {
            war = f;
            break;
        }
    }
    assertNotNull(war);
    rewriteWebXml(war);
    File bootstrap = new File("target", "bootstrap.properties");
    bootstrap.delete();
    File baseDir = new File("target", "tomcat");
    FileUtils.deleteQuietly(baseDir);
    File repoDir = new File("target", "repository");
    FileUtils.deleteQuietly(repoDir);
    url = new URL("http://localhost:" + getPort() + "/");
    tomcat = new Tomcat();
    tomcat.setSilent(true);
    tomcat.setBaseDir(baseDir.getPath());
    tomcat.setHostname(url.getHost());
    tomcat.setPort(url.getPort());
    tomcat.addWebapp("", war.getAbsolutePath());
    tomcat.start();
    client = new WebClient();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL)

Example 93 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project archiva by apache.

the class AbstractRepositoryServletTestCase method newClient.

protected static WebClient newClient() {
    final WebClient webClient = new WebClient();
    webClient.getOptions().setJavaScriptEnabled(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setAppletEnabled(false);
    webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    return webClient;
}
Also used : NicelyResynchronizingAjaxController(com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 94 with WebClient

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

the class WeldSeBuilderTest method test.

private void test(ServletContextHandler context) throws Exception {
    Server server = new Server(8080);
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(TestServlet.class, "/test");
    server.start();
    try {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        Page page = webClient.getPage("http://localhost:8080/test");
        assertEquals("Kitty", page.getWebResponse().getContentAsString().trim());
    } finally {
        // no need to stop Weld here, it is stopped by weld-servlet
        server.stop();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 95 with WebClient

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

the class SimpleAsyncListenerTest method testOnCompleteCalledSuccesfully.

@Test
public void testOnCompleteCalledSuccesfully() throws Exception {
    WebClient webClient = new WebClient();
    webClient.getPage(getPath(AsyncServlet.TEST_COMPLETE));
    Page results = webClient.getPage(contextPath + "Status");
    assertTrue(results.getWebResponse().getContentAsString().contains("onComplete: true"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) 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