Search in sources :

Example 51 with WebClient

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

the class OIDCTest method loginToClientsPage.

// Runs as BeforeClass: Login to the OIDC Clients page + create a new client
private static void loginToClientsPage(String rpPort, String oidcPort, String idpPort) throws Exception {
    String url = "https://localhost:" + oidcPort + "/fediz-oidc/console/clients";
    String user = "alice";
    String password = "ecila";
    // Login to the client page successfully
    WebClient webClient = setupWebClient(user, password, idpPort);
    HtmlPage loginPage = login(url, webClient);
    final String bodyTextContent = loginPage.getBody().getTextContent();
    Assert.assertTrue(bodyTextContent.contains("Registered Clients"));
    String clientUrl = "https://localhost:" + rpPort + "/fedizdoubleit/auth/rp/complete";
    // Now try to register a new client
    HtmlPage registeredClientPage = registerNewClient(webClient, url, "consumer-id", clientUrl, clientUrl);
    String registeredClientPageBody = registeredClientPage.getBody().getTextContent();
    Assert.assertTrue(registeredClientPageBody.contains("Registered Clients"));
    Assert.assertTrue(registeredClientPageBody.contains("consumer-id"));
    HtmlTable table = registeredClientPage.getHtmlElementById("registered_clients");
    storedClientId = table.getCellAt(1, 1).asText().trim();
    Assert.assertNotNull(storedClientId);
    // Now get the Client Secret
    final HtmlPage clientPage = webClient.getPage(url + "/" + storedClientId);
    HtmlTable clientPageTable = clientPage.getHtmlElementById("client");
    storedClientSecret = clientPageTable.getCellAt(1, 2).asText().trim();
    Assert.assertNotNull(storedClientSecret);
    webClient.close();
}
Also used : HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 52 with WebClient

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

the class SAMLSSOTest 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("samlsigninresponseform");
    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 53 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project spring-security by spring-projects.

the class S101Configurer method installBuildTool.

private String installBuildTool(File installationDirectory, File configurationDirectory) {
    String source = "https://structure101.com/binaries/v6";
    try (final WebClient webClient = new WebClient()) {
        HtmlPage page = webClient.getPage(source);
        Matcher matcher = null;
        for (HtmlAnchor anchor : page.getAnchors()) {
            Matcher candidate = Pattern.compile("(structure101-build-java-all-)(.*).zip").matcher(anchor.getHrefAttribute());
            if (candidate.find()) {
                matcher = candidate;
            }
        }
        if (matcher == null) {
            return null;
        }
        copyZipToFilesystem(source, installationDirectory, matcher.group(1) + matcher.group(2));
        return matcher.group(2);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Matcher(java.util.regex.Matcher) WebClient(com.gargoylesoftware.htmlunit.WebClient) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 54 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project javaee7-samples by javaee-samples.

the class MyBeanTest method setup.

@Before
public void setup() throws IOException {
    webClient = new WebClient();
    page = webClient.getPage(base + "/faces/index.xhtml");
    nameInputText = (HtmlTextInput) page.getElementById("nameInputText");
    ageInputText = (HtmlTextInput) page.getElementById("ageInputText");
    zipInputText = (HtmlTextInput) page.getElementById("zipInputText");
    button = (HtmlSubmitInput) page.getElementById("submitButton");
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Before(org.junit.Before)

Example 55 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project javaee7-samples by javaee-samples.

the class SecureServletTest method setup.

@Before
public void setup() {
    correctCreds.addCredentials("u1", "p1");
    incorrectCreds.addCredentials("random", "random");
    webClient = new WebClient();
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Before(org.junit.Before)

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