Search in sources :

Example 91 with HtmlPage

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

the class Weld1262Test method testConversationPropagatedByNavigationHandler.

@Test
public void testConversationPropagatedByNavigationHandler() throws Exception {
    HtmlPage main = startConversation();
    HtmlPage road = getFirstMatchingElement(main, HtmlSubmitInput.class, "guide").click();
    assertEquals("Guide is 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 92 with HtmlPage

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

the class NamedProducerTest method testNamedProducerFieldLoosesValues.

/*
    * description = "WELD-404"
    */
@Test
public void testNamedProducerFieldLoosesValues() throws Exception {
    WebClient client = new WebClient();
    HtmlPage page = client.getPage(getPath("/home.jsf"));
    // Check the page rendered ok
    HtmlSubmitInput saveButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton");
    HtmlTextInput employeeFieldName = getFirstMatchingElement(page, HtmlTextInput.class, "employeeFieldName");
    HtmlTextInput employeeMethodName = getFirstMatchingElement(page, HtmlTextInput.class, "employeeMethodName");
    Assert.assertNotNull(employeeFieldName);
    Assert.assertNotNull(employeeMethodName);
    Assert.assertNotNull(saveButton);
    employeeFieldName.setValueAttribute("Pete");
    employeeMethodName.setValueAttribute("Gavin");
    saveButton.click();
}
Also used : HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 93 with HtmlPage

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

the class NamedProducerTest method testNamedProducerWorks.

/*
    * description = "forum post"
    */
@Test
public void testNamedProducerWorks() throws Exception {
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = client.getPage(getPath("/view.jsf"));
    // Check the page rendered ok
    Assert.assertNotNull(getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton"));
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 94 with HtmlPage

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

the class InnotreeService 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);
    // webClient.getOptions().set
    webClient.getOptions().setTimeout(5000);
    // 
    // // 获取页面
    // HtmlPage page = webClient.getPage("http://www.innotree.cn/indexprocoo/search.html?keyword=%E5%85%AB%E7%88%AA");
    // webClient.waitForBackgroundJavaScript(10000);
    // // 获得name为"session_key"的html元素
    // //        HtmlElement usernameEle = page.getElementByName("session_key");
    // //        // 获得id为"session_password"的html元素
    // //        HtmlElement passwordEle = (HtmlElement) page.getElementById("session_password-login");
    // //        usernameEle.focus(); // 设置输入焦点
    // //        usernameEle.type(name);
    // //        passwordEle.focus(); // 设置输入焦点
    // //
    // //        passwordEle.type(password);
    // System.out.println(page.getWebResponse().getContentAsString());
    String keyEncode = URLEncoder.encode("八爪", "UTF-8");
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    WebRequest webRequest = new WebRequest(new URL("http://www.innotree.cn/collectlog/info.ajax"));
    webRequest.setHttpMethod(HttpMethod.POST);
    JSONObject params = new JSONObject();
    params.put("source_type", "pc");
    params.put("collect_type", "click");
    params.put("collect_key", "search");
    params.put("collect_type", "八爪");
    params.put("collect_id", "");
    params.put("u_request_url", "http://www.innotree.cn/indexprocoo/search.html?keyword=" + keyEncode);
    params.put("u_referer_url", "http://www.innotree.cn/indexprocoo/search.html?keyword=" + keyEncode);
    params.put("u_agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36");
    params.put("gen_time", format.format(new Date()));
    params.put("collect_page", "SearchList");
    JSONObject nj = new JSONObject();
    nj.put("json", params);
    webRequest.setAdditionalHeader("Accept", "application/json, text/javascript, */*; q=0.01");
    webRequest.setAdditionalHeader("Accept-Encoding", "gzip, deflate");
    webRequest.setAdditionalHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    webRequest.setAdditionalHeader("Connection", "keep-alive");
    webRequest.setAdditionalHeader("Host", "www.innotree.cn");
    webRequest.setAdditionalHeader("Cookie", "_user_identify_=38e78465-ca98-39a1-a411-d22034ad31af; JSESSIONID=aaaJR4Oz2351xh_LAPKZv; Hm_lvt_37854ae85b75cf05012d4d71db2a355a=1498484735,1498485012; Hm_lpvt_37854ae85b75cf05012d4d71db2a355a=1498486706");
    webRequest.setAdditionalHeader("Origin", "http://www.innotree.cn");
    webRequest.setAdditionalHeader("Referer", "http://www.innotree.cn/indexprocoo/search.html?keyword=" + keyEncode);
    webRequest.setAdditionalHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36");
    webRequest.setAdditionalHeader("X-Requested-With", "XMLHttpRequest");
    // webRequest.setAdditionalHeader("Content-Length",""+params.toString().length());
    System.out.println(nj.toString());
    // webRequest.setRequestBody("REQUESTBODY");
    webRequest.setRequestParameters(new ArrayList());
    webRequest.getRequestParameters().add(new NameValuePair("json", params.toString()));
    Page page = webClient.getPage(webRequest);
    // webRequest.getre
    page = webClient.getPage("http://www.innotree.cn/indexprocoo/search.html?keyword=" + keyEncode);
    System.out.println(page.getWebResponse().getContentAsString());
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) JSONObject(net.sf.json.JSONObject) ArrayList(java.util.ArrayList) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) SimpleDateFormat(java.text.SimpleDateFormat) URL(java.net.URL) Date(java.util.Date)

Example 95 with HtmlPage

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

the class TomcatIT method testTomcat.

public void testTomcat() throws Exception {
    HtmlPage page = client.getPage(url);
    assertEquals("Content Repository Setup", page.getTitleText());
    page = submitNewRepositoryForm(page);
    assertEquals("Content Repository Ready", page.getTitleText());
    page = page.getAnchorByText("home").click();
    assertEquals("Apache Jackrabbit JCR Server", page.getTitleText());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage)

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