File: Example.java

package info (click to toggle)
httpunit 1.7%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,564 kB
  • ctags: 6,646
  • sloc: java: 33,665; xml: 482; sh: 68; makefile: 11
file content (30 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/** everything you need to start is in the com.meterware.httpunit package **/
import com.meterware.httpunit.*;

/** This is a simple example of using HttpUnit to read and understand web pages. **/
public class Example {


  public static void main( String[] params ) {
    try {
      // create the conversation object which will maintain state for us
      WebConversation wc = new WebConversation();

      // Obtain the main page on the meterware web site
      String url="http://www.meterware.com";
      WebRequest request = new GetMethodWebRequest( url );
      WebResponse response = wc.getResponse( request );

      // find the link which contains the string "HttpUnit" and click it
      WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "HttpUnit" );
      response = httpunitLink.click();

      // print out the number of links on the HttpUnit main page
      System.out.println( "The HttpUnit main page '"+url+"' contains " + response.getLinks().length + " links" );

    } catch (Exception e) {
       System.err.println( "Exception: " + e );
    }
  }
}