Julien HENRY wrote:
Hi all,
Recently I did some modifications (mainly fix easiest bugs and upgrade
some dependencies). I don't know when I will have more time to work on
JWebUnit. Moreover HtmlUnit 1.14 will be the latest Java 1.4 compatible
release and the migration to HtmlUnit 2.0 will required a bit of work.
That's why I would like to release JWebUnit 1.5 even if there are still
lots of feature requests.
What do you think?
Regards
Julien
+1
BTW: I have a slightly different fix for a checkbox problem. (See the
patch).
I think XPath expression does not work well if the id contains colon
(which unfortunately is a common convention in my project). I meant to
write a unit test to pin-point this but did not have time yet.
Damian
>From 7095d2c1565e4b0268ea6a3d924ca673b213591c Mon Sep 17 00:00:00 2001
From: dkrzemin <[EMAIL PROTECTED]>
Date: Wed, 9 Apr 2008 11:48:53 -0400
Subject: [PATCH] Change checkbox support.
Add new hasCheckbox methods to allow for checking for presence of the checkbox without throwing exceptions.
Use those methods in code that sets checkbox value: the old way was to find checkboxes using XPath expression.
That does not work well if checkbox id has ':' (colon) in it.
---
.../sourceforge/jwebunit/api/IJWebUnitDialog.java | 11 ++++++++++-
.../net/sourceforge/jwebunit/junit/WebTester.java | 11 +++--------
.../jwebunit/htmlunit/HtmlUnitDialog.java | 18 ++++++++++++++++++
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java b/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
index 3cafe46..09aae35 100644
--- a/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
+++ b/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
@@ -292,6 +292,16 @@ public interface IJWebUnitDialog {
boolean hasSelectOptionValue(String selectName, String optionValue);
/**
+ * Determines if the checkbox is present.
+ *
+ * @param checkBoxName name of the checkbox.
+ * @return true if the first checkbox with given name is present .
+ */
+ boolean hasCheckbox(String checkBoxName);
+
+ boolean hasCheckbox(String checkboxName, String checkboxValue);
+
+ /**
* Determines if the checkbox is selected.
*
* @param checkBoxName name of the checkbox.
@@ -747,5 +757,4 @@ public interface IJWebUnitDialog {
*/
void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts)
throws ExpectedJavascriptPromptException;
-
}
diff --git a/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java b/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
index cc08480..ffd048b 100644
--- a/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
+++ b/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
@@ -730,8 +730,7 @@ public class WebTester {
public void assertCheckboxPresent(String checkboxName) {
assertFormPresent();
Assert.assertTrue("Did not find form checkbox with name ["
- + checkboxName + "].", getTestingEngine().hasElementByXPath(
- "//[EMAIL PROTECTED]'checkbox' and @name='" + checkboxName + "']"));
+ + checkboxName + "].", getTestingEngine().hasCheckbox(checkboxName));
}
/**
@@ -743,10 +742,7 @@ public class WebTester {
public void assertCheckboxPresent(String checkboxName, String checkboxValue) {
assertFormPresent();
Assert.assertTrue("Did not find form checkbox with name ["
- + checkboxName + "] and value [" + checkboxValue + "].",
- getTestingEngine().hasElementByXPath(
- "//[EMAIL PROTECTED]'checkbox' and @name='" + checkboxName
- + "' and @value='" + checkboxValue + "']"));
+ + checkboxName + "].", getTestingEngine().hasCheckbox(checkboxName, checkboxValue));
}
/**
@@ -757,8 +753,7 @@ public class WebTester {
public void assertCheckboxNotPresent(String checkboxName) {
assertFormPresent();
Assert.assertFalse("Found form checkbox with name [" + checkboxName
- + "] when not expected.", getTestingEngine().hasElementByXPath(
- "//[EMAIL PROTECTED]'checkbox' and @name='" + checkboxName + "']"));
+ + "] when not expected.", getTestingEngine().hasCheckbox(checkboxName));
}
/**
diff --git a/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java b/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
index 348b0c1..af6c529 100644
--- a/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
+++ b/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
@@ -1249,6 +1249,24 @@ public class HtmlUnitDialog implements IJWebUnitDialog {
}
}
+ public boolean hasCheckbox(String checkboxName) {
+ try {
+ return getCheckbox(checkboxName) != null;
+ } catch (RuntimeException e) {
+ // FIXME: should be a special exception
+ return false;
+ }
+ }
+
+ public boolean hasCheckbox(String checkboxName, String checkboxValue) {
+ try {
+ return getCheckbox(checkboxName, checkboxValue) != null;
+ } catch (RuntimeException e) {
+ // FIXME: should be a special exception
+ return false;
+ }
+ }
+
public boolean isCheckboxSelected(String checkBoxName) {
HtmlCheckBoxInput cb = getCheckbox(checkBoxName);
return cb.isChecked();
--
1.5.4.1
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development