Revision: 766
          http://jwebunit.svn.sourceforge.net/jwebunit/?rev=766&view=rev
Author:   jevonwright
Date:     2008-11-18 02:55:26 +0000 (Tue, 18 Nov 2008)

Log Message:
-----------
issue 1277374: added assertCommentPresent(text) and 
assertCommentNotPresent(text) methods

Modified Paths:
--------------
    
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
    
trunk/jwebunit-commons-tests/src/main/resources/testcases/IElementTest/template.html
    
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
    
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/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
    trunk/src/changes/changes.xml

Modified: 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
 2008-11-18 02:22:58 UTC (rev 765)
+++ 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/IElementTest.java
 2008-11-18 02:55:26 UTC (rev 766)
@@ -185,4 +185,19 @@
 
     }
     
+    /**
+     * Tests searching for comments.
+     */
+    public void testComments() {
+       // whitespace is ignored
+       assertCommentPresent("a comment");
+       assertCommentPresent("another comment");
+       assertCommentPresent("  a comment");
+       assertCommentPresent("   another comment  ");
+       
+       // but case is not
+       assertCommentNotPresent("A Comment");
+       assertCommentNotPresent("definitely not here");
+    }
+    
 }

Modified: 
trunk/jwebunit-commons-tests/src/main/resources/testcases/IElementTest/template.html
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/resources/testcases/IElementTest/template.html
        2008-11-18 02:22:58 UTC (rev 765)
+++ 
trunk/jwebunit-commons-tests/src/main/resources/testcases/IElementTest/template.html
        2008-11-18 02:55:26 UTC (rev 766)
@@ -33,5 +33,10 @@
 <input id="js1" value="initial" 
onChange="document.getElementById('js2').value=this.value;" />
 <input id="js2" value="unchanged" />
 
+<!--a comment-->
+<!-- 
+  another comment    
+-->
+
 </body>
 </html>

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
===================================================================
--- 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
  2008-11-18 02:22:58 UTC (rev 765)
+++ 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
  2008-11-18 02:55:26 UTC (rev 766)
@@ -900,4 +900,9 @@
         */
        public void setIgnoreFailingStatusCodes(boolean ignore);
        
+    /**
+     * Get all the comments in a document, as a list of strings.
+     */
+    public List<String> getComments();    
+
 }

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 
    2008-11-18 02:22:58 UTC (rev 765)
+++ 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 
    2008-11-18 02:55:26 UTC (rev 766)
@@ -2012,6 +2012,31 @@
         Assert.assertFalse("Located element with xpath \"" + xpath + "\"",
                 getTestingEngine().hasElementByXPath(xpath));
     }
+    
+    /**
+     * Get all the comments in a document, as a list of strings.
+     */
+    public List<String> getComments() {
+       return getTestingEngine().getComments();
+    }
+    
+    /**
+     * Assert that a comment is present.
+     * 
+     * @param comment
+     */
+    public void assertCommentPresent(String comment) {
+       Assert.assertTrue("Comment present: '" + comment + "'", 
getComments().contains(comment.trim()));
+    }
+    
+    /**
+     * Assert that a comment is not present.
+     * 
+     * @param comment
+     */
+    public void assertCommentNotPresent(String comment) {
+       Assert.assertFalse("Comment not present: '" + comment + "'", 
getComments().contains(comment.trim()));
+    }
 
     /**
      * Assert that a given element contains specific text.

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
       2008-11-18 02:22:58 UTC (rev 765)
+++ 
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
       2008-11-18 02:55:26 UTC (rev 766)
@@ -42,6 +42,8 @@
 import org.apache.regexp.RESyntaxException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import com.gargoylesoftware.htmlunit.AlertHandler;
 import com.gargoylesoftware.htmlunit.BrowserVersion;
@@ -62,6 +64,7 @@
 import com.gargoylesoftware.htmlunit.WebWindowListener;
 import com.gargoylesoftware.htmlunit.WebWindowNotFoundException;
 import com.gargoylesoftware.htmlunit.html.ClickableElement;
+import com.gargoylesoftware.htmlunit.html.DomComment;
 import com.gargoylesoftware.htmlunit.html.DomNode;
 import com.gargoylesoftware.htmlunit.html.FrameWindow;
 import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
@@ -890,6 +893,34 @@
     }
 
     /**
+     * Get all the comments in a document, as a list of strings.
+     */
+    public List<String> getComments() {
+       List<String> comments = new ArrayList<String>();
+       getComments(comments, ((HtmlPage) win.getEnclosedPage()));
+       
+       return comments;
+    }
+
+    /**
+     * Recursively find comments for all child nodes.
+     * 
+     * @param comments
+     * @param node
+     */
+    private void getComments(List<String> comments, Node node) {
+       NodeList nodes = node.getChildNodes();
+       for (int i = 0; i < nodes.getLength(); i++) {
+               Node n = nodes.item(i);
+               if (n instanceof DomComment) {
+                       comments.add(((DomComment) n).getData().trim());
+               }
+               // add all child nodes
+               getComments(comments, n);
+       }
+    }
+    
+    /**
      * Return the first open window with the given title.
      */
     private WebWindow getWindowByTitle(String title) {

Modified: 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
===================================================================
--- 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
       2008-11-18 02:22:58 UTC (rev 765)
+++ 
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
       2008-11-18 02:55:26 UTC (rev 766)
@@ -720,4 +720,9 @@
                throw new 
UnsupportedOperationException("setIgnoreFailingStatusCodes");
        }
 
+       public boolean hasDomComment(String comment) {
+               // TODO implement method
+               throw new UnsupportedOperationException("hasDomComment");
+       }
+
 }

Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml       2008-11-18 02:22:58 UTC (rev 765)
+++ trunk/src/changes/changes.xml       2008-11-18 02:55:26 UTC (rev 766)
@@ -30,9 +30,12 @@
                <action type="fix" dev="jevonwright" issue="2306967" 
due-to="r_monson">
                        Fixed proxy authentication bug in HtmlUnit 
implementation.
                </action>
-               <action type="fix" dev="jevonwright" issue="1637716">
+               <action type="add" dev="jevonwright" issue="1637716">
                        Added assertMatch(regexp, text) and 
assertNotMatch(regexp, text) methods.
                </action>
+               <action type="add" dev="jevonwright" issue="1277374">
+                       Added assertCommentPresent(text) and 
assertCommentNotPresent(text) methods.
+               </action>
        </release>
         <release version="2.0" date="October 27, 2008">
             <action type="update" dev="henryju">


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to