Revision: 627
http://svn.sourceforge.net/jwebunit/?rev=627&view=rev
Author: henryju
Date: 2006-11-27 03:13:19 -0800 (Mon, 27 Nov 2006)
Log Message:
-----------
Add the possibility to manipulate frame by ID.
Modified Paths:
--------------
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FramesAndWindowsTest/Frames.html
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
branches/1.x/src/changes/changes.xml
Modified:
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
===================================================================
---
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
2006-11-24 14:11:31 UTC (rev 626)
+++
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
2006-11-27 11:13:19 UTC (rev 627)
@@ -119,7 +119,22 @@
assertTextPresent("ContentFrame");
}
- public void testGotoInlineFrame() {
+ public void testGotoFrameById() {
+ beginAt("Frames.html");
+ assertFramePresent("frame1");
+ gotoFrame("frame1");
+ assertTextPresent("TopFrame");
+ gotoRootWindow();
+ assertFramePresent("frame3");
+ gotoFrame("frame3");
+ assertTextPresent("BottomFrame");
+ gotoRootWindow();
+ assertFramePresent("frame2");
+ gotoFrame("frame2");
+ assertTextPresent("ContentFrame");
+ }
+
+ public void testGotoInlineFrame() {
beginAt("InlineFrame.html");
assertTextPresent("TopFrame");
// Is this how it should work? see also the test below
Modified:
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FramesAndWindowsTest/Frames.html
===================================================================
---
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FramesAndWindowsTest/Frames.html
2006-11-24 14:11:31 UTC (rev 626)
+++
branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/FramesAndWindowsTest/Frames.html
2006-11-27 11:13:19 UTC (rev 627)
@@ -1,8 +1,8 @@
<html>
<head></head>
<frameset rows="33%, 33%, 33%">
-<frame name="TopFrame" src="TopFrame.html">
-<frame name="ContentFrame" src="ContentFrame.html">
-<frame name="BottomFrame" src="BottomFrame.html">
+<frame id="frame1" name="TopFrame" src="TopFrame.html">
+<frame id="frame2" name="ContentFrame" src="ContentFrame.html">
+<frame id="frame3" name="BottomFrame" src="BottomFrame.html">
</frameset>
</html>
\ No newline at end of file
Modified:
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
===================================================================
---
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
2006-11-24 14:11:31 UTC (rev 626)
+++
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IJWebUnitDialog.java
2006-11-27 11:13:19 UTC (rev 627)
@@ -129,17 +129,17 @@
/**
* Test if the given frame is present.
*
- * @param frameName Frame's name.
+ * @param frameNameOrId Name or ID of the frame. ID is checked first.
* @return true if the frame exists.
*/
- boolean hasFrame(String frameName);
+ boolean hasFrame(String frameNameOrId);
/**
- * Make the frame with the given name active in the current conversation.
+ * Make the frame with the given name or ID active in the current
conversation.
*
- * @param frameName Frame's name.
+ * @param frameNameOrId Name or ID of the frame. ID is checked first.
*/
- void gotoFrame(String frameName);
+ void gotoFrame(String frameNameOrId);
/**
* Set the form on the current page that the client wishes to work with
explicitly by index in the page.
@@ -507,12 +507,14 @@
/**
* Return the string representation of the current page, encoded as
specified by the current
* [EMAIL PROTECTED] net.sourceforge.jwebunit.util.TestContext}.
+ *
* @return Visible text in the page.
*/
String getPageText();
/**
* Return the source of the current page (like in a browser).
+ *
* @return Source of the page (or HTTP Body as String)
*/
String getPageSource();
@@ -520,18 +522,21 @@
/**
* Return the page title of the current response page, encoded as
specified by the current
* [EMAIL PROTECTED] net.sourceforge.jwebunit.util.TestContext}.
+ *
* @return Title of the page.
*/
String getPageTitle();
/**
* Return the response of the server for the current page.
+ *
* @return HTTP header & body
*/
String getServerResponse();
-
+
/**
* Save the last server response as file to the disk.
+ *
* @param f The file name.
*/
void saveAs(File f);
@@ -651,8 +656,8 @@
void clickElementByXPath(String xpath);
/**
- * Get attribut value of the given element. For example, if
- * you have img src="bla.gif" alt="toto",
getElementAttributByXPath("//[EMAIL PROTECTED]'bla.gif']", "alt") returns "toto"
+ * Get attribut value of the given element. For example, if you have img
src="bla.gif" alt="toto",
+ * getElementAttributByXPath("//[EMAIL PROTECTED]'bla.gif']", "alt")
returns "toto"
*
* @param xpath xpath of the element.
* @param attribut name of the attribut.
Modified:
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
---
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
2006-11-24 14:11:31 UTC (rev 626)
+++
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
2006-11-27 11:13:19 UTC (rev 627)
@@ -1570,13 +1570,13 @@
}
/**
- * Assert that a frame with the given name is present.
+ * Assert that a frame with the given name or ID is present.
*
- * @param frameName
+ * @param frameNameOrId Name or ID of the frame. ID is checked first.
*/
- public void assertFramePresent(String frameName) {
- Assert.assertTrue("Unable to locate frame [" + frameName + "].",
- getDialog().hasFrame(frameName));
+ public void assertFramePresent(String frameNameOrId) {
+ Assert.assertTrue("Unable to locate frame with name or ID [" +
frameNameOrId + "].",
+ getDialog().hasFrame(frameNameOrId));
}
/**
@@ -1988,12 +1988,12 @@
}
/**
- * Make the named frame active (current response will be frame's contents).
+ * Make the given frame active.
*
- * @param frameName
+ * @param frameNameOrId Name or ID of the frame. ID is checked first.
*/
- public void gotoFrame(String frameName) {
- getDialog().gotoFrame(frameName);
+ public void gotoFrame(String frameNameOrId) {
+ getDialog().gotoFrame(frameNameOrId);
}
/**
Modified:
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
===================================================================
---
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
2006-11-24 14:11:31 UTC (rev 626)
+++
branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java
2006-11-27 11:13:19 UTC (rev 627)
@@ -64,6 +64,7 @@
import com.gargoylesoftware.htmlunit.WebWindowEvent;
import com.gargoylesoftware.htmlunit.WebWindowListener;
import com.gargoylesoftware.htmlunit.WebWindowNotFoundException;
+import com.gargoylesoftware.htmlunit.html.FrameWindow;
import com.gargoylesoftware.htmlunit.html.HtmlFileInput;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
@@ -294,15 +295,18 @@
}
- public boolean hasFrame(String frameName) {
- return getFrame(frameName) != null;
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean hasFrame(String frameNameOrId) {
+ return getFrame(frameNameOrId) != null;
}
/**
* [EMAIL PROTECTED]
*/
- public void gotoFrame(String frameName) {
- win = getFrame(frameName);
+ public void gotoFrame(String frameNameOrId) {
+ win = getFrame(frameNameOrId);
}
/**
@@ -1801,12 +1805,29 @@
}
/**
- * Return the response for the given frame in the current conversation.
+ * Return the given frame in the current conversation.
*
- * @param frameName
+ * @param frameNameOrId Frame name or ID.
+ * @return The frame found or null.
*/
- private WebWindow getFrame(String frameName) {
- return ((HtmlPage) win.getEnclosedPage()).getFrameByName(frameName);
+ private WebWindow getFrame(String frameNameOrId) {
+ final List frames = getCurrentPage().getFrames();
+ //First try ID
+ for (final Iterator iter = frames.iterator(); iter.hasNext();) {
+ final FrameWindow frame = (FrameWindow) iter.next();
+ if (frameNameOrId.equals(frame.getFrameElement().getId())) {
+ return frame;
+ }
+ }
+ //Now try with Name
+ for (final Iterator iter = frames.iterator(); iter.hasNext();) {
+ final FrameWindow frame = (FrameWindow) iter.next();
+ if (frameNameOrId.equals(frame.getName())) {
+ return frame;
+ }
+ }
+ //Nothing was found.
+ return null;
}
/**
Modified: branches/1.x/src/changes/changes.xml
===================================================================
--- branches/1.x/src/changes/changes.xml 2006-11-24 14:11:31 UTC (rev
626)
+++ branches/1.x/src/changes/changes.xml 2006-11-27 11:13:19 UTC (rev
627)
@@ -9,6 +9,9 @@
<body>
<release version="1.4-RC2" date="UNKNOW">
<action type="add" dev="Julien Henry">
+ Add the possibility to manipulate frame (and iframe) by ID in
addition to their name.
+ </action>
+ <action type="add" dev="Julien Henry">
Add saveAs(File f) and assertDownloadedFileEquals(File
expected) methods
to check downloaded response as a binary File.
</action>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development