01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.rice.testharness;
17:
18: import java.net.URL;
19:
20: import org.kuali.rice.core.Core;
21:
22: import com.gargoylesoftware.htmlunit.BrowserVersion;
23: import com.gargoylesoftware.htmlunit.WebClient;
24: import com.gargoylesoftware.htmlunit.html.HtmlForm;
25: import com.gargoylesoftware.htmlunit.html.HtmlPage;
26: import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
27:
28: public class HtmlUnitUtil {
29:
30: public static final String BASE_URL = "http://localhost:"
31: + getPort() + "/SampleRiceClient";
32:
33: public static HtmlPage gotoPageAndLogin(String url)
34: throws Exception {
35: final WebClient webClient = new WebClient(
36: BrowserVersion.INTERNET_EXPLORER_6_0);
37: HtmlPage loginPage = (HtmlPage) webClient.getPage(new URL(url));
38: HtmlForm htmlForm = (HtmlForm) loginPage.getForms().get(0);
39: HtmlSubmitInput button = (HtmlSubmitInput) htmlForm
40: .getInputByValue("Login");
41: return (HtmlPage) button.click();
42: }
43:
44: public static boolean pageContainsText(HtmlPage page, String text) {
45: return page.asText().indexOf(text) >= 0;
46: }
47:
48: public static Integer getPort() {
49: return new Integer(Core.getCurrentContextConfig().getProperty(
50: "kns.test.port"));
51: }
52: }
|