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");
}
use of com.gargoylesoftware.htmlunit.html.HtmlPage in project spring-boot-quick by vector4wang.
the class BaiduCrawlerUrl method searchResult.
public static void searchResult(String search, String keyword, int page) throws IOException {
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setCssEnabled(false);
client.getOptions().setThrowExceptionOnScriptError(false);
while (true) {
// 限制,如果数据采集错误,或者无限的时候,就限制100页
if (page == 100) {
break;
}
String url = "http://www.baidu.com/s?pn=" + (page - 1) * pageSize + "&wd=" + keyword;
HtmlPage result = client.getPage(url);
String contentAsString = result.getWebResponse().getContentAsString();
try {
parseContent(contentAsString);
} catch (Exception e) {
e.printStackTrace();
break;
}
page++;
}
}
use of com.gargoylesoftware.htmlunit.html.HtmlPage 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();
}
use of com.gargoylesoftware.htmlunit.html.HtmlPage in project testcases by coheigea.
the class OIDCTest method registerNewClient.
private static HtmlPage registerNewClient(WebClient webClient, String url, String clientName, String redirectURI, String clientAudience) throws Exception {
HtmlPage registerPage = webClient.getPage(url + "/register");
final HtmlForm form = registerPage.getForms().get(0);
// Set new client values
final HtmlTextInput clientNameInput = form.getInputByName("client_name");
clientNameInput.setValueAttribute(clientName);
final HtmlSelect clientTypeSelect = form.getSelectByName("client_type");
clientTypeSelect.setSelectedAttribute("confidential", true);
final HtmlTextInput redirectURIInput = form.getInputByName("client_redirectURI");
redirectURIInput.setValueAttribute(redirectURI);
final HtmlTextInput clientAudienceURIInput = form.getInputByName("client_audience");
clientAudienceURIInput.setValueAttribute(clientAudience);
final HtmlButton button = form.getButtonByName("submit_button");
return button.click();
}
use of com.gargoylesoftware.htmlunit.html.HtmlPage 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();
}
Aggregations