[Httpunit-commit] CVS: httpunit/doc Cookbook.html,1.3,1.4 release_notes.txt,1.125,1.126
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-05 15:21:26
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv29000/doc Modified Files: Cookbook.html release_notes.txt Log Message: Correct ordering of links array, support read of link.href Index: Cookbook.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Cookbook.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Cookbook.html 19 Jun 2001 14:43:49 -0000 1.3 +++ Cookbook.html 5 Aug 2002 15:21:19 -0000 1.4 @@ -5,41 +5,41 @@ <H2>Obtaining a web page response</H2> -The center of HttpUnit is the <A HREF="api/com/meterware/httpunit/WebConversation.html">WebConversation</A> class, -which takes the place of a browser talking to a single site. It is responsible for maintaining session context, -which it does via cookies returned by the server. To use it, one must create a -<A HREF="api/com/meterware/httpunit/WebRequest.html">request</A> and ask the WebConversation for a response.<BR> +The center of HttpUnit is the <A HREF="api/com/meterware/httpunit/WebConversation.html">WebConversation</A> class, +which takes the place of a browser talking to a single site. It is responsible for maintaining session context, +which it does via cookies returned by the server. To use it, one must create a +<A HREF="api/com/meterware/httpunit/WebRequest.html">request</A> and ask the WebConversation for a response.<BR> For example: <PRE><CODE> WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest( "http://www.meterware.com/testpage.html" ); WebResponse resp = wc.getResponse( req ); </CODE></PRE> -The <A HREF="api/com/meterware/httpunit/WebResponse.html">response</A> may now be manipulated either as -pure text (via the <CODE>toString()</CODE> method), as a DOM (via the <CODE>getDOM()</CODE> method), +The <A HREF="api/com/meterware/httpunit/WebResponse.html">response</A> may now be manipulated either as +pure text (via the <CODE>getText()</CODE> method), as a DOM (via the <CODE>getDOM()</CODE> method), or by using the various other methods described below. Because the above sequence is so common, it can be abbreviated to: <PRE><CODE> WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://www.meterware.com/testpage.html" ); </CODE></PRE> <H2>Examining and following links</H2> -The simplest and most common form of navigation among web pages is via links. HttpUnit allows users to find links +The simplest and most common form of navigation among web pages is via links. HttpUnit allows users to find links by the text within them, and to use those links as new page requests. For example, this page contains a link to the JavaDoc for the <CODE>WebResponse</CODE> class, above. That page could therefore be obtained as follows: <PRE><CODE> WebConversation wc = new WebConversation(); - WebResponse resp = wc.getResponse( "http://httpunit.sourceforge.net/doc/Cookbook.html" ); // read this page - WebLink link = resp.getLinkWith( "response" ); // find the link - WebRequest req = link.getRequest(); // convert it to a request - WebResponse jdoc = wc.getResponse( req ); // retrieve the referenced page + WebResponse resp = wc.getResponse( "http://www.httpunit.org/doc/Cookbook.html" ); // read this page + WebLink link = resp.getLinkWith( "response" ); // find the link + link.click(); // follow it + WebResponse jdoc = wc.getCurrentPage(); // retrieve the referenced page </CODE></PRE> Image links can be found as well. The <CODE>WebResponse.getLinkWithImageText()</CODE> method can look up links by examining the ALT text, or the <CODE>HttpUnitOptions.setImagesTreatedAsAltText</CODE> method can cause ALT text to be treated as -ordinary searchable text. +ordinary searchable text. <H2>Using the table structure of a web page</H2> -Many web designers make heavy use of tables to control the page formatting. You can take advantage of this by looking +Many web designers make heavy use of tables to control the page formatting. You can take advantage of this by looking at the tables in the page as discrete elements. The :<CODE>getTables()</CODE> method will return an array of the top-level -tables in the page (that is, those which are not nested within other tables), in the order in which they appear in the +tables in the page (that is, those which are not nested within other tables), in the order in which they appear in the document. Given a table, you can ask for one of its cells, and treat the result either as text or a DOM or ask for and tables, links, or forms nested within it. For example, the following code will confirm that the first table in the page has 4 rows and 3 columns, and that there is a single link in the last cell of the first row: @@ -82,10 +82,10 @@ <H2>Working with forms</H2> <P>A dynamic web site tends to have many html forms, each of which contains various kinds of controls: text boxes, pull-down menus, -radio buttons, and so on. The HTML for these controls vary widely; however, the intent is roughly the same, so HttpUnit +radio buttons, and so on. The HTML for these controls vary widely; however, the intent is roughly the same, so HttpUnit makes them look the same.</P> -<P>There are a few basic things that a tester is likely to want to do with a form. The most obvious first step is to verify the +<P>There are a few basic things that a tester is likely to want to do with a form. The most obvious first step is to verify the controls and their default values; if they are correct, the tester will generally make some changes and submit the form to see how the system responds. HttpUnit makes both tasks easy.</P> @@ -113,22 +113,22 @@ </PRE> Note that all controls are treated alike, with the exception of the checkbox. -<P>Simulating the submission of the form will involve asking the WebConversation for a response to a request which was -defined by the form, possibly modifying the form parameters beforehand. For example, to correct the restaurant type and +<P>Simulating the submission of the form can be done most simply by obtaining the form object and calling its 'submit' +method, possibly modifying the form parameters beforehand. For example, to correct the restaurant type and indicate that it does not accept credit cards: -<PRE> request = form.getRequest(); - request.setParameter( "Food", "Italian" ); - request.removeParameter( "CreditCard" ); - response = wc.getResponse( request ); +<PRE> form.setParameter( "Food", "Italian" ); // select one of the permitted values for food + form.removeParameter( "CreditCard" ); // clear the check box + form.submit(); // submit the form </PRE> -And of course the test would then proceed to examine the response to this submission as well. +And of course the test could then proceed to examine the response to this submission as well, +obtaining it from <code>wc.getCurrentPage()</code>. <H2>Working with frames</H2> <P>Without frames, web interaction tends to be straightforward and sequential. There is one current active page at a time, and each new page replaces the old one that referenced it. Frames change that, allowing multiple active pages simultaneously, and allowing for the possibility that a link from one active page could result in the replacement of a different page.</P> -<P>HttpUnit supports frames by providing methods on the WebConversation class to examine those frames +<P>HttpUnit supports frames by providing methods on the WebConversation class to examine those frames which are currently active. Each response replaces the contents of the appropriate frame, which is not necessarily the topmost frame ("_top"). In the following scenation, there are two active subframes, named "overview" and "details": @@ -136,14 +136,13 @@ WebResponse top = wc.getResponse( "http://www.meterware.com/Frames.html" ); // read a page with two frames WebResponse summary = wc.getFrameContents( "summary" ); // read the summary frame WebLink link = summary.getLinkWith( "Cake Recipe" ); // find the link (which targets "details" ); - WebResponse details = wc.getResponse( link.getRequest() ); // retrieve the referenced page + link.click(); // click on it WebResponse response= wc.getFrameContents( "details" ); // retrieve the details frame </CODE></PRE> -At the end of this sequence, <CODE>details</CODE> and <CODE>response</CODE> should point to the same object. </BODY> </HTML> - + Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.125 retrieving revision 1.126 diff -u -r1.125 -r1.126 --- release_notes.txt 2 Aug 2002 16:26:15 -0000 1.125 +++ release_notes.txt 5 Aug 2002 15:21:19 -0000 1.126 @@ -12,6 +12,12 @@ Revision History: + 5-Aug-2002 +Additions: + 1. The JavaScript link.href attribute is now readable. +Problems fixed: + A form request created after a call to getScriptableObject().setAction() now correctly uses the new action. + 2-Aug-2002 Additions: 1. Added JavaScript support for document.links and document.<link name> and the link 'onMouseOver' event. |