1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1 public class HttpUnitTest { 2 public static void main(String[] args) { 3 try { 4 WebConversation wc = new WebConversation(); 5 WebRequest request = new GetMethodWebRequest("http://httpunit.sourceforge.net/index.html"); 6 wc.setProxyServer( "your.proxy.com", 80 ); 7 WebResponse response = wc.getResponse(request); 8 WebLink httpunitLink = response.getFirstMatchingLink(WebLink.MATCH_CONTAINED_TEXT,"Cookbook"); 9 response = httpunitLink.click(); 10 System.out.println("Test successful !!"); 11 } catch (Exception e) { 12 System.err.println("Exception: " + e); 13 } 14 } 15 } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 1 public class JWebUnitTest extends WebTestCase{ 2 public static void main(String[] args){ 3 junit.textui.TestRunner.run(new TestSuite(JWebUnitTest.class)); 4 } 5 public void setUp(){ 6 getTestContext().setBaseUrl("http://httpunit.sourceforge.net"); 7 getTestContext().setProxyName("webproxy.watson.ibm.com"); 8 getTestContext().setProxyPort(8080); 9 } 10 public void testSearch(){ 11 beginAt("/index.html"); 12 clickLinkWithText("Cookbook"); 13 } 14 } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |