[Httpunit-commit] SF.net SVN: httpunit:[1042] trunk/httpunit
Brought to you by:
russgold
|
From: <wol...@us...> - 2009-08-20 07:07:36
|
Revision: 1042
http://httpunit.svn.sourceforge.net/httpunit/?rev=1042&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 07:07:28 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
proposed fix for BR 2407470 Regression in httpUnit-1.7 by redsonic with Patch from Adam Heath
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java
trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java
trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java 2009-08-19 10:08:00 UTC (rev 1041)
+++ trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java 2009-08-20 07:07:28 UTC (rev 1042)
@@ -450,10 +450,13 @@
/**
* Determines whether script errors result in exceptions or warning messages.
+ * @return the current state
*/
- public static void setExceptionsThrownOnScriptError( boolean throwExceptions ) {
+ public static boolean setExceptionsThrownOnScriptError( boolean throwExceptions ) {
+ boolean current=_exceptionsThrownOnScriptError;
_exceptionsThrownOnScriptError = throwExceptions;
getScriptingEngine().setThrowExceptionsOnError( throwExceptions );
+ return current;
}
Modified: trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java 2009-08-19 10:08:00 UTC (rev 1041)
+++ trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java 2009-08-20 07:07:28 UTC (rev 1042)
@@ -97,6 +97,7 @@
* @return an array of objects representing the forms in the page or portion of a page.
**/
public WebForm[] getForms() {
+ loadElements();
HTMLCollection forms = ((HTMLContainerElement) _rootNode).getForms();
WebForm[] result = new WebForm[ forms.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -116,6 +117,7 @@
* Returns the links found in the page in the order in which they appear.
**/
public WebLink[] getLinks() {
+ loadElements();
HTMLCollection links = ((HTMLContainerElement) _rootNode).getLinks();
WebLink[] result = new WebLink[ links.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -133,6 +135,7 @@
* Returns a proxy for each applet found embedded in this page.
*/
public WebApplet[] getApplets() {
+ loadElements();
HTMLCollection applets = ((HTMLContainerElement) _rootNode).getApplets();
WebApplet[] result = new WebApplet[ applets.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -150,6 +153,7 @@
* Returns the images found in the page in the order in which they appear.
*/
public WebImage[] getImages() {
+ loadElements();
HTMLCollection images = ((HTMLContainerElement) _rootNode).getImages();
WebImage[] result = new WebImage[ images.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -167,6 +171,7 @@
* Returns the top-level block elements found in the page in the order in which they appear.
*/
public TextBlock[] getTextBlocks() {
+ loadElements();
if (_blocks == null) {
loadElements();
_blocks = (TextBlock[]) _blocksList.toArray( new TextBlock[ _blocksList.size() ] );
@@ -179,6 +184,7 @@
* Returns the first text block found in the page which matches the specified predicate and value.
*/
public TextBlock getFirstMatchingTextBlock( HTMLElementPredicate predicate, Object criteria ) {
+ loadElements();
TextBlock[] blocks = getTextBlocks();
for (int i = 0; i < blocks.length; i++) {
if (predicate.matchesCriteria( blocks[i], criteria )) return blocks[i];
@@ -187,7 +193,13 @@
}
+ /**
+ * get the next text block based on the given block
+ * @param block
+ * @return - the next text block
+ */
public TextBlock getNextTextBlock( TextBlock block ) {
+ loadElements();
int index = _blocksList.indexOf( block );
if (index < 0 || index == _blocksList.size() - 1) return null;
return (TextBlock) _blocksList.get( index+1 );
@@ -196,8 +208,10 @@
/**
* Returns the top-level tables found in the page in the order in which they appear.
+ * @return an array of tables
**/
public WebTable[] getTables() {
+ loadElements();
if (_tables == null) {
loadElements();
_tables = (WebTable[]) _tableList.toArray( new WebTable[ _tableList.size() ] );
Modified: trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java 2009-08-19 10:08:00 UTC (rev 1041)
+++ trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java 2009-08-20 07:07:28 UTC (rev 1042)
@@ -65,6 +65,38 @@
"</form>" );
}
+ /**
+ * placeholder for test for BR 2407470 by redsonic with comment and patch by Adam Heath
+ *
+ */
+ public void testGetFormWithID() throws Exception {
+ defineWebPage( "OnCommand",
+ "<html>\n"+
+ " <head>\n"+
+ " <script type='JavaScript'>\n" +
+ " function function1() {\n"+
+ " alert( document.forms[0].name );\n" +
+ " }\n"+
+ " </script>\n" +
+ " </head>\n" +
+ " <body>\n"+
+ " <form id='form1' name='form1name'/>\n" +
+ " <form id='form2' name='form2name'/>\n" +
+ " <form id='form3' name='form3name'/>\n" +
+ " <body>\n"+
+ "</html>\n");
+ boolean oldstate = HttpUnitOptions.setExceptionsThrownOnScriptError(false);
+ try {
+ WebConversation wc = new WebConversation();
+ WebResponse wr=wc.getResponse( getHostPath() + "/OnCommand.html" );
+ WebForm form = wr.getFormWithID( "form3" );
+ assertTrue(form!=null);
+ } catch (Exception ex) {
+ throw ex;
+ } finally {
+ HttpUnitOptions.setExceptionsThrownOnScriptError(oldstate);
+ }
+ }
public void testSubmitFromForm() throws Exception {
defineWebPage( "Form", "<form method=GET id=main action = 'tryMe'>" +
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|