Attached is a diff that adds the ability to the the WebResponse associated with the HttpUnitDialog so that I can save a WebResponse
from earlier in the test and later set this response as if the user has hit the back button to this page. The diff also includes a test to demostrate
how I would use such a feature.
Any comments and / or suggestions would be appreciated.
Thanks, Mark Church
--
**********************************************************************
CONFIDENTIALITY NOTICE:
This E-mail and any attachments are confidential. If you are not the intended recipient, you do not have permission to disclose, copy, distribute, or open any attachments. If you have received this E-mail
in error, please notify us immediately by returning it to the sender and delete this copy from your system.
Thank you. accessIndiana, MyLocal.IN.gov, CivicNet
? backButton.patch
? junit1668107692.properties
? test/net/sourceforge/jwebunit/userlist/.RajeshNairTest.java.swp
Index: src/net/sourceforge/jwebunit/HttpUnitDialog.java
===================================================================
RCS file: /cvsroot/jwebunit/jWebUnit/src/net/sourceforge/jwebunit/HttpUnitDialog.java,v
retrieving revision 1.48
diff -u -r1.48 HttpUnitDialog.java
--- src/net/sourceforge/jwebunit/HttpUnitDialog.java 27 Sep 2004 17:10:22 -0000 1.48
+++ src/net/sourceforge/jwebunit/HttpUnitDialog.java 7 Feb 2005 19:29:17 -0000
@@ -130,6 +130,16 @@
}
/**
+ * Sets the HttpUnit object which represents the current response.
+ * This method can be used to simulate the effects of clicking the back
+ * button on the browser.
+ * @param resp The web response to go back too.
+ */
+ public void setResponse(WebResponse resp) {
+ this.resp = resp;
+ }
+
+ /**
* Return the string representation of the current response, encoded as
* specified by the current [EMAIL PROTECTED] net.sourceforge.jwebunit.TestContext}.
*/
@@ -1229,4 +1239,4 @@
}
}
-}
\ No newline at end of file
+}
Index: test/net/sourceforge/jwebunit/FormSubmissionTest.java
===================================================================
RCS file: /cvsroot/jwebunit/jWebUnit/test/net/sourceforge/jwebunit/FormSubmissionTest.java,v
retrieving revision 1.21
diff -u -r1.21 FormSubmissionTest.java
--- test/net/sourceforge/jwebunit/FormSubmissionTest.java 20 Sep 2004 15:18:51 -0000 1.21
+++ test/net/sourceforge/jwebunit/FormSubmissionTest.java 7 Feb 2005 19:29:17 -0000
@@ -24,6 +24,20 @@
addServletResource();
}
+ public void testBackButtonSubmit() {
+ addMultiForm();
+ beginAt("/QueryForm.html");
+ setFormElement("param1", "anyvalue");
+ setWorkingForm("form2");
+ setFormElement("param2", "anyvalue");
+ WebResponse currentPage = getTester().getDialog().getResponse();
+ submit("button2a");
+ assertTextPresent("param2=anyvalue");
+ getTester().getDialog().setResponse(currentPage);
+ submit("button1");
+ assertTextPresent("param1=anyvalue");
+ }
+
public void testSetInputField() {
addSingleNamedButtonForm();
beginAt("/QueryForm.html");
@@ -206,6 +220,7 @@
addTargetResource("TargetPage", "param2=anyvalue&button2b=b2b");
addTargetResource("TargetPage", "param2=anyvalue&button2a=b2a");
addTargetResource("TargetPage", "param1=oneValue¶m2=anotherValue");
+ addTargetResource("TargetPage", "param1=anyvalue");
addTargetResource("TargetPage", "param3=oneValue¶m4=anotherValue");
addTargetResource("TargetPage", "checkBox=1&checkBox=3");
addTargetResource("TargetPage", "checkBox=1");
@@ -320,4 +335,4 @@
"</form></html>");
}
-}
\ No newline at end of file
+}
