Search in sources :

Example 51 with Page

use of com.gargoylesoftware.htmlunit.Page in project mvc-tck by mvc-spec.

the class SimpleAnnotatedTest method shouldDoStuff.

@Test
@SpecAssertion(section = "list-of-assertions", id = "Controller_Annotation")
public void shouldDoStuff() throws IOException {
    Page page = new WebClient().getPage(baseUrl.toString() + "mvc/simple");
    Assert.assertThat(page.getWebResponse().getContentAsString(), CoreMatchers.containsString("Hello world!"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 52 with Page

use of com.gargoylesoftware.htmlunit.Page in project spring-boot-quick by vector4wang.

the class test2 method main.

public static void main(String[] args) throws IOException {
    // 创建WebClient
    final WebClient webClient = new WebClient();
    webClient.getOptions().setJavaScriptEnabled(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setRedirectEnabled(true);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    Document parse = null;
    Page page = null;
    for (int i = 100; i < 1000; i++) {
        try {
            page = webClient.getPage("http://www.innotree.cn/company/" + i + ".html");
            parse = Jsoup.parse(page.getWebResponse().getContentAsString());
            Elements select = parse.select("body > div.details_1221_con > div.details_1221_d01 > div.details_1221_d01_01 > table > tbody > tr > td:nth-child(2) > h3");
            System.out.println(select.get(0).text());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) WebClient(com.gargoylesoftware.htmlunit.WebClient) IOException(java.io.IOException)

Example 53 with Page

use of com.gargoylesoftware.htmlunit.Page in project spring-boot-quick by vector4wang.

the class Test method main.

public static void main(String[] args) throws IOException {
    WebClient client = new WebClient(BrowserVersion.CHROME);
    Page page = client.getPage("https://cas.baidu.com/?action=image&key=1497149653");
    InputStream contentAsStream = page.getWebResponse().getContentAsStream();
    IOUtils.copy(contentAsStream, new FileOutputStream(new File("d:\\bd.png")));
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) File(java.io.File)

Example 54 with Page

use of com.gargoylesoftware.htmlunit.Page in project tomee by apache.

the class FormAuthServletTest method authenticate.

@Test
public void authenticate() throws Exception {
    final WebClient webClient = new WebClient();
    final HtmlPage page = webClient.getPage(getAppUrl() + "/form");
    assertEquals(200, page.getWebResponse().getStatusCode());
    final HtmlForm login = page.getFormByName("login");
    login.getInputByName("j_username").setValueAttribute("tomcat");
    login.getInputByName("j_password").setValueAttribute("tomcat");
    final Page result = login.getInputByName("submit").click();
    assertEquals(200, result.getWebResponse().getStatusCode());
    assertEquals("ok!", result.getWebResponse().getContentAsString());
    assertEquals("ok!", webClient.getPage(getAppUrl() + "/form").getWebResponse().getContentAsString());
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) AbstractTomEESecurityTest(org.apache.tomee.security.AbstractTomEESecurityTest) Test(org.junit.Test)

Example 55 with Page

use of com.gargoylesoftware.htmlunit.Page in project blueocean-plugin by jenkinsci.

the class JwtAuthenticationServiceImplTest method anonymousUserToken.

@Test
public void anonymousUserToken() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    JenkinsRule.WebClient webClient = j.createWebClient();
    String token = getToken(webClient);
    Assert.assertNotNull(token);
    JsonWebStructure jsonWebStructure = JsonWebStructure.fromCompactSerialization(token);
    Assert.assertTrue(jsonWebStructure instanceof JsonWebSignature);
    JsonWebSignature jsw = (JsonWebSignature) jsonWebStructure;
    String kid = jsw.getHeader("kid");
    Assert.assertNotNull(kid);
    Page page = webClient.goTo("jwt-auth/jwks/" + kid + "/", "application/json");
    // for(NameValuePair valuePair: page.getWebResponse().getResponseHeaders()){
    // System.out.println(valuePair);
    // }
    JSONObject jsonObject = JSONObject.fromObject(page.getWebResponse().getContentAsString());
    RsaJsonWebKey rsaJsonWebKey = new RsaJsonWebKey(jsonObject, null);
    JwtConsumer jwtConsumer = new JwtConsumerBuilder().setRequireExpirationTime().setAllowedClockSkewInSeconds(// allow some leeway in validating time based claims to account for clock skew
    30).setRequireSubject().setVerificationKey(// verify the sign with the public key
    rsaJsonWebKey.getKey()).build();
    JwtClaims claims = jwtConsumer.processToClaims(token);
    Assert.assertEquals("anonymous", claims.getSubject());
    Map<String, Object> claimMap = claims.getClaimsMap();
    Map<String, Object> context = (Map<String, Object>) claimMap.get("context");
    Map<String, String> userContext = (Map<String, String>) context.get("user");
    Assert.assertEquals("anonymous", userContext.get("id"));
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) JwtConsumerBuilder(org.jose4j.jwt.consumer.JwtConsumerBuilder) Page(com.gargoylesoftware.htmlunit.Page) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) JsonWebSignature(org.jose4j.jws.JsonWebSignature) JSONObject(net.sf.json.JSONObject) JwtConsumer(org.jose4j.jwt.consumer.JwtConsumer) JSONObject(net.sf.json.JSONObject) RsaJsonWebKey(org.jose4j.jwk.RsaJsonWebKey) Map(java.util.Map) JsonWebStructure(org.jose4j.jwx.JsonWebStructure) Test(org.junit.Test)

Aggregations

Page (com.gargoylesoftware.htmlunit.Page)62 Test (org.junit.Test)39 WebClient (com.gargoylesoftware.htmlunit.WebClient)33 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)15 PublicAtsApi (com.axway.ats.common.PublicAtsApi)9 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)5 File (java.io.File)5 IOException (java.io.IOException)5 URL (java.net.URL)5 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)5 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)4 ConfirmHandler (com.gargoylesoftware.htmlunit.ConfirmHandler)4 Map (java.util.Map)4 JSONObject (net.sf.json.JSONObject)4 RsaJsonWebKey (org.jose4j.jwk.RsaJsonWebKey)4 JsonWebSignature (org.jose4j.jws.JsonWebSignature)4 JwtClaims (org.jose4j.jwt.JwtClaims)4 JwtConsumer (org.jose4j.jwt.consumer.JwtConsumer)4 JwtConsumerBuilder (org.jose4j.jwt.consumer.JwtConsumerBuilder)4 JsonWebStructure (org.jose4j.jwx.JsonWebStructure)4