Tips on HttpUnit

原创 2006年06月10日 21:23:00

Tips on HttpUnit

  1. import package.
    import com.meterware.httpunit.*;
    import junit.framework.*;
  2. Unit test source code of httpunit is primary resource to study how to use it.
    httpunit-1.6.2/test/com/meterware/httpunit
  3. Code fragment which shows how to log in.
    WebConversation     conversation =  WebConversation();
    WebRequest request = GetMethodWebRequest( );

    WebResponse response = conversation.getResponse( request );
    WebForm loginForm = response.getForms()[];
    request = loginForm.getRequest();
    request.setParameter( , );
    request.setParameter( , );
    response = conversation.getResponse( request );

    assertEquals( , , response.getURL().toString() );
  4. Code fragment which shows how to disable javascript. Some web application does do some bad html which httpunit can't parse correctly.
    WebConversation conversation =  WebConversation();




    HttpUnitOptions.setScriptingEnabled();

    WebRequest request = GetMethodWebRequest( );

    WebResponse response = conversation.getResponse( request );



  5. Code fragment which shows how to get frame.

    String[] frames = response.getFrameNames();
    ( i = ; i < frames.length; i++ )
    {
    System.out.println( + i + + frames[i] );
    }

    WebResponse frameResponse = response.getSubframeContents( );

    System.out.println( + frameResponse.getURL().toString() );

    WebLink[] links = frameResponse.getLinks();
    ( i = ; i < links.length; i++ )
    {
    System.out.println( + links[i].getText() + +links[i].getURLString() );
    }

    WebResponse menuResponse = getFrameWithURL( conversation, );
    assertNotNull( , menuResponse );

    links = frameResponse.getLinks();
    ( i = ; i < links.length; i++ )
    {
    System.out.println( + links[i].getText() + +links[i].getURLString() );
    }

    NOTE: the following methods are from httpunit's own unit test.
    String getNameOfFrameWithURL( WebConversation wc, String urlString ) {
    String[] names = wc.getFrameNames();
    ( i = ; i < names.length; i++) {
    WebResponse candidate = wc.getFrameContents( names[i] );
    System.out.println( + candidate.getURL().toExternalForm() );
    (candidate.getURL().toExternalForm().indexOf( urlString ) >= ) {
    names[i];
    }
    }
    ;
    }


    WebResponse getFrameWithURL( WebConversation wc, String urlString ) {
    String name = getNameOfFrameWithURL( wc, urlString );
    System.out.println( + name );
    (name == ) ;
    wc.getFrameContents( name );
    }
  6. Httpunit can't parse iframe's id attribute but name attribute is accepted.

tips on WCDMA measurement

  • 2014年10月27日 01:43
  • 999KB
  • 下载

Database Testing – Practical Tips and Insight on How to Test Database

原文:http://www.softwaretestinghelp.com/database-testing-%E2%80%93-practical-tips-and-insight-on-how-t...
  • xuyo
  • xuyo
  • 2011年10月30日 19:55
  • 322

Tips on Optimizing SQL Server Composite Indexes(SQL server 复合索引优化提示)

SQL server 复合索引优化提示

Tips on working with Theano

zz from http://udibr.github.io/tips-on-working-with-theano.html -----------------------------------...

Simple Tips on C++(对于C++的一些建议)

Introduction(简介) For being a powerful object-oriented programming language, C++ is used almost ever...

Expert Tips on Drop Temporary Tablespace Hangs!!

Sometimes it happens that we issue the command for dropping temporary tablespace and the operation j...
  • gyanp
  • gyanp
  • 2012年04月11日 15:10
  • 616

Tips on 浮点数精度

1、误差量epseps缩写自epsilon,表示一个小量,但这个小量又要确保远大于浮点运算结果的不确定量。eps最常见的取值是1e-8左右。引入eps后,我们判断两浮点数a、b相等的方式如下:定义三出...

20 Killer Perl Programming Tips for Beginners on UNIX / Linux OS

1. List all Installed Perl Modules from Unix Command Line $ perl -MFile::Find=find -MFile::Spec::Fu...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Tips on HttpUnit
举报原因:
原因补充:

(最多只允许输入30个字)