httpunit-commit Mailing List for httpunit (Page 52)
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...> - 2002-09-27 15:49:04
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv22163/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Made Link href Javascript property writeable Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Javascript-support.html 9 Sep 2002 20:04:25 -0000 1.15 +++ Javascript-support.html 27 Sep 2002 15:49:01 -0000 1.16 @@ -65,7 +65,7 @@ <h3>Link</h3> <h4>properties</h4> <ul> -<li>href - readonly - the URL associated with the link</li> +<li>href - read/write - the URL associated with the link</li> </ul> <h4>events</h4> <ul> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.165 retrieving revision 1.166 diff -u -r1.165 -r1.166 --- release_notes.txt 26 Sep 2002 21:49:35 -0000 1.165 +++ release_notes.txt 27 Sep 2002 15:49:01 -0000 1.166 @@ -11,6 +11,10 @@ Revision History: +27-Sep-2002 +Additions: + 1. The Javascript property Link.href is now read-write + 26-Sep-2002 Problems fixed: 1. A Javascript URL containing a question mark was incorrectly being URL-encoded. |
From: Russell G. <rus...@us...> - 2002-09-26 21:49:38
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv7509/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Ignore full first line of HTML comment in Javascript Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- ScriptingTest.java 26 Sep 2002 18:22:33 -0000 1.24 +++ ScriptingTest.java 26 Sep 2002 21:49:35 -0000 1.25 @@ -180,9 +180,9 @@ public void testFunctionCallOnLoad() throws Exception { defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - "<!-- " + + "<!-- hide this\n" + "function sayCheese() { alert( \"Cheese!\" ); }" + - "// -->" + + "// end hiding -->" + "</script></head>" + "<body onLoad='sayCheese()'></body>" ); WebConversation wc = new WebConversation(); |
From: Russell G. <rus...@us...> - 2002-09-26 21:49:38
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7509/doc Modified Files: release_notes.txt Log Message: Ignore full first line of HTML comment in Javascript Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.164 retrieving revision 1.165 diff -u -r1.164 -r1.165 --- release_notes.txt 26 Sep 2002 18:22:30 -0000 1.164 +++ release_notes.txt 26 Sep 2002 21:49:35 -0000 1.165 @@ -14,6 +14,7 @@ 26-Sep-2002 Problems fixed: 1. A Javascript URL containing a question mark was incorrectly being URL-encoded. + 2. HTML comments at the start of a JavaScript were not being completely ignored 25-Sep-2002 Problems fixed: |
From: Russell G. <rus...@us...> - 2002-09-26 21:49:37
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv7509/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Ignore full first line of HTML comment in Javascript Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- JavaScript.java 13 Sep 2002 18:34:57 -0000 1.22 +++ JavaScript.java 26 Sep 2002 21:49:35 -0000 1.23 @@ -112,11 +112,24 @@ public void executeScript( String script ) { try { script = script.trim(); - if (script.startsWith( "<!--" )) script = script.substring( 4 ); + if (script.startsWith( "<!--" )) script = withoutFirstLine( script ); Context.getCurrentContext().evaluateString( this, script, "httpunit", 0, null ); } catch (Exception e) { handleScriptException( e, "Script '" + script + "'" ); } + } + + + private String withoutFirstLine( String script ) { + for (int i=0; i < script.length(); i++) { + if (isLineTerminator( script.charAt(i) )) return script.substring( i ).trim(); + } + return ""; + } + + + private boolean isLineTerminator( char c ) { + return c == 0x0A || c == 0x0D; } |
From: Russell G. <rus...@us...> - 2002-09-26 18:22:35
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv29024/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Don't URL-encode javascript URLs Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- ScriptingTest.java 25 Sep 2002 16:20:53 -0000 1.23 +++ ScriptingTest.java 26 Sep 2002 18:22:33 -0000 1.24 @@ -81,7 +81,7 @@ } - public void testJavaScriptURLWithParameters() throws Exception { + public void testJavaScriptURLWithVariables() throws Exception { defineResource( "OnCommand.html", "<html><head></head>" + "<body>" + "<a href='javascript:\"Our winner is... \" + document.the_form.winner.value'>go</a>" + @@ -92,6 +92,22 @@ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); response.getLinks()[0].click(); assertEquals( "New page", "Our winner is... George of the Jungle", wc.getCurrentPage().getText() ); + } + + + public void testJavaScriptURLWithQuestionMark() throws Exception { + defineResource( "/appname/HandleAction/report?type=C", "You made it!" ); + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<a href=\"javascript:redirect('/appname/HandleAction/report?type=C')\">go</a>" + + "<script language='JavaScript'>" + + " function redirect( url ) { window.location=url; }" + + "</script>" + + "</form></body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + response.getLinks()[0].click(); + assertEquals( "New page", "You made it!", wc.getCurrentPage().getText() ); } |
From: Russell G. <rus...@us...> - 2002-09-26 18:22:35
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv29024/src/com/meterware/httpunit Modified Files: WebRequest.java WebRequestSource.java Log Message: Don't URL-encode javascript URLs Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- WebRequest.java 5 Sep 2002 14:46:55 -0000 1.47 +++ WebRequest.java 26 Sep 2002 18:22:32 -0000 1.48 @@ -311,7 +311,7 @@ protected WebRequest( WebRequestSource requestSource ) { - this( requestSource.getBaseURL(), requestSource.getRelativeURL(), requestSource.getTarget(), newParameterHolder( requestSource ) ); + this( requestSource.getBaseURL(), requestSource.getRelativePage(), requestSource.getTarget(), newParameterHolder( requestSource ) ); _webRequestSource = requestSource; setHeaderField( "Referer", requestSource.getBaseURL().toExternalForm() ); } Index: WebRequestSource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WebRequestSource.java 23 Aug 2002 19:33:13 -0000 1.13 +++ WebRequestSource.java 26 Sep 2002 18:22:33 -0000 1.14 @@ -101,8 +101,9 @@ /** * Returns the URL relative to the current page which will handle the request. */ - String getRelativeURL() { - final String url = getDestinationPage(); + String getRelativePage() { + final String url = getRelativeURL(); + if (url.startsWith( "javascript:" )) return url; final int questionMarkIndex = url.indexOf("?"); if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { return url.substring(0, questionMarkIndex); @@ -111,7 +112,7 @@ } - private String getDestinationPage() { + private String getRelativeURL() { String result = trimFragment( getDestination() ); if (result.trim().length() == 0) result = getBaseURL().getFile(); return result; @@ -245,6 +246,7 @@ **/ private String getParametersString() { final String url = trimFragment( getDestination() ); + if (url.startsWith( "javascript:" )) return ""; final int questionMarkIndex = url.indexOf("?"); if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { return url.substring( questionMarkIndex + 1 ); |
From: Russell G. <rus...@us...> - 2002-09-26 18:22:35
|
Update of /cvsroot/httpunit/httpunit/doc/tutorial In directory usw-pr-cvs1:/tmp/cvs-serv29024/doc/tutorial Modified Files: build.xml Log Message: Don't URL-encode javascript URLs Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/tutorial/build.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- build.xml 27 Nov 2001 16:40:47 -0000 1.2 +++ build.xml 26 Sep 2002 18:22:32 -0000 1.3 @@ -18,6 +18,7 @@ <fileset dir="${jars.dir}"> <include name="*.jar"/> </fileset> + <pathelement location="${classpath}" /> </path> |
From: Russell G. <rus...@us...> - 2002-09-26 18:22:35
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv29024/doc Modified Files: release_notes.txt Log Message: Don't URL-encode javascript URLs Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.163 retrieving revision 1.164 diff -u -r1.163 -r1.164 --- release_notes.txt 25 Sep 2002 16:20:53 -0000 1.163 +++ release_notes.txt 26 Sep 2002 18:22:30 -0000 1.164 @@ -11,6 +11,10 @@ Revision History: +26-Sep-2002 +Problems fixed: + 1. A Javascript URL containing a question mark was incorrectly being URL-encoded. + 25-Sep-2002 Problems fixed: 1. Bug #604478 - setting the form action did not always update the predefined parameter list. This could cause a request |
From: Russell G. <rus...@us...> - 2002-09-25 16:43:45
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv10906/doc Modified Files: faq.html Log Message: update documentation Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- faq.html 5 Sep 2002 14:46:55 -0000 1.17 +++ faq.html 25 Sep 2002 16:43:42 -0000 1.18 @@ -7,43 +7,62 @@ <OL> <LI><A HREF="#Cannot unzip">Why can't I unzip the download library?</A></LI> <LI><A HREF="#org.xml.sax">What is the org.xml.sax package?</A></LI> -<LI><A HREF="#javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> -<LI><A HREF="#norhino">JavaScript is not being executed at all. Why not?</A></LI> +<LI><A HREF="#reload">Why do I get java.lang.IllegalAccessError when calling getResponse()?</A></LI> + +</ol><ol start=4> + <LI><A HREF="sslfaq.html">Does HttpUnit support https?</A></LI> <LI><A HREF="#proxy">Can I use HttpUnit through a proxy server?</A></LI> <LI><A HREF="#charset">Why isn't HttpUnit handling my non-English pages?</A></LI> +<LI><A HREF="#badType">The server is not sending a valid content type. How do I test HTML pages anyway?</A></LI> + +</ol><ol start=8> + <LI><A HREF="#buttons">HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</A></LI> -<LI><A HREF="#reload">Why do I get java.lang.IllegalAccessError when calling getResponse()?</A></LI> <LI><A HREF="#badPost">Why doesn't my servlet see parameters on a POST request?</A></LI> <LI><A HREF="#hidden">Why can't I change hidden parameters?</A></LI> -<LI><A HREF="#badType">The server is not sending a valid content type. How do I test HTML pages anyway?</A></LI> + +</ol><ol start=11> + +<LI><A HREF="#javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> +<LI><A HREF="#norhino">JavaScript is not being executed at all. Why not?</A></LI> +<li><a href="#unsupported">How do I handle a page that uses JavaScript features that HttpUnit does not support?</a></li> </OL> +<h2>Problems getting started</h2> -<A NAME="Cannot unzip"><H2>Why can't I unzip the download library?</H2></A> +<A NAME="Cannot unzip"><h3>Why can't I unzip the download library?</h3></A> HttpUnit is archived using the classes in the java.util.zip package. Some older Unzip programs cannot understand this format. If you are using WinZip, stick to version 7.0 or later. -<A NAME="org.xml.sax"><H2>What is the org.xml.sax package?</H2></A> -You may be getting compile or runtime errors asking for the org.xml.sax package. This package is found in JTidy, the HTML parser used -by HttpUnit. You should download Jtidy from -<A HREF="http://sourceforge.net/project/showfiles.php?group_id=13153">its SourceForge download page</A> -and install Tidy.jar in your classpath. +<A NAME="org.xml.sax"><h3>What is the org.xml.sax package?</h3></A> +You may be getting compile or runtime errors asking for the org.xml.sax package. +This package is found in <a href="http://www.sf.net/projects/jtidy">JTidy</a>, the HTML parser used +by HttpUnit. It is included in the download. -<A NAME="javascript"><H2>How do I use HttpUnit to test my pages that use JavaScript?</H2></A> -You should not have to do anything special; however, not all JavaScript constructs are supported as yet. See -<a href="Javascript-support.html">the list of supported JavaScript features</a> for more information. +<A NAME="#reload"><h3>Why do I get java.lang.IllegalAccessError when calling getResponse()?</h3></A> +<p>This happens when you use HttpUnit and certain versions of JTidy with one of the JUnit graphical test runners, which reloads +classes every time to run a test. Unfortunately, this places different versions of the JTidy +classes in different class loaders, so you get this error. To avoid it, +you can do any of the following:<ul><li>Use only the text test runner</li> +<li>Disable all class reloading in JUnit by adding "loading=false" to <tt>junit.properties</tt> in your current directory</li> +<li>Disable reloading of HttpUnit and JTidy by adding the following lines to <tt>excluded.properties</tt> in junit.jar<blockquote><code> +excluded.10=com.meterware.httpunit.*<br> +excluded.11=org.w3c.tidy.* +</code></blockquote> +This will require extracting the file, modifying it and then putting it back <em>in the same directory</em>, but it should allow your +tests to reload safely.</ul></p> +<p>This problem appears to be resolved in JTidy r7, which is included with HttpUnit 1.4.1 or later. -<A NAME="#norhino"><H2>JavaScript is not being executed at all. Why not?</H2></A> -If you do not have the Rhino JAR (js.jar) in your classpath, JavaScript features do not work. +<h2>Server Issues</h2> -<A NAME="proxy"><H2>Can I use HttpUnit through a proxy server?</H2></A> +<A NAME="proxy"><h3>Can I use HttpUnit through a proxy server?</h3></A> Yes. HttpUnit uses java.net.HttpURLConnection, so the <A HREF="http://www.javaworld.com/javaworld/javatips/jw-javatip42.html">normal Java way to use proxies</A> will work. At some point HttpUnit may support this more directly, but for now, you will need to set the system properties yourself. -<A NAME="charset"><H2>Why isn't HttpUnit handling my non-English pages?</H2></A> +<A NAME="charset"><h3>Why isn't HttpUnit handling my non-English pages?</h3></A> Older versions of HttpUnit (through 1.2) incorrectly assumed that all pages were in the default character set for the client platform. As of version 1.2.1, HttpUnit correctly recognizes the charset parameter of the Content-type header which may specify an alternative character set; @@ -63,33 +82,27 @@ </code></blockquote> where the proper encoding should be substituted for "EUC_JP". The <code>getBytes</code> call is needed to extract the raw bytes from the parameter string. -<A NAME="buttons"><H2>HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</H2></A> +<A name="#badType"><h3>The server is not sending a valid content type. How do I test HTML pages anyway?</h3></A> +By default, HttpUnit assumes a content type of "text/plain" unless the server sends the Content-Type header to override +it, as most servers do. If yours is not, you can +call<blockquote><code>HttpUnitOptions.setDefaultContentType( "text/html" );</code></blockquote>before running your tests. +If you are using JUnit, call this method in your <code>setUp()</code> method. + +<h2>Form Handling Problems</h2> + +<A NAME="buttons"><h3>HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</h3></A> This often happens when your HTML is not valid. Most browsers are extremely forgiving of bad HTML; however, JTidy (the HTML parser used by HttpUnit) is not. It expects tags to be nested according to the HTML specification and will reject any that are not. JTidy can display error messages to tell you what is wrong. To see them, call <code>HttpUnitOptions.setParserWarningsEnabled( true )</code> before retrieving your HTML page. Once you have corrected any errors, HttpUnit should see your form buttons and parameters. -<A NAME="#reload"><H2>Why do I get java.lang.IllegalAccessError when calling getResponse()?</H2></A> -<p>This happens when you use HttpUnit and certain versions of JTidy with one of the JUnit graphical test runners, which reloads -classes every time to run a test. Unfortunately, this places different versions of the JTidy -classes in different class loaders, so you get this error. To avoid it, -you can do any of the following:<ul><li>Use only the text test runner</li> -<li>Disable all class reloading in JUnit by adding "loading=false" to <tt>junit.properties</tt> in your current directory</li> -<li>Disable reloading of HttpUnit and JTidy by adding the following lines to <tt>excluded.properties</tt> in junit.jar<blockquote><code> -excluded.10=com.meterware.httpunit.*<br> -excluded.11=org.w3c.tidy.* -</code></blockquote> -This will require extracting the file, modifying it and then putting it back <em>in the same directory</em>, but it should allow your -tests to reload safely.</ul></p> -<p>This problem appears to be resolved in JTidy r7, which is included with HttpUnit 1.4.1 or later. - -<A NAME="#badPost"><H2>Why doesn't my servlet see parameters on a POST request?</H2></A> +<A NAME="#badPost"><h3>Why doesn't my servlet see parameters on a POST request?</h3></A> Some older servlet engines, such as Tomcat 3.1, get confused when they see a charset attribute on the Content-Type header. HttpUnit 1.2.6 sends this attribute; As of HttpUnit 1.2.7 it will only send it if you call <code>HttpUnitOptions.setPostIncludesCharset(true)</code> before your request. -<A name="#hidden"><h2>Why can't I change hidden parameter values?</h2></A> +<A name="#hidden"><h3>Why can't I change hidden parameter values?</h3></A> By default, HttpUnit verifies any parameter value changes against the form containing them. Since a user cannot directly change hidden parameters, HttpUnit stops you from doing it in your code. If you have to change these values, you have a couple of choices:<ul> @@ -101,12 +114,20 @@ rather than the original one. </ul> -<A name="#badType"><h2>The server is not sending a valid content type. How do I test HTML pages anyway?</h2></A> -By default, HttpUnit assumes a content type of "text/plain" unless the server sends the Content-Type header to override -it, as most servers do. If yours is not, you can -call<blockquote><code>HttpUnitOptions.setDefaultContentType( "text/html" );</code></blockquote>before running your tests. -If you are using JUnit, call this method in your <code>setUp()</code> method. +<h2>JavaScript support</h2> + +<A NAME="javascript"><h3>How do I use HttpUnit to test my pages that use JavaScript?</h3></A> +You should not have to do anything special; however, not all JavaScript constructs are supported as yet. See +<a href="Javascript-support.html">the list of supported JavaScript features</a> for more information. + +<A NAME="norhino"><h3>JavaScript is not being executed at all. Why not?</h3></A> +If you do not have the Rhino JAR (js.jar) in your classpath, JavaScript features do not work. +<a name="unsupported"><h3>How do I handle a page that uses JavaScript features that HttpUnit does not support?</h3></a> +The latest pre-release version supports disabling exceptions as a result of Javascript errors. +If you call<blockquote><code>HttpUnitOptions.setExceptionsThrownOnScriptError( false );</code></blockquote>problems will +recorded but will not throw exceptions. +You can see the list of problems detected by calling<blockquote><code>HttpUnitOptions.getScriptErrorMessages();</code></blockquote> </BODY></HTML> |
From: Russell G. <rus...@us...> - 2002-09-25 16:20:56
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv24618/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Treat form, image, and link names as case-sensitive in JavaScript Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ScriptingTest.java 13 Sep 2002 18:34:58 -0000 1.22 +++ ScriptingTest.java 25 Sep 2002 16:20:53 -0000 1.23 @@ -267,6 +267,24 @@ } + public void testCaseSensitiveNames() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name='item' action='run'></form>" + + "<a name='Item' href='sample.html'></a>" + + "<a href='#' name='first' onMouseOver='alert( document.item.action );'>1</a>" + + "<a href='#' name='second' onMouseOver='alert( document.Item.href );'>2</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebForm form = response.getFormWithName( "realform" ); + response.getLinkWithName( "first" ).mouseOver(); + assertEquals( "form action", "run", wc.popNextAlert() ); + response.getLinkWithName( "second" ).mouseOver(); + assertEquals( "link href", getHostPath() + "/sample.html", wc.popNextAlert() ); + } + + public void testLinkMouseOverEvent() throws Exception { defineResource( "OnCommand.html", "<html><head></head>" + "<body>" + |
From: Russell G. <rus...@us...> - 2002-09-25 16:20:56
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv24618/doc Modified Files: release_notes.txt Log Message: Treat form, image, and link names as case-sensitive in JavaScript Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.162 retrieving revision 1.163 diff -u -r1.162 -r1.163 --- release_notes.txt 25 Sep 2002 15:24:37 -0000 1.162 +++ release_notes.txt 25 Sep 2002 16:20:53 -0000 1.163 @@ -11,6 +11,12 @@ Revision History: +25-Sep-2002 +Problems fixed: + 1. Bug #604478 - setting the form action did not always update the predefined parameter list. This could cause a request + to be sent with the wrong URL parameters. + 2. Form, Image, and Link names are now properly treated as case-sensitive within Javascript. + 13-Sep-2002 Acknowledgements: Thanks to Jin Zhao for help in expanding the search possibilities for links. @@ -20,11 +26,6 @@ either the first match or all matches. 2. It is now possible to control the handling of script errors by calling HttpUnitOptions.setExceptionsThrownOnScriptError. If the exceptions are not thrown, the error messages will instead be available via HttpUnitOptions.getScriptErrorMessages() - -25-Sep-2002 -Problems fixed: - 1. Bug #604478 - setting the form action did not always update the predefined parameter list. This could cause a request - to be sent with the wrong URL parameters. 9-Sep-2002 Acknowledgement: |
From: Russell G. <rus...@us...> - 2002-09-25 16:20:56
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv24618/src/com/meterware/httpunit Modified Files: HTMLPage.java Log Message: Treat form, image, and link names as case-sensitive in JavaScript Index: HTMLPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- HTMLPage.java 30 Aug 2002 18:17:48 -0000 1.8 +++ HTMLPage.java 25 Sep 2002 16:20:53 -0000 1.9 @@ -20,6 +20,7 @@ * *******************************************************************************************************************/ import com.meterware.httpunit.scripting.ScriptableDelegate; +import com.meterware.httpunit.scripting.NamedDelegate; import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; @@ -148,20 +149,28 @@ public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { - WebForm wf = getFormWithName( propertyName ); - if (wf != null) return wf.getScriptableObject(); + NamedDelegate delegate = getNamedItem( getForms(), propertyName ); + if (delegate != null) return delegate; - WebLink wl = getLinkWithName( propertyName ); - if (wl != null) return wl.getScriptableObject(); + delegate = getNamedItem( getLinks(), propertyName ); + if (delegate != null) return delegate; - WebImage wi = getImageWithName( propertyName ); - if (wi != null) return wi.getScriptableObject(); + delegate = getNamedItem( getImages(), propertyName ); + if (delegate != null) return delegate; if (propertyName.equalsIgnoreCase( "location" )) { return getResponse().getScriptableObject().get( "location" ); } else { return super.get( propertyName ); } + } + + + private NamedDelegate getNamedItem( NamedDelegate[] items, String name ) { + for (int i = 0; i < items.length; i++) { + if (items[i].getName().equals( name )) return items[i]; + } + return null; } |
From: Russell G. <rus...@us...> - 2002-09-25 16:20:56
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv24618 Modified Files: index.html Log Message: Treat form, image, and link names as case-sensitive in JavaScript Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- index.html 20 Aug 2002 19:39:20 -0000 1.22 +++ index.html 25 Sep 2002 16:20:52 -0000 1.23 @@ -12,7 +12,7 @@ HttpUnit makes this easy. Written in Java, HttpUnit emulates the relevant portions of browser behavior, including -form submission, <a href="doc/JavaScript-support.html">JavaScript</a>, +form submission, <a href="doc/Javascript-support.html">JavaScript</a>, basic <A HREF="ftp://ftp.isi.edu/in-notes/rfc2617.txt">http authentication</A>, cookies and automatic page redirection, and allows Java test code to examine returned pages either as text, an XML DOM, or containers of forms, tables, and links.</P> |
From: Russell G. <rus...@us...> - 2002-09-25 15:24:40
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv13663/test/com/meterware/httpunit/javascript Modified Files: FormScriptingTest.java Log Message: #604478: setting form action now updates url parameters Index: FormScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- FormScriptingTest.java 9 Sep 2002 20:04:27 -0000 1.10 +++ FormScriptingTest.java 25 Sep 2002 15:24:37 -0000 1.11 @@ -25,6 +25,11 @@ import com.meterware.httpunit.HttpUnitTest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebClient; +import com.meterware.httpunit.WebLink; +import com.meterware.pseudoserver.PseudoServlet; +import com.meterware.pseudoserver.WebResource; + +import java.io.IOException; import org.xml.sax.SAXException; @@ -150,6 +155,36 @@ response.getLinks()[ 0 ].click(); assertEquals( "Result of submit", "You made it!", wc.getCurrentPage().getText() ); } + + + public void testSubmitViaScriptWithPostParams() throws Exception { + defineResource( "/servlet/TestServlet?param3=value3¶m4=value4", new PseudoServlet() { + public WebResource getPostResponse() throws IOException { + return new WebResource( "You made it!", "text/plain" ); + } + } ); + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form method=POST enctype='multipart/form-data' name='TestForm'>" + + " <input type=hidden name=param1 value='value1'>" + + " <input type=text name=param2 value=''>" + + "</form>" + + "<a href='#' onclick='SubmitForm(\"/servlet/TestServlet?param3=value3¶m4=value4\")'>" + + "<img SRC='/gifs/submit.gif' ALT='Submit' TITLE='Submit' NAME='Submit'></a>" + + "<script language=JavaScript type='text/javascript'>" + + " function SubmitForm(submitLink) {" + + " var ltestForm = document.TestForm;" + + " ltestForm.action = submitLink;" + + " ltestForm.submit();" + + " }" + + "</script>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + + response.getLinks()[0].click(); + assertEquals( "Result of submit", "You made it!", wc.getCurrentPage().getText() ); + } public void testSubmitButtonlessFormViaScript() throws Exception { |
From: Russell G. <rus...@us...> - 2002-09-25 15:24:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13663/src/com/meterware/httpunit Modified Files: WebForm.java Log Message: #604478: setting form action now updates url parameters Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- WebForm.java 5 Sep 2002 19:10:44 -0000 1.63 +++ WebForm.java 25 Sep 2002 15:24:37 -0000 1.64 @@ -485,7 +485,7 @@ public class Scriptable extends ScriptableDelegate implements NamedDelegate { public String getAction() { return WebForm.this.getAction(); } - public void setAction( String newAction ) { setDestination( newAction ); } + public void setAction( String newAction ) { setDestination( newAction ); _presetParameters = null; } public void submit() throws IOException, SAXException { |
From: Russell G. <rus...@us...> - 2002-09-25 15:24:40
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv13663/doc Modified Files: release_notes.txt Log Message: #604478: setting form action now updates url parameters Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.161 retrieving revision 1.162 diff -u -r1.161 -r1.162 --- release_notes.txt 13 Sep 2002 18:34:57 -0000 1.161 +++ release_notes.txt 25 Sep 2002 15:24:37 -0000 1.162 @@ -21,6 +21,11 @@ 2. It is now possible to control the handling of script errors by calling HttpUnitOptions.setExceptionsThrownOnScriptError. If the exceptions are not thrown, the error messages will instead be available via HttpUnitOptions.getScriptErrorMessages() +25-Sep-2002 +Problems fixed: + 1. Bug #604478 - setting the form action did not always update the predefined parameter list. This could cause a request + to be sent with the wrong URL parameters. + 9-Sep-2002 Acknowledgement: 1. Thanks to Donald Ball for pointing out the problem with the behavior of Select.selectedIndex. |
From: Russell G. <rus...@us...> - 2002-09-13 18:35:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv23375/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java Added Files: ScriptException.java Log Message: Added control of script error messages ***** Error reading new file[Errno 2] No such file or directory: 'ScriptException.java' Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- HttpUnitOptions.java 30 Aug 2002 15:20:09 -0000 1.26 +++ HttpUnitOptions.java 13 Sep 2002 18:34:57 -0000 1.27 @@ -406,6 +406,40 @@ } + + /** + * Determines whether script errors result in exceptions or warning messages. + */ + public static void setExceptionsThrownOnScriptError( boolean throwExceptions ) { + getScriptingEngine().setThrowExceptionsOnError( throwExceptions ); + } + + + /** + * Returns true if script errors cause exceptions to be thrown. + */ + public static boolean getExceptionsThrownOnScriptError() { + return getScriptingEngine().isThrowExceptionsOnError(); + } + + + /** + * Returns the accumulated script error messages encountered. Error messages are accumulated only + * if 'throwExceptionsOnError' is disabled. + */ + public static String[] getScriptErrorMessages() { + return getScriptingEngine().getErrorMessages(); + } + + + /** + * Clears the accumulated script error messages. + */ + public static void clearScriptErrorMessages() { + getScriptingEngine().clearErrorMessages(); + } + + private static void disableScripting( Exception e, String errorMessage ) { System.err.println( errorMessage + _scriptEngineClassName ); System.err.println( "" + e ); @@ -421,8 +455,11 @@ private static final ScriptingEngineFactory NULL_SCRIPTING_ENGINE_FACTORY = new ScriptingEngineFactory() { public boolean isEnabled() { return false; } - public void associate( WebResponse response ) { - } + public void associate( WebResponse response ) {} + public void setThrowExceptionsOnError( boolean throwExceptions ) {} + public boolean isThrowExceptionsOnError() { return false; } + public String[] getErrorMessages() { return new String[ 0 ]; } + public void clearErrorMessages() {} }; |
From: Russell G. <rus...@us...> - 2002-09-13 18:35:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv23375/src/com/meterware/httpunit/scripting Modified Files: ScriptingEngineFactory.java Log Message: Added control of script error messages Index: ScriptingEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptingEngineFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ScriptingEngineFactory.java 20 Aug 2002 15:09:28 -0000 1.2 +++ ScriptingEngineFactory.java 13 Sep 2002 18:34:57 -0000 1.3 @@ -38,4 +38,25 @@ **/ public void associate( WebResponse response ); + /** + * Determines whether script errors result in exceptions or warning messages. + */ + public void setThrowExceptionsOnError( boolean throwExceptions ); + + /** + * Returns true if script errors cause exceptions to be thrown. + */ + public boolean isThrowExceptionsOnError(); + + /** + * Returns the accumulated script error messages encountered. Error messages are accumulated only + * if 'throwExceptionsOnError' is disabled. + */ + public String[] getErrorMessages(); + + /** + * Clears the accumulated script error messages. + */ + public void clearErrorMessages(); + } |
From: Russell G. <rus...@us...> - 2002-09-13 18:35:02
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv23375/doc Modified Files: release_notes.txt Log Message: Added control of script error messages Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.160 retrieving revision 1.161 diff -u -r1.160 -r1.161 --- release_notes.txt 13 Sep 2002 14:17:25 -0000 1.160 +++ release_notes.txt 13 Sep 2002 18:34:57 -0000 1.161 @@ -18,6 +18,8 @@ Additions: 1. The mechanism for search for links has been expanded to permit arbitrary search criteria and to retrieve either the first match or all matches. + 2. It is now possible to control the handling of script errors by calling HttpUnitOptions.setExceptionsThrownOnScriptError. + If the exceptions are not thrown, the error messages will instead be available via HttpUnitOptions.getScriptErrorMessages() 9-Sep-2002 Acknowledgement: |
From: Russell G. <rus...@us...> - 2002-09-13 18:35:02
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv23375/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Added control of script error messages Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ScriptingTest.java 5 Sep 2002 19:10:44 -0000 1.21 +++ ScriptingTest.java 13 Sep 2002 18:34:58 -0000 1.22 @@ -106,6 +106,21 @@ } + public void testOnLoadErrorBypass() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body onLoad='noSuchFunction()'>" + + "<img src=sample.jpg>" + + "</body>" ); + WebConversation wc = new WebConversation(); + HttpUnitOptions.setExceptionsThrownOnScriptError( false ); + HttpUnitOptions.clearScriptErrorMessages(); + + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + assertEquals( "Number of images on page", 1, response.getImages().length ); + assertEquals( "Number of script failures logged", 1, HttpUnitOptions.getScriptErrorMessages().length ); + } + + public void testConfirmationDialog() throws Exception { defineWebPage( "OnCommand", "<a href='NextPage' id='go' onClick='return confirm( \"go on?\" );'>" ); defineResource( "NextPage", "Got the next page!" ); |
From: Russell G. <rus...@us...> - 2002-09-13 18:35:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv23375/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java JavaScriptEngineFactory.java Log Message: Added control of script error messages Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- JavaScript.java 9 Sep 2002 20:04:26 -0000 1.21 +++ JavaScript.java 13 Sep 2002 18:34:57 -0000 1.22 @@ -24,6 +24,7 @@ import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebImage; +import com.meterware.httpunit.ScriptException; import com.meterware.httpunit.scripting.ScriptingEngine; import com.meterware.httpunit.scripting.ScriptableDelegate; @@ -33,6 +34,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import java.util.ArrayList; import java.io.IOException; import org.mozilla.javascript.*; @@ -47,6 +49,30 @@ private final static Object[] NO_ARGS = new Object[0]; + private static boolean _throwExceptionsOnError = true; + + private static ArrayList _errorMessages = new ArrayList(); + + + static boolean isThrowExceptionsOnError() { + return _throwExceptionsOnError; + } + + + static void setThrowExceptionsOnError( boolean throwExceptionsOnError ) { + _throwExceptionsOnError = throwExceptionsOnError; + } + + + static void clearErrorMessages() { + _errorMessages.clear(); + } + + + static String[] getErrorMessages() { + return (String[]) _errorMessages.toArray( new String[ _errorMessages.size() ] ); + } + /** * Initiates JavaScript execution for the specified web response. @@ -88,10 +114,8 @@ script = script.trim(); if (script.startsWith( "<!--" )) script = script.substring( 4 ); Context.getCurrentContext().evaluateString( this, script, "httpunit", 0, null ); - } catch (JavaScriptException e) { - throw new RuntimeException( "Script '" + script + "' failed: " + e ); - } catch (EcmaError e) { - throw new RuntimeException( "Syntax Error at line " + e.getLineNumber() + ": " + e.getLineSource() ); + } catch (Exception e) { + handleScriptException( e, "Script '" + script + "'" ); } } @@ -104,8 +128,8 @@ Object result = f.call( context, this, this, NO_ARGS ); return (result instanceof Boolean) ? ((Boolean) result).booleanValue() : true; } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException( "Script '" + eventScript + "' failed: " + e ); + handleScriptException( e, "Event '" + eventScript + "'" ); + return false; } } @@ -117,8 +141,20 @@ Object result = Context.getCurrentContext().evaluateString( this, urlString, "httpunit", 0, null ); return (result == null || result instanceof Undefined) ? null : result.toString(); } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException( "Script '" + urlString + "' failed: " + e ); + handleScriptException( e, "URL '" + urlString + "'" ); + return null; + } + } + + + private void handleScriptException( Exception e, String badScript ) { + final String errorMessage = badScript + " failed: " + e; + if (!(e instanceof EcmaError)) { + throw new RuntimeException( errorMessage ); + } else if (isThrowExceptionsOnError()) { + throw new ScriptException( errorMessage ); + } else { + _errorMessages.add( errorMessage ); } } Index: JavaScriptEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScriptEngineFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JavaScriptEngineFactory.java 30 Aug 2002 15:20:09 -0000 1.5 +++ JavaScriptEngineFactory.java 13 Sep 2002 18:34:57 -0000 1.6 @@ -43,9 +43,31 @@ public void associate( WebResponse response ) { try { JavaScript.run( response ); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException( e.toString() ); } + } + + + public void setThrowExceptionsOnError( boolean throwExceptions ) { + JavaScript.setThrowExceptionsOnError( throwExceptions ); + } + + + public boolean isThrowExceptionsOnError() { + return JavaScript.isThrowExceptionsOnError(); + } + + + public String[] getErrorMessages() { + return JavaScript.getErrorMessages(); + } + + + public void clearErrorMessages() { + JavaScript.clearErrorMessages(); } } |
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv23945/src/com/meterware/httpunit Modified Files: HTMLSegment.java HttpUnitUtils.java ParsedHTML.java WebLink.java WebResponse.java Added Files: HTMLElementPredicate.java Log Message: Make link searching mechanism more generic ***** Error reading new file[Errno 2] No such file or directory: 'HTMLElementPredicate.java' Index: HTMLSegment.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLSegment.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- HTMLSegment.java 22 Aug 2002 16:19:54 -0000 1.4 +++ HTMLSegment.java 13 Sep 2002 14:17:25 -0000 1.5 @@ -71,6 +71,20 @@ /** + * Returns the first link found in the page matching the specified criteria. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink getFirstMatchingLink( HTMLElementPredicate predicate, Object value ) throws SAXException; + + + /** + * Returns all links found in the page matching the specified criteria. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink[] getMatchingLinks( HTMLElementPredicate predicate, Object criteria ) throws SAXException; + + + /** * Returns the images found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the segment. **/ @@ -140,5 +154,6 @@ * @exception SAXException thrown if there is an error parsing the segment. **/ public WebTable getTableWithID( final String ID ) throws SAXException; - + + } Index: HttpUnitUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HttpUnitUtils.java 29 Aug 2002 18:39:11 -0000 1.10 +++ HttpUnitUtils.java 13 Sep 2002 14:17:25 -0000 1.11 @@ -133,4 +133,43 @@ } return result; } + + + /** + * Return true if the first string contains the second. + * Case sensitivity is according to the setting of HttpUnitOptions.matchesIgnoreCase + */ + static boolean contains( String string, String substring ) { + if (HttpUnitOptions.getMatchesIgnoreCase()) { + return string.toUpperCase().indexOf( substring.toUpperCase() ) >= 0; + } else { + return string.indexOf( substring ) >= 0; + } + } + + + /** + * Return true if the first string starts with the second. + * Case sensitivity is according to the setting of HttpUnitOptions.matchesIgnoreCase + */ + static boolean hasPrefix( String string, String prefix ) { + if (HttpUnitOptions.getMatchesIgnoreCase()) { + return string.toUpperCase().startsWith( prefix.toUpperCase() ); + } else { + return string.startsWith( prefix ); + } + } + + + /** + * Return true if the first string equals the second. + * Case sensitivity is according to the setting of HttpUnitOptions.matchesIgnoreCase + */ + static boolean matches( String string1, String string2 ) { + if (HttpUnitOptions.getMatchesIgnoreCase()) { + return string1.equalsIgnoreCase( string2 ); + } else { + return string1.equals( string2 ); + } + } } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- ParsedHTML.java 30 Aug 2002 15:20:09 -0000 1.27 +++ ParsedHTML.java 13 Sep 2002 14:17:25 -0000 1.28 @@ -125,7 +125,7 @@ public WebLink getLinkWith( String text ) { WebLink[] links = getLinks(); for (int i = 0; i < links.length; i++) { - if (contains( links[i].asText(), text )) return links[i]; + if (HttpUnitUtils.contains( links[i].asText(), text )) return links[i]; } return null; } @@ -169,6 +169,31 @@ /** + * Returns the first link found in the page matching the specified criteria. + **/ + public WebLink getFirstMatchingLink( HTMLElementPredicate predicate, Object criteria ) { + WebLink[] links = getLinks(); + for (int i = 0; i < links.length; i++) { + if (predicate.matchesCriteria( links[i], criteria )) return links[i]; + } + return null; + } + + + /** + * Returns all links found in the page matching the specified criteria. + **/ + public WebLink[] getMatchingLinks( HTMLElementPredicate predicate, Object criteria ) { + ArrayList matches = new ArrayList(); + WebLink[] links = getLinks(); + for (int i = 0; i < links.length; i++) { + if (predicate.matchesCriteria( links[i], criteria )) matches.add( links[i] ); + } + return (WebLink[]) matches.toArray( new WebLink[ matches.size() ] ); + } + + + /** * Returns the images found in the page in the order in which they appear. **/ public WebImage[] getImages() { @@ -242,7 +267,7 @@ public boolean isTrue( WebTable table ) { table.purgeEmptyCells(); return table.getRowCount() > 0 && - matches( table.getCellAsText(0,0), text ); + HttpUnitUtils.matches( table.getCellAsText(0,0), text ); } } ); } @@ -258,7 +283,7 @@ public boolean isTrue( WebTable table ) { table.purgeEmptyCells(); return table.getRowCount() > 0 && - hasPrefix( table.getCellAsText(0,0).toUpperCase(), text ); + HttpUnitUtils.hasPrefix( table.getCellAsText(0,0).toUpperCase(), text ); } } ); } @@ -272,7 +297,7 @@ public WebTable getTableWithSummary( final String summary ) { return getTableSatisfyingPredicate( getTables(), new TablePredicate() { public boolean isTrue( WebTable table ) { - return matches( table.getSummary(), summary ); + return HttpUnitUtils.matches( table.getSummary(), summary ); } } ); } @@ -286,7 +311,7 @@ public WebTable getTableWithID( final String ID ) { return getTableSatisfyingPredicate( getTables(), new TablePredicate() { public boolean isTrue( WebTable table ) { - return matches( table.getID(), ID ); + return HttpUnitUtils.matches( table.getID(), ID ); } } ); } @@ -382,33 +407,6 @@ private String _baseTarget; private String _characterSet; - - - private boolean contains( String string, String substring ) { - if (HttpUnitOptions.getMatchesIgnoreCase()) { - return string.toUpperCase().indexOf( substring.toUpperCase() ) >= 0; - } else { - return string.indexOf( substring ) >= 0; - } - } - - - private boolean hasPrefix( String string, String prefix ) { - if (HttpUnitOptions.getMatchesIgnoreCase()) { - return string.toUpperCase().startsWith( prefix.toUpperCase() ); - } else { - return string.startsWith( prefix ); - } - } - - - private boolean matches( String string1, String string2 ) { - if (HttpUnitOptions.getMatchesIgnoreCase()) { - return string1.equalsIgnoreCase( string2 ); - } else { - return string1.equals( string2 ); - } - } private String getValue( Node node ) { Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- WebLink.java 5 Sep 2002 19:10:44 -0000 1.27 +++ WebLink.java 13 Sep 2002 14:17:25 -0000 1.28 @@ -39,6 +39,9 @@ **/ public class WebLink extends FixedURLWebRequestSource { + /** Predicate to match part or all of a link's URL string. **/ + public final static HTMLElementPredicate MATCH_URL_STRING; + private Scriptable _scriptable; @@ -144,6 +147,17 @@ Scriptable getScriptableObject() { if (_scriptable == null) _scriptable = new Scriptable(); return _scriptable; + } + + + static { + MATCH_URL_STRING = new HTMLElementPredicate() { + public boolean matchesCriteria( Object htmlElement, Object criteria ) { + return HttpUnitUtils.contains( ((WebLink) htmlElement).getURLString(), (String) criteria ); + }; + }; + + } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.78 retrieving revision 1.79 diff -u -r1.78 -r1.79 --- WebResponse.java 30 Aug 2002 18:17:48 -0000 1.78 +++ WebResponse.java 13 Sep 2002 14:17:25 -0000 1.79 @@ -363,6 +363,24 @@ /** + * Returns the first link found in the page matching the specified criteria. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink getFirstMatchingLink( HTMLElementPredicate predicate, Object criteria ) throws SAXException { + return getReceivedPage().getFirstMatchingLink( predicate, criteria ); + } + + + /** + * Returns all links found in the page matching the specified criteria. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink[] getMatchingLinks( HTMLElementPredicate predicate, Object criteria ) throws SAXException { + return getReceivedPage().getMatchingLinks( predicate, criteria ); + } + + + /** * Returns the images found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ |
From: Russell G. <rus...@us...> - 2002-09-13 14:17:28
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv23945/doc Modified Files: release_notes.txt Log Message: Make link searching mechanism more generic Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.159 retrieving revision 1.160 diff -u -r1.159 -r1.160 --- release_notes.txt 9 Sep 2002 20:04:25 -0000 1.159 +++ release_notes.txt 13 Sep 2002 14:17:25 -0000 1.160 @@ -11,6 +11,14 @@ Revision History: +13-Sep-2002 +Acknowledgements: + Thanks to Jin Zhao for help in expanding the search possibilities for links. + +Additions: + 1. The mechanism for search for links has been expanded to permit arbitrary search criteria and to retrieve + either the first match or all matches. + 9-Sep-2002 Acknowledgement: 1. Thanks to Donald Ball for pointing out the problem with the behavior of Select.selectedIndex. |
From: Russell G. <rus...@us...> - 2002-09-13 14:17:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv23945/test/com/meterware/httpunit Modified Files: WebLinkTest.java Log Message: Make link searching mechanism more generic Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebLinkTest.java 15 Aug 2002 18:29:08 -0000 1.23 +++ WebLinkTest.java 13 Sep 2002 14:17:26 -0000 1.24 @@ -61,6 +61,7 @@ "have <a href=\"/other.html\" id=\"activeID\">an <b>active</b> link</A>\n" + " and <a name=here>an anchor</a>\n" + "<a href=\"basic.html\" name=\"nextLink\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" + + "<a href=\"another.html\" name=\"myLink\">some text</a>\n" + "</body></html>\n" ); WebConversation wc = new WebConversation(); @@ -80,8 +81,8 @@ public void testLinks() throws Exception { WebLink[] links = _simplePage.getLinks(); - assertNotNull( links ); - assertEquals( 2, links.length ); + assertNotNull( "Found no links", links ); + assertEquals( "number of links in page", 3, links.length ); } @@ -118,6 +119,24 @@ HttpUnitOptions.setImagesTreatedAsAltText( false ); link = _simplePage.getLinkWith( "Next -->" ); assertNull( "the image link was found based on its hidden alt attribute", link ); + } + + + public void testCustomMatching() throws Exception { + WebLink link = _simplePage.getFirstMatchingLink( WebLink.MATCH_URL_STRING, "nothing" ); + assertNull( "Non-existent link should not have been found", link ); + + link = _simplePage.getFirstMatchingLink( WebLink.MATCH_URL_STRING, "/other.html" ); + assertNotNull( "an active link was not found", link ); + assertEquals( "active link text", "an active link", link.asText() ); + + link = _simplePage.getFirstMatchingLink( WebLink.MATCH_URL_STRING, "basic" ); + assertNotNull( "the image link was not found", link ); + assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); + + WebLink[] links = _simplePage.getMatchingLinks( WebLink.MATCH_URL_STRING, "other.ht" ); + assertNotNull( "No link array returned", links ); + assertEquals( "Number of links with URL containing 'other.ht'", 2, links.length ); } |
From: Russell G. <rus...@us...> - 2002-09-06 15:06:55
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv22076/test/com/meterware/servletunit Modified Files: WebXMLTest.java Log Message: Ville Skyttä: Removed xerces test dependency Index: WebXMLTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- WebXMLTest.java 19 Jun 2002 13:47:20 -0000 1.10 +++ WebXMLTest.java 6 Sep 2002 15:06:52 -0000 1.11 @@ -21,25 +21,25 @@ *******************************************************************************************************************/ import com.meterware.httpunit.*; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.PrintWriter; -import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.Properties; +import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletException; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; -import org.xml.sax.SAXException; -import org.xml.sax.InputSource; import org.w3c.dom.Document; -import org.apache.xerces.parsers.DOMParser; +import org.xml.sax.SAXException; -import junit.framework.TestSuite; import junit.framework.TestCase; +import junit.framework.TestSuite; public class WebXMLTest extends TestCase { @@ -143,11 +143,9 @@ } - private Document newDocument( String contents ) throws UnsupportedEncodingException, SAXException, IOException { - DOMParser parser = new DOMParser(); - parser.parse( new InputSource( toInputStream( contents ) ) ); - return parser.getDocument(); - } + private Document newDocument( String contents ) throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException { + DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); + return fac.newDocumentBuilder().parse( toInputStream( contents ) ); } private ByteArrayInputStream toInputStream( String contents ) throws UnsupportedEncodingException { |