View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.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  }