Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

Commit fdd30de

Browse files
author
Jim Weaver
committed
Added click link by image support, updated changes file
1 parent 09002de commit fdd30de

6 files changed

Lines changed: 103 additions & 6 deletions

File tree

jWebUnit/CHANGES

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
CHANGES SINCE RC2:
2+
3+
** Additional Functionality**
4+
5+
Support for links with images contributed by Justin Sampson
6+
Methods were added to assert and navigate links with images by filename.
7+
8+
assertFormElementEmpty method added - a convenience.
9+
10+
11+
**API Changes**
12+
assertHasForm renamed to assertFormPresent to be consistent with other methods.
13+
14+
15+
**Miscellaneous**
16+
HttpUnit 1.4.6 incorporated.
17+
18+
119
CHANGES SINCE RC1:
220

321
**Additional Functionality**

jWebUnit/src/net/sourceforge/jwebunit/HttpUnitDialog.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,21 @@ public boolean isLinkPresentWithText(String linkText) {
444444
}
445445
}
446446

447+
/**
448+
* Return true if a link is present with a given image based on filename of image.
449+
*
450+
* @param imageFileName A suffix of the image's filename; for example, to match
451+
* <tt>"images/my_icon.png"<tt>, you could just pass in
452+
* <tt>"my_icon.png"<tt>.
453+
*/
454+
public boolean isLinkPresentWithImage(String imageFileName) {
455+
try {
456+
return (resp.getFirstMatchingLink(new LinkImagePredicate(), imageFileName) != null);
457+
} catch (SAXException e) {
458+
throw new RuntimeException(ExceptionUtility.stackTraceToString(e));
459+
}
460+
}
461+
447462
/**
448463
* Return true if a link is present in the current response with the
449464
* specified id.

jWebUnit/src/net/sourceforge/jwebunit/WebTestCase.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ public void assertSubmitButtonValue(String buttonName, String expectedValue) {
200200
tester.assertSubmitButtonValue(buttonName, expectedValue);
201201
}
202202

203+
public void assertLinkPresent(String linkId) {
204+
tester.assertLinkPresent(linkId);
205+
}
206+
207+
public void assertLinkNotPresent(String linkId) {
208+
tester.assertLinkNotPresent(linkId);
209+
}
210+
203211
public void assertLinkPresentWithText(String linkText) {
204212
tester.assertLinkPresentWithText(linkText);
205213
}
@@ -208,12 +216,12 @@ public void assertLinkNotPresentWithText(String linkText) {
208216
tester.assertLinkNotPresentWithText(linkText);
209217
}
210218

211-
public void assertLinkPresent(String linkId) {
212-
tester.assertLinkPresent(linkId);
219+
public void assertLinkPresentWithImage(String imageFileName) {
220+
tester.assertLinkPresentWithImage(imageFileName);
213221
}
214222

215-
public void assertLinkNotPresent(String linkId) {
216-
tester.assertLinkNotPresent(linkId);
223+
public void assertLinkNotPresentWithImage(String imageFileName) {
224+
tester.assertLinkNotPresentWithImage(imageFileName);
217225
}
218226

219227
public void assertElementPresent(String anID) {
@@ -265,6 +273,10 @@ protected void clickLinkWithText(String linkText) {
265273
tester.clickLinkWithText(linkText);
266274
}
267275

276+
protected void clickLinkWithImage(String imageFileName) {
277+
tester.clickLinkWithImage(imageFileName);
278+
}
279+
268280
protected void clickLink(String linkId) {
269281
tester.clickLink(linkId);
270282
}

jWebUnit/src/net/sourceforge/jwebunit/WebTester.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,28 @@ public void assertLinkNotPresentWithText(String linkText) {
574574
Assert.assertTrue("Link with text [" + linkText + "] found in response.", !dialog.isLinkPresentWithText(linkText));
575575
}
576576

577+
/**
578+
* Assert that a link containing a specified image is present.
579+
*
580+
* @param imageFileName A suffix of the image's filename; for example, to match
581+
* <tt>"images/my_icon.png"<tt>, you could just pass in
582+
* <tt>"my_icon.png"<tt>.
583+
*/
584+
public void assertLinkPresentWithImage(String imageFileName) {
585+
Assert.assertTrue("Link with image file [" + imageFileName + "] not found in response.", dialog.isLinkPresentWithImage(imageFileName));
586+
}
587+
588+
/**
589+
* Assert that a link containing a specified image is not present.
590+
*
591+
* @param imageFileName A suffix of the image's filename; for example, to match
592+
* <tt>"images/my_icon.png"<tt>, you could just pass in
593+
* <tt>"my_icon.png"<tt>.
594+
*/
595+
public void assertLinkNotPresentWithImage(String imageFileName) {
596+
Assert.assertTrue("Link with image file [" + imageFileName + "] found in response.", !dialog.isLinkPresentWithImage(imageFileName));
597+
}
598+
577599
/**
578600
* Assert that an element with a given id is present.
579601
*
@@ -689,6 +711,19 @@ public void clickLinkWithText(String linkText) {
689711
dialog.clickLinkWithText(linkText);
690712
}
691713

714+
/**
715+
* Navigate by selection of a link with a given image.
716+
*
717+
* @param imageFileName A suffix of the image's filename; for example, to match
718+
* <tt>"images/my_icon.png"<tt>, you could just pass in
719+
* <tt>"my_icon.png"<tt>.
720+
*/
721+
public void clickLinkWithImage(String imageFileName) {
722+
assertLinkPresentWithImage(imageFileName);
723+
dialog.clickLinkWithImage(imageFileName);
724+
}
725+
726+
692727
/**
693728
* Navigate by selection of a link with given id.
694729
*

jWebUnit/test/net/sourceforge/jwebunit/NavigationTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,29 @@ public void testInvalidBeginAt() {
4242
fail("Expected exception");
4343
}
4444

45-
public void testClickLink() {
45+
public void testClickLinkWithText() {
4646
gotoLinkTestPage();
4747
clickLinkWithText("an active link");
4848
assertTitleEquals("targetPage");
4949
}
5050

51+
public void testClickLinkWithImage() {
52+
gotoLinkTestPage();
53+
clickLinkWithImage("graphic.jpg");
54+
assertTitleEquals("targetPage2");
55+
}
56+
5157
public void testClickLinkByID() {
5258
gotoLinkTestPage();
5359
clickLink("activeID");
5460
assertTitleEquals("targetPage");
5561
}
5662

5763
private void gotoLinkTestPage() {
58-
defineWebPage("pageWithLink", "<a href=\"/targetPage.html\" id=\"activeID\">an <b>active</b> link</A>\n");
64+
defineWebPage("pageWithLink", "<a href=\"/targetPage.html\" id=\"activeID\">an <b>active</b> link</A>\n" +
65+
"<a href=\"/targetPage2.html\"><img src=\"graphic.jpg\"/></a>)\n");
5966
defineWebPage("targetPage", "");
67+
defineWebPage("targetPage2", "");
6068
beginAt("/pageWithLink.html");
6169
assertTitleEquals("pageWithLink");
6270
}

jWebUnit/test/net/sourceforge/jwebunit/WebAssertionsTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public void testAssertLinkNotPresent() throws Throwable {
4949
assertPassFail("assertLinkNotPresent", "no_link_id", "test_link_id");
5050
}
5151

52+
public void testAssertLinkPresentWithImage() throws Throwable {
53+
assertPassFail("assertLinkPresentWithImage", "graphic.jpg", "nosuchgraphic.jsp");
54+
}
55+
56+
public void testAssertLinkNotPresentWithImage() throws Throwable {
57+
assertPassFail("assertLinkNotPresentWithImage", "nosuchgraphic.jpg", "graphic.jpg");
58+
}
59+
5260
public void testAssertElementPresent() throws Throwable {
5361
assertElementPresent("row1");
5462
assertPassFail("assertElementPresent", "span_id", "no_id");
@@ -78,6 +86,7 @@ private void addTestPage() {
7886
"<tr><td>table text row 2</td></tr>" +
7987
"<tr><td>table text row 3</td><td>row 3 col 1</td>" +
8088
"<a id=\"test_link_id\" href=\"someurl.html\">test link</a>" +
89+
"<a id=\"test_graphic_link_id\" href=\"someurl2.html\"><img src=\"graphic.jpg\"/></a>" +
8190
"<form>" +
8291
"<input type=\"text\" name=\"testInputElement\" value=\"testValue\"/>" +
8392
"<input type=\"submit\" name=\"submitButton\" value=\"buttonLabel\"/>" +

0 commit comments

Comments
 (0)