Posted on 2008-01-29 17:25
G_G 阅读(437)
评论(0) 编辑 收藏 所属分类:
JUnit
httpUnit
package httpUnit;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import junit.framework.TestCase;
public class HttpTest extends TestCase {
public void testT() throws Exception {
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest( "http://www.baidu.com" );
WebResponse resp = wc.getResponse( req );
//<input type=submit value=百度一下 id=sb>
//<input type=text name=wd id=kw size=36 maxlength=100>
WebForm form = resp.getForms()[0]; // select the first form in the page
form.setParameter( "wd", "Italian" );
resp.getForms()[0].getSubmitButtonWithID("sb").click();
System.out.println( wc.getCurrentPage().getText() );
}
}