Revision: 583
http://svn.sourceforge.net/jwebunit/?rev=583&view=rev
Author: henryju
Date: 2006-10-17 05:43:34 -0700 (Tue, 17 Oct 2006)
Log Message:
-----------
Refactor IJWebUnitDialog interface (much smaller).
Continue refactoring of unit tests.
PART 2 (due to sourceforge bug).
Modified Paths:
--------------
trunk/jwebunit-commons-tests/pom.xml
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/HtmlParsingTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JWebUnitAPITestCase.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
trunk/pom.xml
Modified: trunk/jwebunit-commons-tests/pom.xml
===================================================================
--- trunk/jwebunit-commons-tests/pom.xml 2006-10-17 12:42:51 UTC (rev
582)
+++ trunk/jwebunit-commons-tests/pom.xml 2006-10-17 12:43:34 UTC (rev
583)
@@ -21,7 +21,7 @@
</dependency>
<dependency>
<groupId>net.sourceforge.jwebunit</groupId>
- <artifactId>jwebunit-core</artifactId>
+ <artifactId>jwebunit-junit-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/CharsetTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -6,6 +6,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.locator.HtmlTextInputLocatorByName;
import net.sourceforge.jwebunit.tests.util.JettySetup;
/**
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -10,6 +10,15 @@
import java.io.IOException;
import java.net.URL;
+import net.sourceforge.jwebunit.locator.HtmlAnchorLocatorByText;
+import net.sourceforge.jwebunit.locator.HtmlButtonLocatorByName;
+import net.sourceforge.jwebunit.locator.HtmlCheckboxInputLocatorByName;
+import net.sourceforge.jwebunit.locator.HtmlFileInputLocatorByName;
+import net.sourceforge.jwebunit.locator.HtmlFormLocatorByName;
+import net.sourceforge.jwebunit.locator.HtmlResetInputLocator;
+import net.sourceforge.jwebunit.locator.HtmlSubmitInputLocator;
+import net.sourceforge.jwebunit.locator.HtmlSubmitInputLocatorByName;
+import net.sourceforge.jwebunit.locator.HtmlTextInputLocatorByName;
import net.sourceforge.jwebunit.tests.util.JettySetup;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
@@ -37,25 +46,25 @@
public void testSetTextField() {
beginAt("/SingleNamedButtonForm.html");
- setTextField("color", "blue");
- submit("button");
+ setTextField(new HtmlTextInputLocatorByName("color"), "blue");
+ click(new HtmlSubmitInputLocatorByName("button"));
assertTextPresent("Submitted parameters");
assertTextPresent("Params are: color=blue");
- clickLink("return");
- setTextField("color", "red");
- submit();
+ click(new HtmlAnchorLocatorByText("return"));
+ setTextField(new HtmlTextInputLocatorByName("color"), "red");
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Params are: color=red");
}
public void testSetTextArea() {
beginAt("/TextAreaForm.html");
- setTextField("text", "sometext");
- submit("button");
+ setTextField(new HtmlTextInputLocatorByName("text"), "sometext");
+ click(new HtmlSubmitInputLocatorByName("button"));
assertTextPresent("Submitted parameters");
assertTextPresent("Params are: text=sometext");
- clickLink("return");
- setTextField("text", "anothertext");
- submit();
+ click(new HtmlAnchorLocatorByText("return"));
+ setTextField(new HtmlTextInputLocatorByName("text"), "anothertext");
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Params are: text=anothertext");
}
@@ -75,17 +84,17 @@
fail(e.toString());
}
String filename = temp.getAbsolutePath();
- setTextField("file", filename);
- submit("button");
+ setTextField(new HtmlFileInputLocatorByName("file"), filename);
+ click(new HtmlSubmitInputLocatorByName("button"));
assertTextPresent("Submitted parameters");
assertTextPresent("file=" + temp.getName() + "{abcdefgh}");
}
public void testCheckBoxSelection() {
beginAt("/SingleNamedButtonForm.html");
- checkCheckbox("checkBox");
- setTextField("color", "blue");
- submit();
+ click(new HtmlCheckboxInputLocatorByName("checkBox"));
+ setTextField(new HtmlTextInputLocatorByName("color"), "blue");
+ click(new HtmlSubmitInputLocator());
// checkBox contains 2 parameters: one for the hidden input and one for
// the checkbox
assertTextPresent("Params are: color=blue checkBox=,on");
@@ -93,60 +102,68 @@
public void testCheckBoxSelectionWithSameFieldName() {
beginAt("/CheckboxForm.html");
- checkCheckbox("checkBox", "1");
- checkCheckbox("checkBox", "3");
- checkCheckbox("checkBox", "3"); // check for duplicates
- submit();
+ HtmlCheckboxInputLocatorByName cb1 = new
HtmlCheckboxInputLocatorByName("checkBox");
+ cb1.addAttribut("value", "1");
+ click(cb1);
+ HtmlCheckboxInputLocatorByName cb2 = new
HtmlCheckboxInputLocatorByName("checkBox");
+ cb1.addAttribut("value", "3");
+ click(cb2);
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Params are: checkBox=1,3 ");
}
public void testCheckBoxDeSelectionWithSameFieldName() {
beginAt("/CheckboxForm.html");
- checkCheckbox("checkBox", "1");
- checkCheckbox("checkBox", "3");
- uncheckCheckbox("checkBox", "3");
- submit();
+ HtmlCheckboxInputLocatorByName cb1 = new
HtmlCheckboxInputLocatorByName("checkBox");
+ cb1.addAttribut("value", "1");
+ click(cb1);
+ HtmlCheckboxInputLocatorByName cb2 = new
HtmlCheckboxInputLocatorByName("checkBox");
+ cb1.addAttribut("value", "3");
+ click(cb2);
+ click(cb2);
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Params are: checkBox=1");
}
public void testCheckBoxDeselection() {
beginAt("/SingleNamedButtonForm.html");
- checkCheckbox("checkBox"); // Fail with httpunit because of hidden
- // field with same name
- assertCheckboxSelected("checkBox");
- setTextField("color", "blue");
- uncheckCheckbox("checkBox");
- submit();
+ click(new HtmlCheckboxInputLocatorByName("checkBox"));
+ assertCheckboxSelected(new HtmlCheckboxInputLocatorByName("checkBox"));
+ setTextField(new HtmlTextInputLocatorByName("color"), "blue");
+ click(new HtmlCheckboxInputLocatorByName("checkBox"));
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Params are: color=blue ");
}
public void testSingleFormSingleUnnamedButtonSubmission() {
beginAt("/SingleUnnamedButtonForm.html");
- setTextField("color", "blue");
- submit();
+ setTextField(new HtmlTextInputLocatorByName("color"), "blue");
+ click(new HtmlSubmitInputLocator());
assertTextPresent(" color=blue ");
}
public void testSingleNamedButtonSubmission() {
beginAt("/SingleNamedButtonForm.html");
- setTextField("color", "red");
- submit();
+ setTextField(new HtmlTextInputLocatorByName("color"), "red");
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Params are: color=red");
}
public void testSingleFormMultipleButtonSubmission() {
gotoMultiButtonPage();
- submit("color");
+ click(new HtmlSubmitInputLocatorByName("color"));
assertTextPresent("Params are: color=red");
gotoMultiButtonPage();
- submit("color", "blue");
+ HtmlSubmitInputLocatorByName l = new
HtmlSubmitInputLocatorByName("color");
+ l.addAttribut("value", "blue");
+ click(l);
assertTextPresent("Params are: color=blue");
}
public void testBogusParameter() {
gotoMultiButtonPage();
try {
- setTextField("nonexistent", "anyvalue");
+ setTextField(new HtmlTextInputLocatorByName("nonexistent"),
"anyvalue");
} catch (AssertionFailedError e) {
return;
}
@@ -155,32 +172,32 @@
public void testParamSetOnMultiForm() {
beginAt("/MultiFormPage.html");
- setTextField("param1", "anyvalue");
- setWorkingForm("form2");
- setTextField("param2", "anyvalue");
- submit("button2a");
+ setTextField(new HtmlTextInputLocatorByName("param1"), "anyvalue");
+ setWorkingForm(new HtmlFormLocatorByName("form2"));
+ setTextField(new HtmlTextInputLocatorByName("param2"), "anyvalue");
+ click(new HtmlSubmitInputLocatorByName("button2a"));
assertTextPresent("param2=anyvalue");
}
public void testSetWorkingFormById() {
beginAt("/MultiFormPage.html");
- setWorkingForm("form5");
+ setWorkingForm(new HtmlFormLocatorByName("form5"));
}
public void testSetWorkingFormWithSameName() {
beginAt("/MultiFormPage.html");
- setWorkingForm("myForm", 0);
- assertSubmitButtonPresent("myInput1");
- assertSubmitButtonNotPresent("myInput2");
- setWorkingForm("myForm", 1);
- assertSubmitButtonNotPresent("myInput1");
- assertSubmitButtonPresent("myInput2");
+ setWorkingForm(new HtmlFormLocatorByName("myForm", 0));
+ assertElementPresent(new HtmlSubmitInputLocatorByName("myInput1"));
+ assertElementNotPresent(new HtmlSubmitInputLocatorByName("myInput2"));
+ setWorkingForm(new HtmlFormLocatorByName("myForm", 1));
+ assertElementNotPresent(new HtmlSubmitInputLocatorByName("myInput1"));
+ assertElementPresent(new HtmlSubmitInputLocatorByName("myInput2"));
}
public void testInvalidButton() {
beginAt("/InvalidActionForm.html");
try {
- submit("button1");
+ click(new HtmlSubmitInputLocatorByName("button1"));
fail("Should have failed because the target page does not exist");
} catch (RuntimeException e) {
// TODO Have a better way to know if 404 happened
@@ -190,24 +207,24 @@
public void testUnnamedSubmitOnSpecificForm() {
beginAt("/MultiFormPage.html");
- setTextField("param4", "anyvalue");
- submit();
+ setTextField(new HtmlTextInputLocatorByName("param4"), "anyvalue");
+ click(new HtmlSubmitInputLocator());
assertTextPresent("param4=anyvalue");
}
public void testNamedSubmitOnSpecificForm() {
beginAt("/MultiFormPage.html");
- setTextField("param2", "anyvalue");
- submit("button2b");
+ setTextField(new HtmlTextInputLocatorByName("param2"), "anyvalue");
+ click(new HtmlSubmitInputLocatorByName("button2b"));
assertTextPresent("param2=anyvalue ");
assertTextPresent(" button2b=b2b");
}
public void testSubmissionReset() {
beginAt("/MultiFormPage.html");
- setTextField("param2", "anyvalue");
- reset();
- submit("button2b");
+ setTextField(new HtmlTextInputLocatorByName("param2"), "anyvalue");
+ click(new HtmlResetInputLocator());
+ click(new HtmlSubmitInputLocatorByName("button2b"));
assertTextNotPresent("param2=anyvalue ");
assertTextPresent(" button2b=b2b");
}
@@ -221,7 +238,7 @@
public void testSelectOptionInAnotherForm() {
beginAt("/MultiFormPage.html");
- setWorkingForm("form6bis");
+ setWorkingForm(new HtmlFormLocatorByName("form6bis"));
assertSelectedOptionEquals("select1", "four");
selectOption("select1", "five");
assertSelectedOptionEquals("select1", "five");
@@ -241,9 +258,9 @@
public void testCachedForm() {
beginAt("/Submit1.html");
assertTextPresent("Page 1");
- submit();
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Page 2");
- submit();
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Page 3");
}
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -6,6 +6,9 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.locator.HtmlAnchorLocator;
+import net.sourceforge.jwebunit.locator.HtmlAnchorLocatorByText;
+import net.sourceforge.jwebunit.locator.WindowLocatorByName;
import net.sourceforge.jwebunit.tests.util.JettySetup;
/**
@@ -29,7 +32,7 @@
public void testHttpUnitWithRhinoForWindowOpen() throws Throwable {
try {
beginAt("RootPage.html");
- clickLink("ChildPage1"); // does javascript:window.open(...)
+ click(new HtmlAnchorLocator("ChildPage1")); // does
javascript:window.open(...)
} catch (NoSuchFieldError e) {
fail("HttpUnit 1.6 does not support the current version of Rhino");
}
@@ -41,7 +44,7 @@
*/
private void gotoRootAndOpenChild(String childName) {
beginAt("RootPage.html");
- clickLink(childName);
+ click(new HtmlAnchorLocator(childName));
}
// ------------ windows test ------------
@@ -53,7 +56,7 @@
public void testGotoWindow() {
gotoRootAndOpenChild("ChildPage1");
- gotoWindow("ChildPage1");
+ gotoWindow(new WindowLocatorByName("ChildPage1"));
assertTextPresent("child 1");
}
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/HtmlParsingTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/HtmlParsingTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/HtmlParsingTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -6,6 +6,9 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.locator.HtmlElementLocator;
+import net.sourceforge.jwebunit.locator.HtmlFormLocator;
+import net.sourceforge.jwebunit.locator.HtmlSubmitInputLocator;
import net.sourceforge.jwebunit.tests.util.JettySetup;
/**
@@ -27,38 +30,37 @@
public void testSimpleForm() {
beginAt("SimpleForm.html");
- assertFormPresent();
- submit();
+ assertElementPresent(new HtmlFormLocator());
+ click(new HtmlSubmitInputLocator());
}
public void testInvalidForm() {
beginAt("InvalidForm.html");
- assertFormPresent();
- submit();
+ assertElementPresent(new HtmlFormLocator());
+ click(new HtmlSubmitInputLocator());
}
public void testInvalidFormNoDoctype() {
beginAt("InvalidFormNoDoctype.html");
- assertFormPresent();
- submit();
+ assertElementPresent(new HtmlFormLocator());
+ click(new HtmlSubmitInputLocator());
}
public void testValidComplexForm() {
beginAt("ValidComplexForm.html");
- assertFormPresent();
- submit();
+ assertElementPresent(new HtmlFormLocator());
+ click(new HtmlSubmitInputLocator());
}
public void testValidFormNoDoctype() {
beginAt("ValidFormNoDoctype.html");
- assertFormPresent();
- submit();
+ assertElementPresent(new HtmlFormLocator());
+ click(new HtmlSubmitInputLocator());
}
public void testXhtmlStrict() {
beginAt("XhtmlStrict.html");
// run a method that gets the DOM
- assertElementPresent("div1");
- //TODO This test gives a "org.w3c.dom.DOMException: NOT_SUPPORTED_ERR"
with nekohtml 0.9.5 and httpunit
+ assertElementPresent(new HtmlElementLocator("div1"));
}
}
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JWebUnitAPITestCase.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JWebUnitAPITestCase.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JWebUnitAPITestCase.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -7,7 +7,7 @@
import java.lang.reflect.InvocationTargetException;
import junit.framework.AssertionFailedError;
-import net.sourceforge.jwebunit.WebTestCase;
+import net.sourceforge.jwebunit.junit.WebTestCase;
import net.sourceforge.jwebunit.tests.util.reflect.MethodInvoker;
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/JavaScriptEventsTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -6,6 +6,9 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.locator.HtmlResetInputLocator;
+import net.sourceforge.jwebunit.locator.HtmlSubmitInputLocator;
+import net.sourceforge.jwebunit.locator.HtmlSubmitInputLocatorByName;
import net.sourceforge.jwebunit.tests.util.JettySetup;
/**
@@ -28,14 +31,14 @@
public void testFormOnSubmit() {
beginAt("FormOnSubmit.html");
- submit();
+ click(new HtmlSubmitInputLocator());
gotoWindow("child");
assertTextPresent("on=submit");
}
public void testFormOnReset() {
beginAt("FormOnSubmit.html");
- reset();
+ click(new HtmlResetInputLocator());
gotoWindow("child");
assertTextPresent("on=reset");
}
@@ -57,7 +60,7 @@
beginAt("index.html");
assertTitleEquals("Startpage");
- submit();
+ click(new HtmlSubmitInputLocator());
assertTextPresent("Here is the text we expect");
}
@@ -107,6 +110,6 @@
public void testFormOnSubmitSetTarget() {
beginAt("FormOnSubmitSetTarget.html");
setWorkingForm("formID");
- submit("go");
+ click(new HtmlSubmitInputLocatorByName("go"));
}
}
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebAssertionsTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -6,6 +6,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.locator.HtmlElementLocator;
import net.sourceforge.jwebunit.tests.util.JettySetup;
/**
@@ -99,7 +100,7 @@
}
public void testAssertElementPresent() throws Throwable {
- assertElementPresent("row1");
+ assertElementPresent(new HtmlElementLocator("row1"));
assertPassFail("assertElementPresent", "span_id", "no_id");
}
Modified:
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
===================================================================
---
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
2006-10-17 12:42:51 UTC (rev 582)
+++
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/XPathTest.java
2006-10-17 12:43:34 UTC (rev 583)
@@ -4,6 +4,7 @@
******************************************************************************/
package net.sourceforge.jwebunit.tests;
+import net.sourceforge.jwebunit.locator.ClickableHtmlElementLocator;
import net.sourceforge.jwebunit.tests.util.JettySetup;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -37,10 +38,20 @@
assertPassFail("assertElementNotPresentByXPath", "//InvalidXPath",
"//tr[contains(.//a/@href,\"next\") and
contains(string(),\"test link\")]");
}
+
+ private class myLink extends ClickableHtmlElementLocator {
+ public myLink() {
+ super("a");
+ }
+
+ public String getXPath() {
+ return "//tr//a[contains(@href,\"next\") and
contains(string(),\"test link\")]";
+ }
+ }
public void testClickElementByXPath() throws Throwable {
beginAt("/testPage.html");
- clickElementByXPath("//tr//a[contains(@href,\"next\") and
contains(string(),\"test link\")]");
+ click(new myLink());
assertTitleEquals("Next");
}
}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2006-10-17 12:42:51 UTC (rev 582)
+++ trunk/pom.xml 2006-10-17 12:43:34 UTC (rev 583)
@@ -23,6 +23,7 @@
<inceptionYear>2002</inceptionYear>
<modules>
<module>jwebunit-core</module>
+ <module>jwebunit-junit-plugin</module>
<module>jwebunit-commons-tests</module>
<module>jwebunit-htmlunit-plugin</module>
<module>jwebunit-selenium-plugin</module>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development