posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

httpUnit 之使用其他web资源

Posted on 2008-01-29 17:25 G_G 阅读(426) 评论(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() );
    }
}


只有注册用户登录后才能发表评论。


网站导航: