httpunit-commit Mailing List for httpunit (Page 79)
Brought to you by:
russgold
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
From: Russell G. <rus...@us...> - 2000-10-12 16:16:40
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv20697/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java PseudoServerTest.java Log Message: Added redirect delay, responseCode methods Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- HttpUnitSuite.java 2000/10/02 16:32:10 1.7 +++ HttpUnitSuite.java 2000/10/12 16:16:36 1.8 @@ -44,6 +44,7 @@ suite.addTest( RequestTargetTest.suite() ); suite.addTest( FormParametersTest.suite() ); suite.addTest( Base64Test.suite() ); + suite.addTest( PseudoServerTest.suite() ); return suite; } Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PseudoServerTest.java 2000/09/27 18:04:04 1.1 +++ PseudoServerTest.java 2000/10/12 16:16:36 1.2 @@ -24,6 +24,7 @@ import junit.framework.TestSuite; import com.meterware.httpunit.*; +import java.net.HttpURLConnection; /** * Tests the basic authentication. @@ -55,6 +56,7 @@ WebResponse response = wc.getResponse( request ); fail( "Should have rejected the request" ); } catch (HttpNotFoundException e) { + assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() ); } } |
From: Russell G. <rus...@us...> - 2000-10-12 16:16:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv20697/src/com/meterware/httpunit Modified Files: HttpInternalErrorException.java HttpNotFoundException.java HttpUnitOptions.java WebConversation.java WebResponse.java package.html Added Files: HttpException.java Log Message: Added redirect delay, responseCode methods ***** Error reading new file(2, 'No such file or directory') Index: HttpInternalErrorException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpInternalErrorException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpInternalErrorException.java 2000/09/13 20:42:36 1.1 +++ HttpInternalErrorException.java 2000/10/12 16:16:35 1.2 @@ -19,19 +19,18 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.util.Properties; -import java.io.*; +import java.net.HttpURLConnection; /** * This exception is thrown when an internal error is found on the server. * @author Seth Ladd **/ -public class HttpInternalErrorException extends RuntimeException { +public class HttpInternalErrorException extends HttpException { HttpInternalErrorException( String url ) { - super( url ); + super( HttpURLConnection.HTTP_INTERNAL_ERROR, url ); } Index: HttpNotFoundException.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpNotFoundException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpNotFoundException.java 2000/09/13 20:42:36 1.1 +++ HttpNotFoundException.java 2000/10/12 16:16:35 1.2 @@ -19,8 +19,7 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.util.Properties; -import java.io.*; +import java.net.HttpURLConnection; /** @@ -28,11 +27,11 @@ * @author Seth Ladd * @author Russell Gold **/ -public class HttpNotFoundException extends RuntimeException { +public class HttpNotFoundException extends HttpException { HttpNotFoundException( String url ) { - super( url ); + super( HttpURLConnection.HTTP_NOT_FOUND, url ); } Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HttpUnitOptions.java 2000/10/11 19:15:11 1.3 +++ HttpUnitOptions.java 2000/10/12 16:16:35 1.4 @@ -96,6 +96,25 @@ } + /** + * Returns the delay, in milliseconds, before a redirect request is issues. + **/ + public static int getRedirectDelay() { + return _redirectDelay; + } + + + /** + * Sets the delay, in milliseconds, before a redirect request is issued. This may be necessary if the server + * under some cases where the server performs asynchronous processing which must be completed before the + * new request can be handled properly, and is taking advantage of slower processing by most user agents. It + * almost always indicates an error in the server design, and therefore the default delay is zero. + **/ + public static void setRedirectDelay( int delayInMilliseconds ) { + _redirectDelay = delayInMilliseconds; + } + + //--------------------------------- private members -------------------------------------- @@ -106,6 +125,8 @@ private static boolean _imagesTreatedAsAltText; private static boolean _loggingHttpHeaders; + + private static int _redirectDelay; } Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- WebConversation.java 2000/10/11 19:15:11 1.15 +++ WebConversation.java 2000/10/12 16:16:35 1.16 @@ -87,6 +87,7 @@ updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { + delay( HttpUnitOptions.getRedirectDelay() ); return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else if (connection.getHeaderField( "WWW-Authenticate" ) != null) { throw new AuthorizationRequiredException( connection.getHeaderField( "WWW-Authenticate" ) ); @@ -94,6 +95,8 @@ throw new HttpInternalErrorException( request.getURLString() ); } else if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HttpNotFoundException( request.getURLString() ); + } else if (connection.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) { + throw new HttpException( connection.getResponseCode(), request.getURLString() ); } else { WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); if (result.isHTML()) { @@ -104,6 +107,16 @@ for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); } return result; + } + } + + + private void delay( int numMilliseconds ) { + if (numMilliseconds == 0) return; + try { + Thread.sleep( numMilliseconds ); + } catch (InterruptedException e) { + // ignore the exception } } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- WebResponse.java 2000/10/11 19:15:11 1.19 +++ WebResponse.java 2000/10/12 16:16:35 1.20 @@ -41,6 +41,14 @@ /** + * Returns the response code associated with this response. + **/ + public int getResponseCode() { + return _responseCode; + } + + + /** * Returns the URL which invoked this response. **/ public URL getURL() { @@ -249,6 +257,8 @@ private String _characterSet = "us-ascii"; + private int _responseCode; + final private URL _url; final private WebConversation _conversation; @@ -323,6 +333,10 @@ private void readHeaders( URLConnection connection ) { readContentTypeHeader( connection ); + try { + _responseCode = ((HttpURLConnection) connection).getResponseCode(); + } catch (IOException e) { + } } Index: package.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/package.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- package.html 2000/10/05 14:45:14 1.2 +++ package.html 2000/10/12 16:16:35 1.3 @@ -8,7 +8,7 @@ requests based on either submitting a form or clicking on a link. <H2>Installation</H2> -The package depends on <A HREF="http://httpunit.sourceforge.net/Tidy.jar.zip">JTidy</A> by Andy Quick. +The package depends on <A HREF="http://httpunit.sourceforge.net/Tidy.jar.zip">JTidy</A>, created by Andy Quick. The jtidy.jar must be in the class path ahead of any other implementation of the DOM classes. In addition, unit tests will require <A HREF=http://www.xprogramming.com/ftp/TestingFramework/JUnit/junit32.zip>JUnit</A> as well. |
From: Russell G. <rus...@us...> - 2000-10-12 16:16:39
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv20697/doc Modified Files: release_notes.txt Log Message: Added redirect delay, responseCode methods Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- release_notes.txt 2000/10/11 19:15:10 1.3 +++ release_notes.txt 2000/10/12 16:16:35 1.4 @@ -14,6 +14,11 @@ Thanks to Ken Hygh for the proper handling of parameters with no specified type Revision History: +Additions: + 1. It is now possible to set a delay in the handling of redirect requests, if necessary + 2. The WebResponse now can return the response code associated with it (2xx) + 3. An exception (HttpException or a subclass) is now thrown on all client and server errors (4xx or 5xx) + Problems corrected: 1. Unnamed frames are now handled |
From: Russell G. <rus...@us...> - 2000-10-12 16:16:39
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv20697 Modified Files: index.html Log Message: Added redirect delay, responseCode methods Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- index.html 2000/09/26 13:38:09 1.7 +++ index.html 2000/10/12 16:16:35 1.8 @@ -34,7 +34,10 @@ <var:dist> from the <a href="http://httpunit.sourceforge.net"><var:dist> HttpUnit home page</A> <var:publish as a <a href="http://httpunit.sourceforge.net/httpunit_<version>.zip"><var:publish zip file</A> .<var:publish <br><var:publish Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"> -<var:publish anonymous ftp</a>.</blockquote> +<var:publish anonymous ftp</a>. +<b><var:publish Note: Andy Quick has dropped support for JTidy, a library on which HttpUnit depends. I am investigating the situation. +For now, you may download it from <a href="Tidy.jar.zip"><var:publish this site</a></b>. +</blockquote> <h2>How do I contribute, give feedback, fix bugs and so on?</h2> <ul> |
From: Russell G. <rus...@us...> - 2000-10-11 19:15:17
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv2316/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java WebConversation.java WebRequest.java WebResponse.java Added Files: WebFrame.java Log Message: Support unnamed frames, controlled logging of headers Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpUnitOptions.java 2000/10/02 16:32:10 1.2 +++ HttpUnitOptions.java 2000/10/11 19:15:11 1.3 @@ -80,6 +80,22 @@ } + /** + * Returns true if HTTP headers are to be dumped to system output. + **/ + public static boolean isLoggingHttpHeaders() { + return _loggingHttpHeaders; + } + + + /** + * If true, tells HttpUnit to log HTTP headers to system output. The default is false. + **/ + public static void setLoggingHttpHeaders( boolean enabled ) { + _loggingHttpHeaders = enabled; + } + + //--------------------------------- private members -------------------------------------- @@ -88,6 +104,8 @@ private static boolean _parameterValuesValidated = true; private static boolean _imagesTreatedAsAltText; + + private static boolean _loggingHttpHeaders; } Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WebConversation.java 2000/10/06 18:38:54 1.14 +++ WebConversation.java 2000/10/11 19:15:11 1.15 @@ -245,6 +245,9 @@ for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; + if (HttpUnitOptions.isLoggingHttpHeaders()) { + System.out.println( "Header:: " + connection.getHeaderFieldKey( i ) + ": " + connection.getHeaderField(i) ); + } if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebRequest.java 2000/10/02 16:31:36 1.7 +++ WebRequest.java 2000/10/11 19:15:11 1.8 @@ -246,10 +246,12 @@ private void validateProtocol( String urlString ) { - String protocol = urlString.substring( 0, urlString.indexOf( ':' ) ); - if (protocol.length() == 0) { + if (urlString.indexOf(':') <= 0) { throw new RuntimeException( "No protocol specified in URL '" + urlString + "'" ); - } else if (protocol.equalsIgnoreCase( "http" )) { + } + + String protocol = urlString.substring( 0, urlString.indexOf( ':' ) ); + if (protocol.equalsIgnoreCase( "http" )) { return; } else if (protocol.equalsIgnoreCase( "https" )) { validateHttpsProtocolSupport(); Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- WebResponse.java 2000/10/06 18:38:54 1.18 +++ WebResponse.java 2000/10/11 19:15:11 1.19 @@ -84,10 +84,10 @@ * Returns the names of the frames found in the page in the order in which they appear. **/ public String[] getFrameNames() throws SAXException { - NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - String[] result = new String[ frames.getLength() ]; + WebFrame[] frames = getFrames(); + String[] result = new String[ frames.length ]; for (int i = 0; i < result.length; i++) { - result[i] = NodeUtils.getNodeAttribute( frames.item(i), "name" ); + result[i] = frames[i].getName(); } return result; @@ -95,26 +95,6 @@ /** - * Returns the frames found in the page in the order in which they appear. - **/ - public WebRequest[] getFrameRequests() throws SAXException { - NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - Vector requests = new Vector(); - for (int i = 0; i < frames.getLength(); i++) { - if (NodeUtils.getNodeAttribute( frames.item(i), "src" ).length() > 0) { - requests.addElement( new GetMethodWebRequest( getReceivedPage().getBaseURL(), - NodeUtils.getNodeAttribute( frames.item(i), "src" ), - NodeUtils.getNodeAttribute( frames.item(i), "name" ) ) ); - } - } - - WebRequest[] result = new WebRequest[ requests.size() ]; - requests.copyInto( result ); - return result; - } - - - /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ @@ -232,6 +212,24 @@ } + /** + * Returns the frames found in the page in the order in which they appear. + **/ + WebRequest[] getFrameRequests() throws SAXException { + WebFrame[] frames = getFrames(); + Vector requests = new Vector(); + for (int i = 0; i < frames.length; i++) { + if (frames[i].hasInitialRequest()) { + requests.addElement( frames[i].getInitialRequest() ); + } + } + + WebRequest[] result = new WebRequest[ requests.size() ]; + requests.copyInto( result ); + return result; + } + + //--------------------------------- private members -------------------------------------- @@ -241,6 +239,8 @@ final private static String HTML_CONTENT = "text/html"; + private WebFrame[] _frames; + private ReceivedPage _page; private String _responseText; @@ -293,6 +293,22 @@ } catch (IOException e) { throw new RuntimeException( "Unable to retrieve data from URL: " + url.toExternalForm() + " (" + e + ")" ); } + } + + + private WebFrame[] getFrames() throws SAXException { + if (_frames == null) { + NodeList nl = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); + Vector list = new Vector(); + for (int i = 0; i < nl.getLength(); i++) { + Node child = nl.item(i); + list.addElement( new WebFrame( getReceivedPage().getBaseURL(), child ) ); + } + _frames = new WebFrame[ list.size() ]; + list.copyInto( _frames ); + } + + return _frames; } |
From: Russell G. <rus...@us...> - 2000-10-11 19:15:16
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv2316/test/com/meterware/httpunit Modified Files: WebFrameTest.java Log Message: Support unnamed frames, controlled logging of headers Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebFrameTest.java 2000/10/05 14:45:14 1.3 +++ WebFrameTest.java 2000/10/11 19:15:11 1.4 @@ -98,6 +98,64 @@ } + public void testFrameURLBase() throws Exception { + defineWebPage( "Deeper/Linker", "This is a trivial page with <a href=Target.html>one link</a>" ); + defineWebPage( "Deeper/Target", "This is another page with <a href=Form.html target=\"_top\">one link</a>" ); + defineWebPage( "Deeper/Form", "This is a page with a simple form: " + + "<form action=submit><input name=name><input type=submit></form>" + + "<a href=Linker.html target=red>a link</a>"); + defineResource( "Frames.html", + "<HTML><HEAD><TITLE>Initial</TITLE>" + + "<base href=\"" + getHostPath() + "/Deeper/Frames.html\"></HEAD>" + + "<FRAMESET cols=\"20%,80%\">" + + " <FRAME src=\"Linker.html\" name=\"red\">" + + " <FRAME src=Form.html name=blue>" + + "</FRAMESET></HTML>" ); + + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "URL for second request", getHostPath() + "/Deeper/Target.html", response.getURL().toExternalForm() ); + } + + + public void testUnnamedFrames() throws Exception { + defineWebPage( "Linker", "This is a trivial page with <a href=Target.html>one link</a>" ); + defineWebPage( "Target", "This is another page with <a href=Form.html target=\"_top\">one link</a>" ); + defineWebPage( "Form", "This is a page with a simple form: " + + "<form action=submit><input name=name><input type=submit></form>" + + "<a href=Linker.html target=red>a link</a>"); + defineResource( "Frames.html", + "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + + "<FRAMESET cols=\"20%,80%\">" + + " <FRAME src=\"Linker.html\">" + + " <FRAME src=Form.html>" + + "</FRAMESET></HTML>" ); + + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + WebResponse linker = getFrameWithURL( _wc, "Linker" ); + assertNotNull( "Linker not found", linker ); + + response = _wc.getResponse( linker.getLinks()[0].getRequest() ); + WebResponse target = getFrameWithURL( _wc, "Target" ); + assert( "Second response not the same as source frame contents", response == target ); + } + + + private WebResponse getFrameWithURL( WebConversation wc, String urlString ) { + String[] names = wc.getFrameNames(); + for (int i = 0; i < names.length; i++) { + WebResponse candidate = wc.getFrameContents( names[i] ); + if (candidate.getURL().toExternalForm().indexOf( urlString ) >= 0) { + return candidate; + } + } + return null; + } + + public void testCrossFrameLinks() throws Exception { WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); @@ -142,6 +200,17 @@ WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); + } + + + public void notestParentTarget() throws Exception { + defineWebPage( "Linker", "This is a trivial page with <a href=Target.html target=_parent>one link</a>" ); + + _wc.getResponse( getHostPath() + "/Frames.html" ); + WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); } |
From: Russell G. <rus...@us...> - 2000-10-11 19:15:15
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv2316/doc Modified Files: release_notes.txt Log Message: Support unnamed frames, controlled logging of headers Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- release_notes.txt 2000/10/06 14:52:53 1.2 +++ release_notes.txt 2000/10/11 19:15:10 1.3 @@ -1,19 +1,22 @@ HttpUnit release notes Known problems: - 1. Unnamed frames are not handled correctly - 2. The "_parent" and "_empty" targets are not handled correctly + 1. The "_parent" and "_empty" frame targets are not handled correctly + 2. The "_self" target only works for links Limitations: HttpUnit does not support JavaScript Acknowledgements: Thanks to Seth Ladd for specific exceptions from WebConversation.getResponse Thanks to Dave Glowacki for suggestions on convenience methods in WebResponse and WebLink, - and for correcting my set up of the https protocol handling. + and for correcting the set up of the https protocol handling. Thanks to Perry Doell for the methods to examine cookies on WebConversation Thanks to Ken Hygh for the proper handling of parameters with no specified type Revision History: +Problems corrected: + 1. Unnamed frames are now handled + 6-Oct-00 Problems corrected: 1. Base tag is now handled to override defaults for page URL and target |
From: Russell G. <rus...@us...> - 2000-10-06 18:39:00
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv3868/src/com/meterware/httpunit Modified Files: ParsedHTML.java WebConversation.java WebResponse.java Log Message: Make base tag work for frames Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ParsedHTML.java 2000/10/06 14:52:53 1.7 +++ ParsedHTML.java 2000/10/06 18:38:54 1.8 @@ -170,6 +170,17 @@ } +//---------------------------------- package members -------------------------------- + + + /** + * Returns the base URL for this HTML segment. + **/ + URL getBaseURL() { + return _baseURL; + } + + //---------------------------------- private members -------------------------------- private Node _rootNode; Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WebConversation.java 2000/10/05 14:45:14 1.13 +++ WebConversation.java 2000/10/06 18:38:54 1.14 @@ -96,11 +96,13 @@ throw new HttpNotFoundException( request.getURLString() ); } else { WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); - removeSubFrames( request.getTarget() ); - _frameContents.put( request.getTarget(), result ); - createSubFrames( request.getTarget(), result.getFrameNames() ); - WebRequest[] requests = result.getFrameRequests(); - for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); + if (result.isHTML()) { + removeSubFrames( request.getTarget() ); + _frameContents.put( request.getTarget(), result ); + createSubFrames( request.getTarget(), result.getFrameNames() ); + WebRequest[] requests = result.getFrameRequests(); + for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); + } return result; } } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- WebResponse.java 2000/10/05 14:45:14 1.17 +++ WebResponse.java 2000/10/06 18:38:54 1.18 @@ -33,6 +33,14 @@ /** + * Returns true if the response is HTML. + **/ + public boolean isHTML() { + return _contentType.equals( HTML_CONTENT ); + } + + + /** * Returns the URL which invoked this response. **/ public URL getURL() { @@ -94,7 +102,7 @@ Vector requests = new Vector(); for (int i = 0; i < frames.getLength(); i++) { if (NodeUtils.getNodeAttribute( frames.item(i), "src" ).length() > 0) { - requests.addElement( new GetMethodWebRequest( this.getURL(), + requests.addElement( new GetMethodWebRequest( getReceivedPage().getBaseURL(), NodeUtils.getNodeAttribute( frames.item(i), "src" ), NodeUtils.getNodeAttribute( frames.item(i), "name" ) ) ); } @@ -230,6 +238,9 @@ final private static String endOfLine = System.getProperty( "line.separator" ); + + final private static String HTML_CONTENT = "text/html"; + private ReceivedPage _page; private String _responseText; @@ -250,7 +261,7 @@ **/ private WebResponse( String responseText ) { this( null, "", null, responseText ); - _contentType = "text/html"; + _contentType = HTML_CONTENT; } @@ -287,7 +298,7 @@ private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { - if (!_contentType.equals( "text/html" )) throw new RuntimeException( "Response is not HTML" ); + if (!isHTML()) throw new RuntimeException( "Response is not HTML" ); _page = new ReceivedPage( _url, _target, _responseText ); } return _page; |
From: Russell G. <rus...@us...> - 2000-10-06 14:52:58
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv7904/src/com/meterware/httpunit Modified Files: ParsedHTML.java ReceivedPage.java Log Message: support base tag Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ParsedHTML.java 2000/10/02 16:32:10 1.6 +++ ParsedHTML.java 2000/10/06 14:52:53 1.7 @@ -30,10 +30,10 @@ class ParsedHTML { - ParsedHTML( URL pageURL, String parentTarget, Node rootNode ) { - _url = pageURL; - _rootNode = rootNode; - _parentTarget = parentTarget; + ParsedHTML( URL baseURL, String baseTarget, Node rootNode ) { + _baseURL = baseURL; + _baseTarget = baseTarget; + _rootNode = rootNode; } @@ -44,7 +44,7 @@ NodeList forms = NodeUtils.getElementsByTagName( _rootNode, "form" ); WebForm[] result = new WebForm[ forms.getLength() ]; for (int i = 0; i < result.length; i++) { - result[i] = new WebForm( getURL(), _parentTarget, forms.item( i ) ); + result[i] = new WebForm( _baseURL, _baseTarget, forms.item( i ) ); } return result; @@ -61,7 +61,7 @@ for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i); if (isLinkAnchor( child )) { - list.addElement( new WebLink( getURL(), _parentTarget, child ) ); + list.addElement( new WebLink( _baseURL, _baseTarget, child ) ); } } _links = new WebLink[ list.size() ]; @@ -110,7 +110,7 @@ * they appear. **/ public WebTable[] getTables() { - return WebTable.getTables( getDOM(), _url, _parentTarget ); + return WebTable.getTables( getDOM(), _baseURL, _baseTarget ); } @@ -142,33 +142,43 @@ } - /** - * Returns the associated URL. - **/ - public URL getURL() { - return _url; +//---------------------------------- Object methods -------------------------------- + + + public String toString() { + return _baseURL.toExternalForm() + System.getProperty( "line.separator" ) + + _rootNode; } +//---------------------------------- protected members ------------------------------ -//---------------------------------- Object methods -------------------------------- + /** + * Overrides the base URL for this HTML segment. + **/ + protected void setBaseURL( URL baseURL ) { + _baseURL = baseURL; + } - public String toString() { - return _url.toExternalForm() + System.getProperty( "line.separator" ) + - _rootNode; + + /** + * Overrides the base target for this HTML segment. + **/ + protected void setBaseTarget( String baseTarget ) { + _baseTarget = baseTarget; } //---------------------------------- private members -------------------------------- - Node _rootNode; + private Node _rootNode; - WebLink[] _links; + private WebLink[] _links; - URL _url; + private URL _baseURL; - private String _parentTarget; + private String _baseTarget; private String getValue( Node node ) { Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ReceivedPage.java 2000/10/02 16:32:10 1.7 +++ ReceivedPage.java 2000/10/06 14:52:53 1.8 @@ -21,6 +21,7 @@ *******************************************************************************************************************/ import java.io.ByteArrayInputStream; +import java.net.MalformedURLException; import java.net.URL; import java.util.Vector; @@ -39,7 +40,8 @@ public ReceivedPage( URL url, String parentTarget, String pageText ) throws SAXException { - super( url, parentTarget, getParser().parseDOM( new ByteArrayInputStream( pageText.getBytes() ), null ) ); + super( url, parentTarget, getParser().parseDOM( new ByteArrayInputStream( pageText.getBytes() ), null ) ); + setBaseAttributes(); } @@ -55,6 +57,28 @@ //---------------------------------- private members -------------------------------- + + + private void setBaseAttributes() throws SAXException { + NodeList nl = ((Document) getDOM()).getElementsByTagName( "base" ); + if (nl.getLength() == 0) return; + try { + applyBaseAttributes( NodeUtils.getNodeAttribute( nl.item(0), "href" ), + NodeUtils.getNodeAttribute( nl.item(0), "target" ) ); + } catch (MalformedURLException e) { + throw new RuntimeException( "Unable to set document base: " + e ); + } + } + + + private void applyBaseAttributes( String baseURLString, String baseTarget ) throws MalformedURLException { + if (baseURLString.length() > 0) { + this.setBaseURL( new URL( baseURLString ) ); + } + if (baseTarget.length() > 0) { + this.setBaseTarget( baseTarget ); + } + } private static Tidy getParser() { |
From: Russell G. <rus...@us...> - 2000-10-06 14:52:57
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv7904/doc Modified Files: release_notes.txt Log Message: support base tag Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- release_notes.txt 2000/10/05 14:45:13 1.1 +++ release_notes.txt 2000/10/06 14:52:53 1.2 @@ -14,6 +14,10 @@ Thanks to Ken Hygh for the proper handling of parameters with no specified type Revision History: + 6-Oct-00 +Problems corrected: + 1. Base tag is now handled to override defaults for page URL and target + 5-Oct-00 Problems corrected: 1. Blank "src" attributes in FRAME nodes now correctly result in a blank page |
From: Russell G. <rus...@us...> - 2000-10-06 14:52:57
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv7904/test/com/meterware/httpunit Modified Files: WebLinkTest.java Log Message: support base tag Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebLinkTest.java 2000/10/02 16:32:10 1.6 +++ WebLinkTest.java 2000/10/06 14:52:53 1.7 @@ -141,7 +141,41 @@ assertEquals( "Title of next page", "Initial", thirdPage.getTitle() ); } + + public void testDocumentBase() throws Exception { + WebConversation wc = new WebConversation(); + defineWebPage( "alternate/Target", "Found me!" ); + defineResource( "Initial.html", "<html><head><title>Test for Base</title>" + + " <base href=\"" + getHostPath() + "/alternate/\"></head>" + + " <body><a href=\"Target.html\">Go</a></body></html>" ); + + WebResponse initialPage = wc.getResponse( getHostPath() + "/Initial.html" ); + assertEquals( "Num links in initial page", 1, initialPage.getLinks().length ); + WebLink link = initialPage.getLinks()[0]; + + WebRequest request = link.getRequest(); + assertEquals( "Destination for link", getHostPath() + "/alternate/Target.html", request.getURL().toExternalForm() ); + WebResponse nextPage = wc.getResponse( request ); + assert( "Did not find the target", nextPage.toString().indexOf( "Found" ) >= 0 ); + } + + public void testTargetBase() throws Exception { + WebConversation wc = new WebConversation(); + defineWebPage( "alternate/Target", "Found me!" ); + defineResource( "Initial.html", "<html><head><title>Test for Base</title>" + + " <base target=blue></head>" + + " <body><a href=\"Target.html\">Go</a></body></html>" ); + + WebResponse initialPage = wc.getResponse( getHostPath() + "/Initial.html" ); + assertEquals( "Num links in initial page", 1, initialPage.getLinks().length ); + WebLink link = initialPage.getLinks()[0]; + + WebRequest request = link.getRequest(); + assertEquals( "Target for link", "blue", request.getTarget() ); + } + + private WebResponse _simplePage; |
From: Russell G. <rus...@us...> - 2000-10-05 14:45:18
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv20163/src/com/meterware/httpunit Modified Files: WebConversation.java WebLink.java WebResponse.java package.html Log Message: Corrected handling of blank frames Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebConversation.java 2000/10/04 15:45:47 1.12 +++ WebConversation.java 2000/10/05 14:45:14 1.13 @@ -98,10 +98,18 @@ WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); removeSubFrames( request.getTarget() ); _frameContents.put( request.getTarget(), result ); - _subFrames.put( request.getTarget(), result.getFrameNames() ); + createSubFrames( request.getTarget(), result.getFrameNames() ); WebRequest[] requests = result.getFrameRequests(); for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); return result; + } + } + + + private void createSubFrames( String targetName, String[] frameNames ) { + _subFrames.put( targetName, frameNames ); + for (int i = 0; i < frameNames.length; i++) { + _frameContents.put( frameNames[i], WebResponse.BLANK_RESPONSE ); } } Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebLink.java 2000/10/02 16:32:10 1.4 +++ WebLink.java 2000/10/05 14:45:14 1.5 @@ -36,11 +36,18 @@ * Returns the target for this link. **/ public String getTarget() { - if (_node.getAttributes().getNamedItem( "target" ) == null) { + if (getSpecifiedTarget().length() == 0) { return _parentTarget; + } else if (getSpecifiedTarget().equalsIgnoreCase( "_self" )) { + return _parentTarget; } else { - return getValue( _node.getAttributes().getNamedItem( "target" ) ); + return getSpecifiedTarget(); } + } + + + private String getSpecifiedTarget() { + return NodeUtils.getNodeAttribute( _node, "target" ); } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- WebResponse.java 2000/10/04 15:45:47 1.16 +++ WebResponse.java 2000/10/05 14:45:14 1.17 @@ -22,7 +22,7 @@ import java.io.*; import java.net.*; -import java.util.StringTokenizer; +import java.util.*; import org.xml.sax.*; import org.w3c.dom.*; @@ -91,13 +91,17 @@ **/ public WebRequest[] getFrameRequests() throws SAXException { NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - WebRequest[] result = new WebRequest[ frames.getLength() ]; - for (int i = 0; i < result.length; i++) { - result[i] = new GetMethodWebRequest( this.getURL(), - NodeUtils.getNodeAttribute( frames.item(i), "src" ), - NodeUtils.getNodeAttribute( frames.item(i), "name" ) ); + Vector requests = new Vector(); + for (int i = 0; i < frames.getLength(); i++) { + if (NodeUtils.getNodeAttribute( frames.item(i), "src" ).length() > 0) { + requests.addElement( new GetMethodWebRequest( this.getURL(), + NodeUtils.getNodeAttribute( frames.item(i), "src" ), + NodeUtils.getNodeAttribute( frames.item(i), "name" ) ) ); + } } + WebRequest[] result = new WebRequest[ requests.size() ]; + requests.copyInto( result ); return result; } @@ -196,6 +200,9 @@ //---------------------------------- package members -------------------------------- + final static WebResponse BLANK_RESPONSE = new WebResponse( "<html><head></head><body></body></html>" ); + + /** * Constructs a response object from an input stream. * @param conversation the web conversation which received the response @@ -203,23 +210,8 @@ * @param inputStream the input stream from which the response can be read **/ WebResponse( WebConversation conversation, String target, URL url, URLConnection connection ) { - _conversation = conversation; - _url = url; - _target = target; - StringBuffer sb = new StringBuffer(); - try { - BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); - - String str; - while (null != ((str = input.readLine()))) { - sb.append( str ).append( endOfLine ); - } - input.close (); - _responseText = sb.toString(); - readHeaders( connection ); - } catch (IOException e) { - throw new RuntimeException( "Unable to retrieve data from URL: " + _url.toExternalForm() + " (" + e + ")" ); - } + this( conversation, target, url, getResponseText( url, connection ) ); + readHeaders( connection ); } @@ -235,6 +227,7 @@ //--------------------------------- private members -------------------------------------- + final private static String endOfLine = System.getProperty( "line.separator" ); private ReceivedPage _page; @@ -250,6 +243,46 @@ final private WebConversation _conversation; final private String _target; + + + /** + * Constructs a response object from a text response. + **/ + private WebResponse( String responseText ) { + this( null, "", null, responseText ); + _contentType = "text/html"; + } + + + /** + * Constructs a response object. + * @param conversation the web conversation which received the response + * @param url the url from which the response was received + * @param inputStream the input stream from which the response can be read + **/ + private WebResponse( WebConversation conversation, String target, URL url, String responseText ) { + _conversation = conversation; + _url = url; + _target = target; + _responseText = responseText; + } + + + private static String getResponseText( URL url, URLConnection connection ) { + StringBuffer sb = new StringBuffer(); + try { + BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); + + String str; + while (null != ((str = input.readLine()))) { + sb.append( str ).append( endOfLine ); + } + input.close (); + return sb.toString(); + } catch (IOException e) { + throw new RuntimeException( "Unable to retrieve data from URL: " + url.toExternalForm() + " (" + e + ")" ); + } + } private ReceivedPage getReceivedPage() throws SAXException { Index: package.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/package.html,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- package.html 2000/06/12 13:09:26 1.1.1.1 +++ package.html 2000/10/05 14:45:14 1.2 @@ -8,7 +8,7 @@ requests based on either submitting a form or clicking on a link. <H2>Installation</H2> -The package depends on <A HREF="http://www3.sympatico.ca/ac.quick/jtidy.html">JTidy</A> by Andy Quick. +The package depends on <A HREF="http://httpunit.sourceforge.net/Tidy.jar.zip">JTidy</A> by Andy Quick. The jtidy.jar must be in the class path ahead of any other implementation of the DOM classes. In addition, unit tests will require <A HREF=http://www.xprogramming.com/ftp/TestingFramework/JUnit/junit32.zip>JUnit</A> as well. |
From: Russell G. <rus...@us...> - 2000-10-05 14:45:18
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv20163/test/com/meterware/httpunit Modified Files: WebFrameTest.java Log Message: Corrected handling of blank frames Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebFrameTest.java 2000/10/04 15:45:47 1.2 +++ WebFrameTest.java 2000/10/05 14:45:14 1.3 @@ -120,5 +120,31 @@ } + public void testEmptyFrame() throws Exception { + defineResource( "HalfFrames.html", + "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + + "<FRAMESET cols=\"20%,80%\">" + + " <FRAME src=\"Linker.html\" name=\"red\">" + + " <FRAME name=blue>" + + "</FRAMESET></HTML>" ); + _wc.getResponse( getHostPath() + "/HalfFrames.html" ); + WebResponse response = _wc.getFrameContents( "blue" ); + + assertNotNull( "Loaded nothing for the empty frame", response ); + assertEquals( "Num links", 0, response.getLinks().length ); + } + + + public void testSelfTarget() throws Exception { + defineWebPage( "Linker", "This is a trivial page with <a href=Target.html target=_self>one link</a>" ); + + _wc.getResponse( getHostPath() + "/Frames.html" ); + WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); + } + + private WebConversation _wc; } |
From: Russell G. <rus...@us...> - 2000-10-05 14:45:17
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv20163/doc Added Files: release_notes.txt Removed Files: release notes.txt Log Message: Corrected handling of blank frames --- NEW FILE --- HttpUnit release notes Known problems: 1. Unnamed frames are not handled correctly 2. The "_parent" and "_empty" targets are not handled correctly Limitations: HttpUnit does not support JavaScript Acknowledgements: Thanks to Seth Ladd for specific exceptions from WebConversation.getResponse Thanks to Dave Glowacki for suggestions on convenience methods in WebResponse and WebLink, and for correcting my set up of the https protocol handling. Thanks to Perry Doell for the methods to examine cookies on WebConversation Thanks to Ken Hygh for the proper handling of parameters with no specified type Revision History: 5-Oct-00 Problems corrected: 1. Blank "src" attributes in FRAME nodes now correctly result in a blank page 2. The "_self" target is now handled as the default target 4-Oct-00 Additions: 1. Frames are now supported. The WebConversation method has two methods: getFrameNames and getFrameContents which allow manipulation of frames. 2. Calling HttpUnitOptions.setImagesTreatedAsAltText( true ) will cause the ALT text in images to be treated as ordinary text Problems corrected: 1. It is no longer necessary to edit the java.security file to enable HTTPS support. Just install the JSSE jars in your classpath. 2. Parameters with no type specified are now properly handled as text 28-Sep-00 Additions: 1. PseudoServer class is now used by unit tests to handle requests. This will enable development of frames capability 2. Https support is now built in; however, it depends on the JSSE extension (not included). See http://java.sun.com/products/jsse and be careful to follow the installation instructions 25-Sep-00 Problems corrected: 1. In the 15-Sep build, the value parameter for checkboxes was ignored in computing defaults and validating parameter values - all checkboxes were assumed to have the value 'on' only 2. getTableStartingWith[Prefix] only checked the nested tables in cell (0,0) of each outer table Additions: 3. WebConversation now supports getCookieNames and getCookieValue to return the current cookies 15-Sep-00 General: 1. Non-breaking spaces are converted to spaces on any conversion to text 2. WebConversation.getResponse() can now throw HttpInternalErrorException and HttpNotFoundException in response to 501 and 404 codes, respectively 3. By default, parser warnings are no longer displayed. They may be enabled by a call to HttpUnitOptions.setParserWarningsEnabled( true ) 4. By default, WebRequest.setParameter will now throw IllegalRequestParameterException on any attempt to set a form parameter to a value not normally available from the browser. This checking can be disabled via a call to HttpUnitOptions.setParameterValuesValidated( false ) Additions: 1. WebResponse.getTitle() returns the HTML title of the page 2. WebLink.getURLString() returns the URL string specified by the link in its href attribute 3. The license agreement is now available from the home page and javadoc 4. WebResponse.getURL() return the URL used to retrieve the page 1-Sep-00 1.0 Acknowledgements: Thanks to Jan Ohrstrom for his additions to WebConversation Problems corrected: 1. Parsing a response would crash if there were no nodes inside a form Additions: 1. WebResponse.getOptions and getOptionValues now return the displayed and parameter value options available to the user in a <select> 2. WebRespose.getLinkWith() and .getLinkWithImageText() can now be used to locate a link in a page based on its text or the ALT text attribute of an enclosed image 3. WebConversation.setUserAgent allows httpunit to pretend to be a particular browser 4. WebConversation.addCookie allows the test to include additional cookies for the servlets to respond to. 5. WebLink.asText returns the text value of a link 6. WebConversation now throws AuthorizationRequiredException when the web server rejects a request because of authorization problems. 7. WebConversation now supports basic authentication via the setAuthorization method. 4-Aug-00 0.9.5 General: 1. Nested tables are now supported (examples to follow) by using WebTable.getTableCell 2. table columns and rows used only for formatting may now be ignored using WebTable.purgeEmptyCells 3. It is now easy to find a table in a page based on the text in its first non-blank column and row, using WebResponse.getTableStartingWith 4. All form controls should now be supported 5. There is a preliminary cookbook available Additions: 1. Deprecated WebTable.getCell, new method is getCellAsText 2. Added WebTable.getTableCell to return a cell which could contain nested tables or just a DOM to examine 3. Added WebTable.asText to return a 2D representation of the table 4. Added WebTable.purgeEmptyCells to eliminate meaningless spacing information 5. Added copyright notices to most source files 6. Added support for checkboxes, radio buttons, text areas, and selects 29-Jun-00 0.9.1 Additions: 1. The PostMethodWebRequest class is now public. 2. Row and column spans are now handled 3. Formatting inside table cells is ignored in computing the text value of a cell 19-Jun-00 0.9 Additions: 1. The parser may be tested during the build by issuing the command: 'ant test -Dclasspath="%classpath%"' 2. WebResponse now can return an array of the top-level tables in the HTML response. Each table may now be asked for its size and the contents of each of its cells. 5-Jun-00 0.8.2 Additions: WebResponse now has a getDOM method which permits examination of the DOM equivalent of the response. 1-Jun-00 0.8.1 Problems corrected: Default parameter values are ignored Parameter values without explicit types were being ignored, rather than defaulting to TEXT Additions: ExampleTest now demonstrates the use of httpunit and JUnit to test servlets NearWords demonstrates the use of httpunit to access web site functionality 03-May-00 0.8 Initial public release ***** Bogus filespec: release |
From: Russell G. <rus...@us...> - 2000-10-04 16:57:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv12531/src/com/meterware/httpunit Removed Files: WebFrame.java Log Message: Remove unnecessary file |
From: Russell G. <rus...@us...> - 2000-10-04 15:45:51
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv23587/test/com/meterware/httpunit Modified Files: WebFrameTest.java Log Message: Added frame support Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebFrameTest.java 2000/10/02 16:32:10 1.1 +++ WebFrameTest.java 2000/10/04 15:45:47 1.2 @@ -32,44 +32,93 @@ public void setUp() throws Exception { super.setUp(); _wc = new WebConversation(); - } - - public void testFrameNames() throws Exception { - defineResource( "Initial.html", + defineWebPage( "Linker", "This is a trivial page with <a href=Target.html>one link</a>" ); + defineWebPage( "Target", "This is another page with <a href=Form.html target=\"_top\">one link</a>" ); + defineWebPage( "Form", "This is a page with a simple form: " + + "<form action=submit><input name=name><input type=submit></form>" + + "<a href=Linker.html target=red>a link</a>"); + defineResource( "Frames.html", "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + "<FRAMESET cols=\"20%,80%\">" + - " <FRAMESET rows=\"30%,70%\">" + - " <FRAME src=\"overview-frame.html\" name=\"packageListFrame\">" + - " <FRAME src=allclasses-frame.html name=packageFrame>" + - " </FRAMESET>" + - " <FRAME src=\"overview-summary.html\" name=\"classFrame\">" + + " <FRAME src=\"Linker.html\" name=\"red\">" + + " <FRAME src=Form.html name=blue>" + "</FRAMESET></HTML>" ); + } + + + public void testDefaultFrameNames() throws Exception { + defineWebPage( "Initial", "This is a trivial page" ); WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); + } + + + public void testDefaultFrameContents() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Linker.html" ); + assert( "Default response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); + response = _wc.getResponse( response.getLinks()[0].getRequest() ); + assert( "Second response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); + } + + public void testFrameNames() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); assertMatchingSet( "frame set names", - new String[] { "packageListFrame", "packageFrame", "classFrame" }, + new String[] { "red", "blue" }, response.getFrameNames() ); } - - - - public void testFrameRetrieval() throws Exception { - defineResource( "Initial.html", - "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + - "<FRAMESET cols=\"20%,80%\">" + - " <FRAMESET rows=\"30%,70%\">" + - " <FRAME src=\"overview-frame.html\" name=\"packageListFrame\">" + - " <FRAME src=allclasses-frame.html name=packageFrame>" + - " </FRAMESET>" + - " <FRAME src=\"overview-summary.html\" name=\"classFrame\">" + - "</FRAMESET></HTML>" ); - WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); - assertEquals( "number of frames found", 3, response.getFrames().length ); + + public void testFrameRequests() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + WebRequest[] requests = response.getFrameRequests(); + assertEquals( "Number of frame requests", 2, requests.length ); + assertEquals( "Target for first request", "red", requests[0].getTarget() ); + assertEquals( "URL for second request", getHostPath() + "/Form.html", requests[1].getURL().toExternalForm() ); } - - - + + + public void testFrameLoading() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "Number of links in first frame", 1, _wc.getFrameContents( "red" ).getLinks().length ); + assertEquals( "Number of forms in second frame", 1, _wc.getFrameContents( "blue" ).getForms().length ); + } + + + public void testInFrameLinks() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); + } + + + public void testCrossFrameLinks() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + response = _wc.getResponse( _wc.getFrameContents( "blue" ).getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "URL for second request", getHostPath() + "/Linker.html", response.getURL().toExternalForm() ); + } + + + public void testLinkToTopFrame() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + response = _wc.getResponse( response.getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); + assertEquals( "URL for second request", getHostPath() + "/Form.html", response.getURL().toExternalForm() ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); + } + + private WebConversation _wc; } |
From: Russell G. <rus...@us...> - 2000-10-04 15:45:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv23587/src/com/meterware/httpunit Modified Files: NodeUtils.java WebConversation.java WebResponse.java Log Message: Added frame support Index: NodeUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- NodeUtils.java 2000/10/02 16:32:10 1.4 +++ NodeUtils.java 2000/10/04 15:45:47 1.5 @@ -43,17 +43,24 @@ public static int getAttributeValue( Node node, String attributeName, int defaultValue ) { NamedNodeMap nnm = node.getAttributes(); - Node span = nnm.getNamedItem( attributeName ); - if (span == null) { + Node attribute = nnm.getNamedItem( attributeName ); + if (attribute == null) { return defaultValue; } else try { - return Integer.parseInt( span.getNodeValue() ); + return Integer.parseInt( attribute.getNodeValue() ); } catch (NumberFormatException e) { return defaultValue; } } + public static String getNodeAttribute( Node node, String attributeName ) { + NamedNodeMap nnm = node.getAttributes(); + Node attribute = nnm.getNamedItem( attributeName ); + return (attribute == null) ? "" : attribute.getNodeValue(); + } + + /** * Converts the DOM trees rooted at the specified nodes to text, ignoring * any HTML tags. @@ -91,13 +98,6 @@ } } return sb.toString(); - } - - - private static String getNodeAttribute( Node node, String attributeName ) { - NamedNodeMap nnm = node.getAttributes(); - Node attribute = nnm.getNamedItem( attributeName ); - return (attribute == null) ? "" : attribute.getNodeValue(); } Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebConversation.java 2000/10/02 16:32:10 1.11 +++ WebConversation.java 2000/10/04 15:45:47 1.12 @@ -43,10 +43,36 @@ public WebConversation() { } + + /** + * Returns the name of the currently active frames. + **/ + public String[] getFrameNames() { + Vector names = new Vector(); + for (Enumeration e = _frameContents.keys(); e.hasMoreElements();) { + names.addElement( e.nextElement() ); + } + + String[] result = new String[ names.size() ]; + names.copyInto( result ); + return result; + } + + /** + * Returns the response associated with the specified frame name. + **/ + public WebResponse getFrameContents( String frameName ) { + WebResponse response = (WebResponse) _frameContents.get( frameName ); + if (response == null) throw new NoSuchFrameException( frameName ); + return response; + } + + + /** * Submits a GET method request and returns a response. **/ - public WebResponse getResponse( String urlString ) throws MalformedURLException, IOException { + public WebResponse getResponse( String urlString ) throws MalformedURLException, IOException, SAXException { return getResponse( new GetMethodWebRequest( urlString ) ); } @@ -55,7 +81,7 @@ * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ - public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException { + public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException, SAXException { HttpURLConnection connection = (HttpURLConnection) openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); @@ -70,11 +96,27 @@ throw new HttpNotFoundException( request.getURLString() ); } else { WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); + removeSubFrames( request.getTarget() ); + _frameContents.put( request.getTarget(), result ); + _subFrames.put( request.getTarget(), result.getFrameNames() ); + WebRequest[] requests = result.getFrameRequests(); + for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); return result; } } + private void removeSubFrames( String targetName ) { + String[] names = (String[]) _subFrames.get( targetName ); + if (names == null) return; + for (int i = 0; i < names.length; i++) { + removeSubFrames( names[i] ); + _frameContents.remove( names[i] ); + _subFrames.remove( names[i] ); + } + } + + /** * Defines a cookie to be sent to the server on every request. **/ @@ -141,6 +183,14 @@ /** The authorization header value. **/ private String _authorization; + + /** A map of frame names to current contents. **/ + private Hashtable _frameContents = new Hashtable(); + + + /** A map of frame names to frames nested within them. **/ + private Hashtable _subFrames = new Hashtable(); + static { HttpURLConnection.setFollowRedirects( false ); @@ -202,4 +252,21 @@ super( baseRequest, relativeURL ); } +} + + + +class NoSuchFrameException extends RuntimeException { + + NoSuchFrameException( String frameName ) { + _frameName = frameName; + } + + + public String getMessage() { + return "No frame named " + _frameName + " is currently active"; + } + + + private String _frameName; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- WebResponse.java 2000/10/02 16:32:10 1.15 +++ WebResponse.java 2000/10/04 15:45:47 1.16 @@ -79,7 +79,7 @@ NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); String[] result = new String[ frames.getLength() ]; for (int i = 0; i < result.length; i++) { - result[i] = getValue( frames.item(i).getAttributes().getNamedItem( "name" ) ); + result[i] = NodeUtils.getNodeAttribute( frames.item(i), "name" ); } return result; @@ -89,19 +89,16 @@ /** * Returns the frames found in the page in the order in which they appear. **/ - public WebFrame[] getFrames() throws SAXException { + public WebRequest[] getFrameRequests() throws SAXException { NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - WebFrame[] result = new WebFrame[ frames.getLength() ]; + WebRequest[] result = new WebRequest[ frames.getLength() ]; for (int i = 0; i < result.length; i++) { - result[i] = new WebFrame( frames.item(i) ); + result[i] = new GetMethodWebRequest( this.getURL(), + NodeUtils.getNodeAttribute( frames.item(i), "src" ), + NodeUtils.getNodeAttribute( frames.item(i), "name" ) ); } return result; - } - - - private String getValue( Node node ) { - return node == null ? "" : node.getNodeValue(); } |
From: Russell G. <rus...@us...> - 2000-10-04 15:45:50
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv23587/doc Modified Files: Cookbook.html plans.txt release notes.txt todo.txt Log Message: Added frame support Index: Cookbook.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Cookbook.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Cookbook.html 2000/08/03 13:19:19 1.1 +++ Cookbook.html 2000/10/04 15:45:46 1.2 @@ -16,7 +16,25 @@ </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), -or by using the various other methods described below. +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 +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 +</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. + <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 @@ -104,6 +122,25 @@ response = wc.getResponse( request ); </PRE> And of course the test would then proceed to examine the response to this submission as well. + +<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 +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": + +<PRE><CODE> WebConversation wc = new WebConversation; + 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 + 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: plans.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/plans.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- plans.txt 2000/10/02 16:32:09 1.1 +++ plans.txt 2000/10/04 15:45:46 1.2 @@ -2,11 +2,11 @@ ------------------- Without frames, browser behavior is simply in at least one aspect: each response replaces the previous one. As a result, -it makes sense to test web site behavior by simply retrieving one response after another, and (usually) ignoring any previous -ones. Frames change that rather drastically, requiring a concept to correspond to the browser window contents, only part of -which may be updated by any particular server request. The most obvious object to hold this information is the WebConversation, -which will need to have added to it a 'current window' property. In addition, every request will need to have encoded in it -somewhere the target information, so that the appropriate section of the window will receive the update. +it makes sense to test web site behavior by simply retrieving one response after another, and (usually) ignoring any +previous ones. Frames change that rather drastically, requiring a concept to correspond to the browser window contents, +only part of which may be updated by any particular server request. The most obvious object to hold this information is the +WebConversation, which will need to have added to it a 'current window' property. In addition, every request will need to +have encoded in it somewhere the target information, so that the appropriate section of the window will receive the update. This could be done either by: 1. making the target an attribute of the WebRequest, or @@ -20,7 +20,7 @@ response1 = conversation.getResponse( initial frame request ); request1 = response1.getLink( within a frame ) // the link is found in frame "details" and has no target attribute response2 = conversation.getResponse( request1 ); // this updates the nested frame only - frame = conversation.getFrame( "details" ); + frame = conversation.getFrameContents( "details" ); frame and response2 should be the same object @@ -35,14 +35,10 @@ WebConversation.frameNames[] -- the names of the current active frames WebResponse.allFrameNames[] -- the names of the frames in or below this response WebResponse.frameNames[] -- the names of the frames in this response -WebResponse.frames[] -- all of the frames defined in this response -WebFrame.name -WebFrame.response - Potential validations: -validate whether a response is currently displayed? Not sure why... +validate whether a response is targeted to an active frame. What happens in the real world if it is not? Other Consequences: ***** Bogus filespec: release Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- todo.txt 2000/09/28 18:27:39 1.3 +++ todo.txt 2000/10/04 15:45:46 1.4 @@ -1,4 +1,10 @@ -o Support Frames -o Support digest HTTP Authentication (?) o Documentation, Documentation + +Possibles: +o replace JTidy with a simpler custom parser + +Low priority: + +o history on web conversation +o Support digest HTTP Authentication (?) |
From: Russell G. <rus...@us...> - 2000-10-03 13:41:10
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv22618/doc Modified Files: release notes.txt Log Message: Correct handling of untyped input parameters ***** Bogus filespec: release |
From: Russell G. <rus...@us...> - 2000-10-03 13:41:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv22618/src/com/meterware/httpunit Modified Files: WebForm.java Log Message: Correct handling of untyped input parameters Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebForm.java 2000/10/02 16:32:10 1.9 +++ WebForm.java 2000/10/03 13:41:05 1.10 @@ -240,9 +240,9 @@ String name = getValue( parameters[i].getNamedItem( "name" ) ); String value = getValue( parameters[i].getNamedItem( "value" ) ); String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); - if (type == null) type = "TEXT"; + if (type == null || type.length() == 0) type = "TEXT"; - if (type.equals( "TEXT" ) | type.equals( "HIDDEN" ) | type.equals( "PASSWORD" )) { + if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) { defaults.put( name, value ); } else if (type.equals( "RADIO" ) && parameters[i].getNamedItem( "checked" ) != null) { defaults.put( name, value ); @@ -291,7 +291,7 @@ String name = getValue( parameters[i].getNamedItem( "name" ) ); String value = getValue( parameters[i].getNamedItem( "value" ) ); String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); - if (type == null) type = "TEXT"; + if (type == null || type.length() == 0) type = "TEXT"; if (type.equals( "RADIO" ) || type.equals( "CHECKBOX" )) { if (value.length() == 0 && type.equals( "CHECKBOX" )) value = "on"; @@ -328,9 +328,9 @@ for (int i = 0; i < parameters.length; i++) { String name = getValue( parameters[i].getNamedItem( "name" ) ); String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); - if (type == null) type = "TEXT"; + if (type == null || type.length() == 0) type = "TEXT"; - if (type.equals( "TEXT" ) | type.equals( "HIDDEN" ) | type.equals( "PASSWORD" )) { + if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) { types.put( name, TYPE_TEXT ); } else if (type.equals( "RADIO" )) { types.put( name, TYPE_SCALAR ); |
From: Russell G. <rus...@us...> - 2000-10-03 13:41:09
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv22618/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Correct handling of untyped input parameters Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebFormTest.java 2000/09/27 18:04:04 1.5 +++ WebFormTest.java 2000/10/03 13:41:04 1.6 @@ -85,7 +85,7 @@ public void testHiddenParameters() throws Exception { defineWebPage( "Default", "<form method=POST action = \"/servlet/Login\">" + "<Input name=\"secret\" type=\"hidden\" value=\"surprise\">" + - "<br><Input name=typeless>" + + "<br><Input name=typeless value=nothing>" + "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); @@ -96,6 +96,7 @@ WebRequest request = form.getRequest(); assertEquals( "surprise", request.getParameter( "secret" ) ); + assertEquals( "nothing", request.getParameter( "typeless" ) ); } |
From: Russell G. <rus...@us...> - 2000-10-02 16:33:58
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv2539/doc Modified Files: release notes.txt Log Message: Begin frame support ***** Bogus filespec: release |
From: Russell G. <rus...@us...> - 2000-10-02 16:32:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv1035/src/com/meterware/httpunit Modified Files: GetMethodWebRequest.java HttpUnitOptions.java NodeUtils.java ParsedHTML.java PostMethodWebRequest.java ReceivedPage.java TableCell.java WebConversation.java WebForm.java WebLink.java WebResponse.java WebTable.java Added Files: WebFrame.java Log Message: Begin frame support ***** Error reading new file(2, 'No such file or directory') Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- GetMethodWebRequest.java 2000/09/28 18:27:39 1.4 +++ GetMethodWebRequest.java 2000/10/02 16:32:10 1.5 @@ -48,10 +48,18 @@ /** + * Constructs a web request with a specific target. + **/ + GetMethodWebRequest( URL urlBase, String urlString, String target ) { + super( urlBase, urlString, target ); + } + + + /** * Constructs a web request for a form. **/ - GetMethodWebRequest( URL urlBase, String urlString, WebForm sourceForm ) { - super( urlBase, urlString, sourceForm ); + GetMethodWebRequest( URL urlBase, String urlString, String target, WebForm sourceForm ) { + super( urlBase, urlString, target, sourceForm ); } Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpUnitOptions.java 2000/09/15 16:38:44 1.1 +++ HttpUnitOptions.java 2000/10/02 16:32:10 1.2 @@ -63,12 +63,31 @@ } + /** + * Returns true if images are treated as text, using their alt attributes. + **/ + public static boolean getImagesTreatedAsAltText() { + return _imagesTreatedAsAltText; + } + + + /** + * If true, tells HttpUnit to treat images with alt attributes as though they were the text + * value of that attribute in all searches and displays. The default is false (image text is generally ignored). + **/ + public static void setImagesTreatedAsAltText( boolean asText ) { + _imagesTreatedAsAltText = asText; + } + + //--------------------------------- private members -------------------------------------- private static boolean _parserWarningsEnabled; private static boolean _parameterValuesValidated = true; + + private static boolean _imagesTreatedAsAltText; } Index: NodeUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- NodeUtils.java 2000/09/11 14:23:47 1.3 +++ NodeUtils.java 2000/10/02 16:32:10 1.4 @@ -76,19 +76,28 @@ continue; } else if (node.getNodeName().equalsIgnoreCase( "p" )) { sb.append( "\n" ); - } else if (node.getNodeName().equalsIgnoreCase( "tr")) { + } else if (node.getNodeName().equalsIgnoreCase( "tr" )) { sb.append( "\n" ); pendingNodes.push( " |" ); - } else if (node.getNodeName().equalsIgnoreCase( "td")) { + } else if (node.getNodeName().equalsIgnoreCase( "td" )) { sb.append( " | " ); - } else if (node.getNodeName().equalsIgnoreCase( "th")) { + } else if (node.getNodeName().equalsIgnoreCase( "th" )) { sb.append( " | " ); + } else if (node.getNodeName().equalsIgnoreCase( "img" ) && HttpUnitOptions.getImagesTreatedAsAltText()) { + sb.append( getNodeAttribute( node, "alt" ) ); } pushNodeList( node.getChildNodes(), pendingNodes ); } } return sb.toString(); + } + + + private static String getNodeAttribute( Node node, String attributeName ) { + NamedNodeMap nnm = node.getAttributes(); + Node attribute = nnm.getNamedItem( attributeName ); + return (attribute == null) ? "" : attribute.getNodeValue(); } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ParsedHTML.java 2000/09/25 21:28:44 1.5 +++ ParsedHTML.java 2000/10/02 16:32:10 1.6 @@ -30,9 +30,10 @@ class ParsedHTML { - ParsedHTML( URL pageURL, Node rootNode ) { + ParsedHTML( URL pageURL, String parentTarget, Node rootNode ) { _url = pageURL; _rootNode = rootNode; + _parentTarget = parentTarget; } @@ -43,7 +44,7 @@ NodeList forms = NodeUtils.getElementsByTagName( _rootNode, "form" ); WebForm[] result = new WebForm[ forms.getLength() ]; for (int i = 0; i < result.length; i++) { - result[i] = new WebForm( getURL(), forms.item( i ) ); + result[i] = new WebForm( getURL(), _parentTarget, forms.item( i ) ); } return result; @@ -60,7 +61,7 @@ for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i); if (isLinkAnchor( child )) { - list.addElement( new WebLink( _url, child ) ); + list.addElement( new WebLink( getURL(), _parentTarget, child ) ); } } _links = new WebLink[ list.size() ]; @@ -109,7 +110,7 @@ * they appear. **/ public WebTable[] getTables() { - return WebTable.getTables( getDOM(), _url ); + return WebTable.getTables( getDOM(), _url, _parentTarget ); } @@ -166,6 +167,8 @@ WebLink[] _links; URL _url; + + private String _parentTarget; private String getValue( Node node ) { Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PostMethodWebRequest.java 2000/09/28 18:27:39 1.5 +++ PostMethodWebRequest.java 2000/10/02 16:32:10 1.6 @@ -56,11 +56,13 @@ /** - * Constructs a web request using a base URL and a relative url string. + * Constructs a web request for a form. **/ - PostMethodWebRequest( URL urlBase, String urlString, WebForm sourceForm ) { - super( urlBase, urlString, sourceForm ); + PostMethodWebRequest( URL urlBase, String urlString, String target, WebForm sourceForm ) { + super( urlBase, urlString, target, sourceForm ); } + + } Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ReceivedPage.java 2000/09/25 21:28:44 1.6 +++ ReceivedPage.java 2000/10/02 16:32:10 1.7 @@ -38,8 +38,8 @@ class ReceivedPage extends ParsedHTML { - public ReceivedPage( URL url, String pageText ) throws SAXException { - super( url, getParser().parseDOM( new ByteArrayInputStream( pageText.getBytes() ), null ) ); + public ReceivedPage( URL url, String parentTarget, String pageText ) throws SAXException { + super( url, parentTarget, getParser().parseDOM( new ByteArrayInputStream( pageText.getBytes() ), null ) ); } Index: TableCell.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TableCell.java 2000/09/01 14:54:03 1.3 +++ TableCell.java 2000/10/02 16:32:10 1.4 @@ -60,8 +60,8 @@ //---------------------------------------- package methods ----------------------------------------- - TableCell( Element cellNode, URL url ) { - super( url, cellNode ); + TableCell( Element cellNode, URL url, String parentTarget ) { + super( url, parentTarget, cellNode ); _element = cellNode; _colSpan = getAttributeValue( cellNode, "colspan", 1 ); _rowSpan = getAttributeValue( cellNode, "rowspan", 1 ); Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- WebConversation.java 2000/09/28 18:27:39 1.10 +++ WebConversation.java 2000/10/02 16:32:10 1.11 @@ -69,7 +69,7 @@ } else if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new HttpNotFoundException( request.getURLString() ); } else { - WebResponse result = new WebResponse( this, request.getURL(), connection ); + WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); return result; } } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebForm.java 2000/09/25 21:28:44 1.8 +++ WebForm.java 2000/10/02 16:32:10 1.9 @@ -34,6 +34,18 @@ /** + * Returns the target for this link. + **/ + public String getTarget() { + if (_node.getAttributes().getNamedItem( "target" ) == null) { + return _parentTarget; + } else { + return getValue( _node.getAttributes().getNamedItem( "target" ) ); + } + } + + + /** * Returns an array containing the names of the parameters defined for this form, * in the order in which they appear. **/ @@ -71,9 +83,9 @@ WebRequest result; if (getValue( nnm.getNamedItem( "method" ) ).equalsIgnoreCase( "post" )) { - result = new PostMethodWebRequest( _baseURL, action, this ); + result = new PostMethodWebRequest( _baseURL, action, getTarget(), this ); } else { - result = new GetMethodWebRequest( _baseURL, action, this ); + result = new GetMethodWebRequest( _baseURL, action, getTarget(), this ); } String[] parameterNames = getParameterNames(); @@ -164,9 +176,10 @@ * Contructs a web form given the URL of its source page and the DOM extracted * from that page. **/ - WebForm( URL baseURL, Node node ) { - _node = node; - _baseURL = baseURL; + WebForm( URL baseURL, String parentTarget, Node node ) { + _node = node; + _baseURL = baseURL; + _parentTarget = parentTarget; } @@ -202,6 +215,9 @@ /** The parameters mapped to the type of data which they accept. **/ private Hashtable _dataTypes; + + /** The target in which the parent response is to be rendered. **/ + private String _parentTarget; /** The selections in this form. **/ private HTMLSelectElement[] _selections; Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebLink.java 2000/09/11 14:23:47 1.3 +++ WebLink.java 2000/10/02 16:32:10 1.4 @@ -20,7 +20,7 @@ * Creates and returns a web request which will simulate clicking on this link. **/ public WebRequest getRequest() { - return new GetMethodWebRequest( _baseURL, getURLString() ); + return new GetMethodWebRequest( _baseURL, getURLString(), getTarget() ); } @@ -33,6 +33,18 @@ /** + * Returns the target for this link. + **/ + public String getTarget() { + if (_node.getAttributes().getNamedItem( "target" ) == null) { + return _parentTarget; + } else { + return getValue( _node.getAttributes().getNamedItem( "target" ) ); + } + } + + + /** * Returns a copy of the domain object model subtree associated with this link. **/ public Node getDOMSubtree() { @@ -59,10 +71,11 @@ * Contructs a web link given the URL of its source page and the DOM extracted * from that page. **/ - WebLink( URL baseURL, Node node ) { + WebLink( URL baseURL, String parentTarget, Node node ) { if (node == null) throw new IllegalArgumentException( "node must not be null" ); - _node = node; - _baseURL = baseURL; + _node = node; + _baseURL = baseURL; + _parentTarget = parentTarget; } @@ -74,6 +87,9 @@ /** The DOM node representing the link. **/ private Node _node; + + /** The target window to which the parent response was directed. **/ + private String _parentTarget; private String getValue( Node node ) { Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WebResponse.java 2000/09/27 18:04:04 1.14 +++ WebResponse.java 2000/10/02 16:32:10 1.15 @@ -65,6 +65,47 @@ /** + * Returns the target of the page. + **/ + public String getTarget() throws SAXException { + return _target; + } + + + /** + * Returns the names of the frames found in the page in the order in which they appear. + **/ + public String[] getFrameNames() throws SAXException { + NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); + String[] result = new String[ frames.getLength() ]; + for (int i = 0; i < result.length; i++) { + result[i] = getValue( frames.item(i).getAttributes().getNamedItem( "name" ) ); + } + + return result; + } + + + /** + * Returns the frames found in the page in the order in which they appear. + **/ + public WebFrame[] getFrames() throws SAXException { + NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); + WebFrame[] result = new WebFrame[ frames.getLength() ]; + for (int i = 0; i < result.length; i++) { + result[i] = new WebFrame( frames.item(i) ); + } + + return result; + } + + + private String getValue( Node node ) { + return node == null ? "" : node.getNodeValue(); + } + + + /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ @@ -164,9 +205,10 @@ * @param url the url from which the response was received * @param inputStream the input stream from which the response can be read **/ - WebResponse( WebConversation conversation, URL url, URLConnection connection ) { + WebResponse( WebConversation conversation, String target, URL url, URLConnection connection ) { _conversation = conversation; _url = url; + _target = target; StringBuffer sb = new StringBuffer(); try { BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); @@ -202,19 +244,21 @@ private String _responseText; - private URL _url; - - private WebConversation _conversation; - private String _contentType = "text/plain"; private String _characterSet = "us-ascii"; + final private URL _url; + + final private WebConversation _conversation; + + final private String _target; + private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { if (!_contentType.equals( "text/html" )) throw new RuntimeException( "Response is not HTML" ); - _page = new ReceivedPage( _url, _responseText ); + _page = new ReceivedPage( _url, _target, _responseText ); } return _page; } Index: WebTable.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebTable.java 2000/09/25 21:30:25 1.9 +++ WebTable.java 2000/10/02 16:32:10 1.10 @@ -190,13 +190,13 @@ /** * Returns the top-level tables found in the specified DOM. **/ - static WebTable[] getTables( Node domRoot, URL baseURL ) { + static WebTable[] getTables( Node domRoot, URL baseURL, String parentTarget ) { NodeList nl = NodeUtils.getElementsByTagName( domRoot, "table" ); Vector topLevelTables = new Vector(); for (int i = 0; i < nl.getLength(); i++) { if (isTopLevelTable( nl.item(i), domRoot )) { - topLevelTables.addElement( new WebTable( nl.item(i), baseURL ) ); + topLevelTables.addElement( new WebTable( nl.item(i), baseURL, parentTarget ) ); } } @@ -211,14 +211,16 @@ private Element _dom; private URL _url; + private String _parentTarget; private TableCell[][] _cells; - private WebTable( Node domTreeRoot, URL sourceURL ) { - _dom = (Element) domTreeRoot; - _url = sourceURL; + private WebTable( Node domTreeRoot, URL sourceURL, String parentTarget ) { + _dom = (Element) domTreeRoot; + _url = sourceURL; + _parentTarget = parentTarget; } @@ -326,7 +328,7 @@ private void collectChildren( String childTag, final Vector children ) { processChildren( _element, childTag, "table", new ElementHandler() { public void handleElement( Element element ) { - children.addElement( new TableCell( element, _url ) ); + children.addElement( new TableCell( element, _url, _parentTarget ) ); } } ); } |
From: Russell G. <rus...@us...> - 2000-10-02 16:32:15
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv1035/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java WebLinkTest.java Added Files: RequestTargetTest.java WebFrameTest.java Log Message: Begin frame support --- NEW FILE --- package com.meterware.httpunit; import java.net.URL; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.util.Vector; /** * Tests to ensure the proper handling of the target attribute. **/ public class RequestTargetTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } public static Test suite() { return new TestSuite( RequestTargetTest.class ); } public RequestTargetTest( String name ) { super( name ); } public void setUp() throws Exception { super.setUp(); _wc = new WebConversation(); } public void testDefaultLinkTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\">simple link</a>." ); WebRequest request = new GetMethodWebRequest( getHostPath() + "/Initial.html" ); assertEquals( "new link target", WebRequest.TOP_FRAME, request.getTarget() ); WebResponse response = _wc.getResponse( request ); assertEquals( "default response target", WebRequest.TOP_FRAME, response.getTarget() ); WebLink link = response.getLinks()[0]; assertEquals( "default link target", WebRequest.TOP_FRAME, link.getTarget() ); assertEquals( "default request target", WebRequest.TOP_FRAME, link.getRequest().getTarget() ); } public void testExplicitLinkTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); } public void testInheritedLinkTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); defineWebPage( "SimpleLink", "Here is <a href=\"Initial.html\">another simple link</a>." ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); WebResponse response = _wc.getResponse( link.getRequest() ); assertEquals( "response target", "subframe", response.getTarget() ); link = response.getLinks()[0]; assertEquals( "inherited link target", "subframe", link.getTarget() ); } public void testInheritedLinkTargetInTable() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); defineWebPage( "SimpleLink", "Here is <table><tr><td><a href=\"Initial.html\">another simple link</a>.</td></tr></table>" ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); WebResponse response = _wc.getResponse( link.getRequest() ); assertEquals( "response target", "subframe", response.getTarget() ); WebTable table = response.getTables()[0]; TableCell cell = table.getTableCell(0,0); link = cell.getLinks()[0]; assertEquals( "inherited link target", "subframe", link.getTarget() ); } public void testDefaultFormTarget() throws Exception { defineWebPage( "Initial", "Here is a simple form: " + "<form method=POST action = \"/servlet/Login\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); assertEquals( "Num forms in page", 1, response.getForms().length ); WebForm form = response.getForms()[0]; assertEquals( "default form target", WebRequest.TOP_FRAME, form.getTarget() ); assertEquals( "default request target", WebRequest.TOP_FRAME, form.getRequest().getTarget() ); } public void testExplicitPostFormTarget() throws Exception { defineWebPage( "Initial", "Here is a simple form: " + "<form method=POST action = \"/servlet/Login\" target=\"subframe\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebForm form = _wc.getResponse( getHostPath() + "/Initial.html" ).getForms()[0]; assertEquals( "explicit form target", "subframe", form.getTarget() ); assertEquals( "request target", "subframe", form.getRequest().getTarget() ); } public void testExplicitGetFormTarget() throws Exception { defineWebPage( "Initial", "Here is a simple form: " + "<form method=GET action = \"/servlet/Login\" target=\"subframe\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebForm form = _wc.getResponse( getHostPath() + "/Initial.html" ).getForms()[0]; assertEquals( "explicit form target", "subframe", form.getTarget() ); assertEquals( "request target", "subframe", form.getRequest().getTarget() ); } public void testInheritedFormTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); defineWebPage( "SimpleLink", "Here is a simple form: " + "<form method=GET action = \"/servlet/Login\" target=\"subframe\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); WebResponse response = _wc.getResponse( link.getRequest() ); assertEquals( "response target", "subframe", response.getTarget() ); WebForm form = response.getForms()[0]; assertEquals( "inherited form target", "subframe", form.getTarget() ); } private WebConversation _wc; } --- NEW FILE --- package com.meterware.httpunit; import java.net.URL; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.util.Vector; /** * A test of the web frame functionality. **/ public class WebFrameTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } public static Test suite() { return new TestSuite( WebFrameTest.class ); } public WebFrameTest( String name ) { super( name ); } public void setUp() throws Exception { super.setUp(); _wc = new WebConversation(); } public void testFrameNames() throws Exception { defineResource( "Initial.html", "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + "<FRAMESET cols=\"20%,80%\">" + " <FRAMESET rows=\"30%,70%\">" + " <FRAME src=\"overview-frame.html\" name=\"packageListFrame\">" + " <FRAME src=allclasses-frame.html name=packageFrame>" + " </FRAMESET>" + " <FRAME src=\"overview-summary.html\" name=\"classFrame\">" + "</FRAMESET></HTML>" ); WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); assertMatchingSet( "frame set names", new String[] { "packageListFrame", "packageFrame", "classFrame" }, response.getFrameNames() ); } public void testFrameRetrieval() throws Exception { defineResource( "Initial.html", "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + "<FRAMESET cols=\"20%,80%\">" + " <FRAMESET rows=\"30%,70%\">" + " <FRAME src=\"overview-frame.html\" name=\"packageListFrame\">" + " <FRAME src=allclasses-frame.html name=packageFrame>" + " </FRAMESET>" + " <FRAME src=\"overview-summary.html\" name=\"classFrame\">" + "</FRAMESET></HTML>" ); WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); assertEquals( "number of frames found", 3, response.getFrames().length ); } private WebConversation _wc; } Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- HttpUnitSuite.java 2000/09/15 16:38:44 1.6 +++ HttpUnitSuite.java 2000/10/02 16:32:10 1.7 @@ -40,6 +40,8 @@ suite.addTest( WebLinkTest.suite() ); suite.addTest( HtmlTablesTest.suite() ); suite.addTest( WebFormTest.suite() ); + suite.addTest( WebFrameTest.suite() ); + suite.addTest( RequestTargetTest.suite() ); suite.addTest( FormParametersTest.suite() ); suite.addTest( Base64Test.suite() ); return suite; Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebLinkTest.java 2000/09/27 18:04:04 1.5 +++ WebLinkTest.java 2000/10/02 16:32:10 1.6 @@ -105,12 +105,40 @@ link = _simplePage.getLinkWithImageText( "Next -->" ); assertNotNull( "the image link was not found", link ); assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); + + HttpUnitOptions.setImagesTreatedAsAltText( true ); + link = _simplePage.getLinkWith( "Next -->" ); + assertNotNull( "the image link was not found", link ); + assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); + + HttpUnitOptions.setImagesTreatedAsAltText( false ); + link = _simplePage.getLinkWith( "Next -->" ); + assertNull( "the image link was found based on its hidden alt attribute", link ); } public void testLinkText() throws Exception { WebLink link = _simplePage.getLinks()[0]; assertEquals( "Link text", "an active link", link.asText() ); + } + + + public void testLinkFollowing() throws Exception { + WebConversation wc = new WebConversation(); + defineWebPage( "Initial", "Go to <a href=\"Next.html\">the next page.</a> <a name=\"bottom\">Bottom</a>" ); + defineWebPage( "Next", "And go back to <a href=\"Initial.html#Bottom\">the first page.</a>" ); + + WebResponse initialPage = wc.getResponse( getHostPath() + "/Initial.html" ); + assertEquals( "Num links in initial page", 1, initialPage.getLinks().length ); + WebLink link = initialPage.getLinks()[0]; + + WebResponse nextPage = wc.getResponse( link.getRequest() ); + assertEquals( "Title of next page", "Next", nextPage.getTitle() ); + assertEquals( "Num links in next page", 1, nextPage.getLinks().length ); + link = nextPage.getLinks()[0]; + + WebResponse thirdPage = wc.getResponse( link.getRequest() ); + assertEquals( "Title of next page", "Initial", thirdPage.getTitle() ); } |
From: Russell G. <rus...@us...> - 2000-10-02 16:32:13
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv1035/doc Modified Files: release notes.txt Added Files: plans.txt Log Message: Begin frame support --- NEW FILE --- Implementing frames ------------------- Without frames, browser behavior is simply in at least one aspect: each response replaces the previous one. As a result, it makes sense to test web site behavior by simply retrieving one response after another, and (usually) ignoring any previous ones. Frames change that rather drastically, requiring a concept to correspond to the browser window contents, only part of which may be updated by any particular server request. The most obvious object to hold this information is the WebConversation, which will need to have added to it a 'current window' property. In addition, every request will need to have encoded in it somewhere the target information, so that the appropriate section of the window will receive the update. This could be done either by: 1. making the target an attribute of the WebRequest, or 2. specifying the target in the getResponse call. The question is, how would we use such features? Imagine: (assuming option 1) response1 = conversation.getResponse( initial frame request ); request1 = response1.getLink( within a frame ) // the link is found in frame "details" and has no target attribute response2 = conversation.getResponse( request1 ); // this updates the nested frame only frame = conversation.getFrame( "details" ); frame and response2 should be the same object To do this, each response must have encoded its current frame (default is "_top") and each request must as well. "target" is an attribute of both <A> and <FORM> tags. Additional properties: WebRequest.target -- the target for the request WebResponse.target -- the name of the window in which the response is displayed WebConversation.frameNames[] -- the names of the current active frames WebResponse.allFrameNames[] -- the names of the frames in or below this response WebResponse.frameNames[] -- the names of the frames in this response WebResponse.frames[] -- all of the frames defined in this response WebFrame.name WebFrame.response Potential validations: validate whether a response is currently displayed? Not sure why... Other Consequences: will probably want to support history on the web conversation object. Support "back, forward, mayGoBack, mayGoForward" ***** Bogus filespec: release |