Revision: 892 http://jwebunit.svn.sourceforge.net/jwebunit/?rev=892&view=rev Author: henryju Date: 2011-01-27 13:03:38 +0000 (Thu, 27 Jan 2011)
Log Message: ----------- [3166502] Added indexed alternatives of methods clickLinkWithImage, assertLinkPresentWithImage and assertLinkNotPresentWithImage to test and expose a bug in HtmlUnit testing engine. Modified Paths: -------------- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java trunk/src/changes/changes.xml Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java =================================================================== --- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java 2011-01-27 12:37:47 UTC (rev 891) +++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java 2011-01-27 13:03:38 UTC (rev 892) @@ -34,6 +34,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; + +import org.junit.Before; + import net.sourceforge.jwebunit.exception.TestingEngineResponseException; import org.junit.Test; @@ -47,20 +50,24 @@ */ public class NavigationTest extends JWebUnitAPITestCase { + @Before public void setUp() throws Exception { super.setUp(); setBaseUrl(HOST_PATH + "/NavigationTest"); } - @Test public void testBeginAtRelative() { + @Test + public void testBeginAtRelative() { beginAt("/blah.html"); } - @Test public void testBeginAtAbsolute() { + @Test + public void testBeginAtAbsolute() { beginAt(HOST_PATH + "/NavigationTest/blah.html"); } - @Test public void testForwardSlashConfusion() throws Exception { + @Test + public void testForwardSlashConfusion() throws Exception { beginAt("/blah.html"); beginAt("blah.html"); getTestContext().setBaseUrl(HOST_PATH + "/NavigationTest/"); @@ -68,14 +75,16 @@ beginAt("blah.html"); } - @Test public void testInvalidBeginAt() { + @Test + public void testInvalidBeginAt() { //the testing engines should throw an exception if a 404 Error is found. assertException(TestingEngineResponseException.class, "beginAt", new Object[] {"/nosuchresource.html"}); } - @Test public void testClickLinkWithText() { + @Test + public void testClickLinkWithText() { beginAt("/pageWithLink.html"); assertTitleEquals("pageWithLink"); @@ -106,7 +115,8 @@ assertTitleEquals("pageWithLink"); } - @Test public void testClickLinkWithImage() { + @Test + public void testClickLinkWithImage() { beginAt("/pageWithLink.html"); assertTitleEquals("pageWithLink"); @@ -114,7 +124,26 @@ assertTitleEquals("targetPage2"); } - @Test public void testClickLinkByID() { + @Test + public void testClickLinkWithImageAnd0Index() { + beginAt("/pageWithLink.html"); + assertTitleEquals("pageWithLink"); + + clickLinkWithImage("graphic.jpg", 0); + assertTitleEquals("targetPage2"); + } + + @Test + public void testClickLinkWithImageAnd1Index() { + beginAt("/pageWithLink.html"); + assertTitleEquals("pageWithLink"); + + clickLinkWithImage("graphic.jpg", 1); + assertTitleEquals("targetPage"); + } + + @Test + public void testClickLinkByID() { beginAt("/pageWithLink.html"); assertTitleEquals("pageWithLink"); @@ -122,7 +151,8 @@ assertTitleEquals("targetPage"); } - @Test public void testInvalidClickLink() { + @Test + public void testInvalidClickLink() { beginAt("/pageWithLink.html"); assertTitleEquals("pageWithLink"); @@ -134,14 +164,16 @@ fail("Expected exception"); } - @Test public void testGotoPageRelative() { + @Test + public void testGotoPageRelative() { beginAt("/targetPage.html"); assertTitleEquals("targetPage"); gotoPage("/targetPage2.html"); assertTitleEquals("targetPage2"); } - @Test public void testGotoPageAbsolute() { + @Test + public void testGotoPageAbsolute() { beginAt("/targetPage.html"); assertTitleEquals("targetPage"); gotoPage(HOST_PATH + "/NavigationTest/targetPage2.html"); @@ -149,7 +181,8 @@ } //For bug 726143 - @Test public void testLinkWithEscapedText() { + @Test + public void testLinkWithEscapedText() { beginAt("/pageWithAmpersandInLink.html"); assertLinkPresentWithText("Map & Directions"); clickLinkWithText("Map & Directions"); @@ -159,7 +192,8 @@ /** * Testing for issue 996031 */ - @Test public void testLinkExactText() { + @Test + public void testLinkExactText() { beginAt("/test1.html"); assertTitleEquals("test1"); assertLinkPresentWithExactText("one"); Modified: trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html =================================================================== --- trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html 2011-01-27 12:37:47 UTC (rev 891) +++ trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html 2011-01-27 13:03:38 UTC (rev 892) @@ -29,5 +29,8 @@ <img src="graphic.jpg"/> </a> <a href="/jwebunit/NavigationTest/targetPage2.html">an active <i>link</i></a> + <a href="/jwebunit/NavigationTest/targetPage.html"> + <img src="graphic.jpg"/> + </a> </body> </html> \ No newline at end of file Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java =================================================================== --- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2011-01-27 12:37:47 UTC (rev 891) +++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2011-01-27 13:03:38 UTC (rev 892) @@ -2035,18 +2035,44 @@ } /** + * Assert that a link containing a specified image is present. + * + * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, + * you could just pass in <tt>"my_icon.png"</tt>. + * @param index The 0-based index, when more than one link with the same image is expected. + */ + public void assertLinkPresentWithImage(String imageFileName, int index) { + assertTrue("Link with image file [" + imageFileName + + "] and index " + index + " not found in response.", getTestingEngine() + .hasLinkWithImage(imageFileName, index)); + } + + /** * Assert that a link containing a specified image is not present. * * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, * you could just pass in <tt>"my_icon.png"</tt>. */ public void assertLinkNotPresentWithImage(String imageFileName) { - assertTrue("Link with image file [" + imageFileName - + "] found in response.", !getTestingEngine().hasLinkWithImage( + assertFalse("Link with image file [" + imageFileName + + "] found in response.", getTestingEngine().hasLinkWithImage( imageFileName, 0)); } /** + * Assert that a link containing a specified image is not present. + * + * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, + * you could just pass in <tt>"my_icon.png"</tt>. + * @param index The 0-based index, when more than one link with the same image is expected. + */ + public void assertLinkNotPresentWithImage(String imageFileName, int index) { + assertFalse("Link with image file [" + imageFileName + + "] and index " + index + " found in response.", + getTestingEngine().hasLinkWithImage(imageFileName, index)); + } + + /** * Assert that an element with a given id is present. * * @param anID element id to test for. @@ -2601,6 +2627,18 @@ } /** + * Navigate by selection of a link with a given image. + * + * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, + * you could just pass in <tt>"my_icon.png"</tt>. + * @param index The 0-based index, when more than one link with the same image is expected. + */ + public void clickLinkWithImage(String imageFileName, int index) { + assertLinkPresentWithImage(imageFileName, index); + getTestingEngine().clickLinkWithImage(imageFileName, index); + } + + /** * Navigate by selection of a link with given id. * * @param linkId id of link Modified: trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java =================================================================== --- trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 12:37:47 UTC (rev 891) +++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 13:03:38 UTC (rev 892) @@ -1822,7 +1822,7 @@ private HtmlAnchor getLinkWithImage(String filename, int index) { return (HtmlAnchor) getHtmlElementByXPath("(//a[img[contains(@src,\"" - + filename + "\")]])[" + index + 1 + "]"); + + filename + "\")]])[" + (index + 1) + "]"); } private HtmlAnchor getLinkWithText(String linkText, int index) { Modified: trunk/src/changes/changes.xml =================================================================== --- trunk/src/changes/changes.xml 2011-01-27 12:37:47 UTC (rev 891) +++ trunk/src/changes/changes.xml 2011-01-27 13:03:38 UTC (rev 892) @@ -32,6 +32,9 @@ </properties> <body> <release version="3.0" date="UNKNOW" description="Updated all internals to JUnit 4"> + <action type="add" dev="henryju" issue="3166502" due-to="Harri"> + Added indexed alternatives of methods clickLinkWithImage, assertLinkPresentWithImage and assertLinkNotPresentWithImage. + </action> <action type="fix" dev="henryju" issue="3116839" due-to="Tony Qian"> assertTitleNotSame works incorrectly. Deprecated and replaced by a working assertTitleNotEquals. </action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ JWebUnit-development mailing list JWebUnit-development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jwebunit-development