1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.test.web;
17
18 import com.gargoylesoftware.htmlunit.BrowserVersion;
19 import com.gargoylesoftware.htmlunit.WebClient;
20 import com.gargoylesoftware.htmlunit.html.HtmlForm;
21 import com.gargoylesoftware.htmlunit.html.HtmlPage;
22 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
23 import org.kuali.rice.core.config.ConfigContext;
24
25 import java.net.URL;
26
27 public class HtmlUnitUtil {
28
29 public static final String BASE_URL = "http://localhost:" + getPort() + "/knstest";
30
31 public static HtmlPage gotoPageAndLogin(String url) throws Exception {
32 final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
33 HtmlPage loginPage = (HtmlPage)webClient.getPage(new URL(url));
34 HtmlForm htmlForm = (HtmlForm)loginPage.getForms().get(0);
35 htmlForm.getInputByName("__login_user").setValueAttribute("quickstart");
36 HtmlSubmitInput button = (HtmlSubmitInput)htmlForm.getInputByValue("Login");
37 return (HtmlPage)button.click();
38 }
39
40 public static boolean pageContainsText(HtmlPage page, String text) {
41 return page.asText().contains(text);
42 }
43
44 public static Integer getPort() {
45 return new Integer(ConfigContext.getCurrentContextConfig().getProperty("kns.test.port"));
46 }
47 }