Update of /cvsroot/jwebunit/jWebUnit/src/net/sourceforge/jwebunit
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9584/src/net/sourceforge/jwebunit
Modified Files:
HttpUnitDialog.java WebTester.java WebTestCase.java
IJWebUnitDialog.java
Log Message:
Added test methods to check checkboxes that are only known by a text label. Not
yet implemented in JacobieDialog.
Index: WebTester.java
===================================================================
RCS file:
/cvsroot/jwebunit/jWebUnit/src/net/sourceforge/jwebunit/WebTester.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** WebTester.java 22 Jul 2005 01:24:54 -0000 1.59
--- WebTester.java 22 Dec 2005 18:05:00 -0000 1.60
***************
*** 1425,1428 ****
--- 1425,1462 ----
}
+ /**
+ * Identifies and checks checkbox based on a label appearing before the
input tag.
+ *
+ * Checkboxes are identified by name+value. If both are known, use
+ * [EMAIL PROTECTED] #checkCheckbox(String, String)} or [EMAIL PROTECTED]
#setFormElement(String, String)}
+ * to check the box. If name or value is unknown, use this method if
there is a
+ * known text label appearing after the checkbox.
+ *
+ * @param formElementLabel The text label, appearing after the checkbox
+ */
+ public void checkCheckboxBeforeLabel(String formElementLabel) {
+ assertTextPresent(formElementLabel);
+ String name =
getDialog().getFormElementNameBeforeLabel(formElementLabel);
+ String value =
getDialog().getFormElementValueBeforeLabel(formElementLabel);
+ checkCheckbox(name, value);
+ }
+
+ /**
+ * Identifies and checks checkbox based on a label appearing after the
input tag.
+ *
+ * Checkboxes are identified by name+value. If both are known, use
+ * [EMAIL PROTECTED] #checkCheckbox(String, String)} or [EMAIL PROTECTED]
#setFormElement(String, String)}
+ * to check the box. If name or value is unknown, use this method if
there is a
+ * known text label appearing before the checkbox.
+ *
+ * @param formElementLabel The text label, appearing after the checkbox
+ */
+ public void checkCheckboxWithLabel(String formElementLabel) {
+ assertTextPresent(formElementLabel);
+ String name =
getDialog().getFormElementNameForLabel(formElementLabel);
+ String value =
getDialog().getFormElementValueForLabel(formElementLabel);
+ checkCheckbox(name, value);
+ }
+
/**
* Deselect a specified checkbox. If the checkbox is already unchecked
then
Index: HttpUnitDialog.java
===================================================================
RCS file:
/cvsroot/jwebunit/jWebUnit/src/net/sourceforge/jwebunit/HttpUnitDialog.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** HttpUnitDialog.java 7 Dec 2005 06:07:23 -0000 1.58
--- HttpUnitDialog.java 22 Dec 2005 18:05:00 -0000 1.59
***************
*** 431,434 ****
--- 431,448 ----
*/
public String getFormElementNameForLabel(String formElementLabel) {
+ Element formElement = getFormElementForLabel(formElementLabel);
+ if (formElement != null) {
+ return formElement.getAttribute("name");
+ }
+ return null;
+ }
+
+ /**
+ * Finds the first form element after a text label
+ * @param formElementLabel
+ * @return
+ */
+ private Element getFormElementForLabel(String formElementLabel) {
+ Element formElement = null;
try {
Document document = getResponse().getDOM();
***************
*** 436,454 ****
NodeList forms = root.getElementsByTagName("form");
! for (int i = 0; i < forms.getLength(); i++) {
Element form = (Element) forms.item(i);
TextAndElementWalker walker = new TextAndElementWalker(form,
new String[] { "input", "select", "textarea" });
! Element formElement = walker
.getElementAfterText(formElementLabel);
- if (formElement != null) { return formElement
- .getAttribute("name"); }
}
! return null;
} catch (SAXException e) {
e.printStackTrace();
- return null;
}
}
--- 450,520 ----
NodeList forms = root.getElementsByTagName("form");
! for (int i = 0; i < forms.getLength() && formElement == null;
i++) {
Element form = (Element) forms.item(i);
TextAndElementWalker walker = new TextAndElementWalker(form,
new String[] { "input", "select", "textarea" });
! formElement = walker
.getElementAfterText(formElementLabel);
}
+ } catch (SAXException e) {
+ e.printStackTrace();
+ }
+ return formElement;
+ }
+
+ /**
+ * Finds the first form element before a label
+ * @param formElementLabel
+ * @return
+ */
+ private Element getFormElementBeforeLabel(String formElementLabel) {
+ Element formElement = null;
+ try {
+ Document document = getResponse().getDOM();
+ Element root = document.getDocumentElement();
+ NodeList forms = root.getElementsByTagName("form");
! for (int i = 0; i < forms.getLength() && formElement == null;
i++) {
! Element form = (Element) forms.item(i);
! TextAndElementWalkerReverse walker = new
TextAndElementWalkerReverse(form,
! new String[] { "input" });
! formElement = walker
! .getElementAfterText(formElementLabel);
! }
} catch (SAXException e) {
e.printStackTrace();
}
+ return formElement;
+ }
+
+ /**
+ * Return the name of a form parameter (input element) on the current
+ * response preceded by a givel label.
+ *
+ * @param formElementLabel
+ * label of the input element to fetch name.
+ */
+ public String getFormElementValueForLabel(String formElementLabel) {
+ Element formElement = getFormElementForLabel(formElementLabel);
+ if (formElement != null) {
+ return formElement.getAttribute("value");
+ }
+ return null;
+ }
+
+ public String getFormElementNameBeforeLabel(String formElementLabel) {
+ Element formElement = getFormElementBeforeLabel(formElementLabel);
+ if (formElement != null) {
+ return formElement.getAttribute("name");
+ }
+ return null;
+ }
+
+ public String getFormElementValueBeforeLabel(String formElementLabel) {
+ Element formElement = getFormElementBeforeLabel(formElementLabel);
+ if (formElement != null) {
+ return formElement.getAttribute("value");
+ }
+ return null;
}
Index: WebTestCase.java
===================================================================
RCS file:
/cvsroot/jwebunit/jWebUnit/src/net/sourceforge/jwebunit/WebTestCase.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** WebTestCase.java 22 Jul 2005 01:24:55 -0000 1.57
--- WebTestCase.java 22 Dec 2005 18:05:01 -0000 1.58
***************
*** 522,525 ****
--- 522,533 ----
}
+ public void checkCheckboxWithLabel(String formElementLabel) {
+ getTester().checkCheckboxWithLabel(formElementLabel);
+ }
+
+ public void checkCheckboxBeforeLabel(String formElementLabel) {
+ getTester().checkCheckboxBeforeLabel(formElementLabel);
+ }
+
public void uncheckCheckbox(String checkBoxName) {
getTester().uncheckCheckbox(checkBoxName);
Index: IJWebUnitDialog.java
===================================================================
RCS file:
/cvsroot/jwebunit/jWebUnit/src/net/sourceforge/jwebunit/IJWebUnitDialog.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** IJWebUnitDialog.java 22 Jul 2005 01:24:55 -0000 1.8
--- IJWebUnitDialog.java 22 Dec 2005 18:05:01 -0000 1.9
***************
*** 613,615 ****
--- 613,636 ----
public abstract void dumpTable(String tableNameOrId, String[][] table,
PrintStream stream);
+
+ /**
+ * Get the name of the first input element appearing before a text label.
+ * @param formElementLabel the input element label
+ * @return the 'name' attribute of the first input element preceding the
text
+ */
+ public abstract String getFormElementNameBeforeLabel(String
formElementLabel);
+
+ /**
+ * Get the vale of the first input element appearing before a text label.
+ * @param formElementLabel the input element label
+ * @return the 'value' attribute of the first input element preceding the
text
+ */
+ public abstract String getFormElementValueBeforeLabel(String
formElementLabel);
+
+ /**
+ * Get the value of the first input element appearing after a text label.
+ * @param formElementLabel the input element label
+ * @return the 'name' attribute of the first input element preceding the
text
+ */
+ public abstract String getFormElementValueForLabel(String
formElementLabel);
}
\ No newline at end of file
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development