Revision: 799
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=799&view=rev
Author: henryju
Date: 2009-03-02 19:08:46 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
[2106019] Enable partial matches of image src and alt attributes. Thanks to
Kent R. Spillner.
Modified Paths:
--------------
trunk/jwebunit-core/pom.xml
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
trunk/src/changes/changes.xml
Added Paths:
-----------
trunk/jwebunit-core/src/test/java/net/sourceforge/jwebunit/junit/
trunk/jwebunit-core/src/test/java/net/sourceforge/jwebunit/junit/WebTesterTest.java
Modified: trunk/jwebunit-core/pom.xml
===================================================================
--- trunk/jwebunit-core/pom.xml 2009-03-02 18:46:13 UTC (rev 798)
+++ trunk/jwebunit-core/pom.xml 2009-03-02 19:08:46 UTC (rev 799)
@@ -17,6 +17,12 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>regexp</groupId>
<artifactId>regexp</artifactId>
</dependency>
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
2009-03-02 18:46:13 UTC (rev 798)
+++
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
2009-03-02 19:08:46 UTC (rev 799)
@@ -3324,6 +3324,11 @@
}
}
+ /**
+ * Assert there is at least one image in the page with given src and
(optional) alt attributes.
+ * @param imageSrc Value of image src attribute.
+ * @param imageAlt Value of image alt attribute. Ignored when null.
+ */
public void assertImagePresent(String imageSrc, String imageAlt) {
String xpath = "//i...@src=\"" + imageSrc + "\"";
if (imageAlt!= null) {
@@ -3334,6 +3339,20 @@
}
/**
+ * Assert there is at least one image in the page with given partial src
and (optional) partial alt attributes.
+ * @param partialImageSrc
+ * @param partialImageAlt
+ */
+ public void assertImagePresentPartial(String partialImageSrc, String
partialImageAlt) {
+ String xpath = "//img[contains(@src, \"" + partialImageSrc + "\")";
+ if (partialImageAlt!= null) {
+ xpath += " and contains(@alt, \"" + partialImageAlt + "\")";
+ }
+ xpath += "]";
+ assertElementPresentByXPath(xpath);
+ }
+
+ /**
* @see #assertImageValidAndStore(String, String, java.io.File)
*/
public void assertImageValid(String imageSrc, String imageAlt) {
Added:
trunk/jwebunit-core/src/test/java/net/sourceforge/jwebunit/junit/WebTesterTest.java
===================================================================
---
trunk/jwebunit-core/src/test/java/net/sourceforge/jwebunit/junit/WebTesterTest.java
(rev 0)
+++
trunk/jwebunit-core/src/test/java/net/sourceforge/jwebunit/junit/WebTesterTest.java
2009-03-02 19:08:46 UTC (rev 799)
@@ -0,0 +1,47 @@
+package net.sourceforge.jwebunit.junit;
+
+import junit.framework.TestCase;
+import net.sourceforge.jwebunit.api.ITestingEngine;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class WebTesterTest extends TestCase {
+ public void
testAssertImageSrcContainsShouldDelegateXPathExpressionToUnderlyingTestingEngine()
throws Exception {
+ String xpath = "//img[" + contains("src", "SOME URL") + "]";
+
+ ITestingEngine engine = engine(xpath, true);
+ WebTester tester = webTester(engine);
+
+ tester.assertImagePresentPartial("SOME URL", null);
+
+ verify(engine).hasElementByXPath(xpath);
+ }
+
+ public void
testAssertImageContainsShouldDelegateXPathExpressionToUnderlyingTestingEngine()
throws Exception {
+ String xpath = "//img[" + contains("src", "SOME URL") + " and " +
contains("alt", "SOME ALT TEXT") + "]";
+
+ ITestingEngine engine = engine(xpath, true);
+ WebTester tester = webTester(engine);
+
+ tester.assertImagePresentPartial("SOME URL", "SOME ALT TEXT");
+
+ verify(engine).hasElementByXPath(xpath);
+ }
+
+ private String contains(String attribute, String substring) {
+ return "contains(@" + attribute + ", \"" + substring + "\")";
+ }
+
+ private ITestingEngine engine(String xpath, boolean hasElement) {
+ ITestingEngine mock = mock(ITestingEngine.class);
+ when(mock.hasElementByXPath(xpath)).thenReturn(hasElement);
+ return mock;
+ }
+
+ private WebTester webTester(ITestingEngine engine) {
+ WebTester tester = new WebTester();
+ tester.setDialog(engine);
+ return tester;
+ }
+}
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2009-03-02 18:46:13 UTC (rev 798)
+++ trunk/src/changes/changes.xml 2009-03-02 19:08:46 UTC (rev 799)
@@ -8,6 +8,9 @@
</properties>
<body>
<release version="2.2" date="UNKNOW">
+ <action type="add" dev="henryju" issue="2106019" due-to="Kent R.
Spillner">
+ Enable partial matches of image src and alt attributes. Added
assertImagePresentPartial(String partialImageSrc, String partialImageAlt)
method.
+ </action>
<action type="add" dev="henryju" issue="2647451" due-to="Kent R.
Spillner">
Exposed option to toggle exceptions on Javascript errors.
</action>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development