Revision: 236
http://jsptest.svn.sourceforge.net/jsptest/?rev=236&view=rev
Author: lkoskela
Date: 2008-06-27 04:47:44 -0700 (Fri, 27 Jun 2008)
Log Message:
-----------
'page().shouldContain(String)' and 'page().shouldNotContain(String)' no longer consider the 'head' section of an HTML document
Modified Paths:
--------------
trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/assertion/PageAssertion.java
Modified: trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/assertion/PageAssertion.java
===================================================================
--- trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/assertion/PageAssertion.java 2008-06-27 11:46:09 UTC (rev 235)
+++ trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/assertion/PageAssertion.java 2008-06-27 11:47:44 UTC (rev 236)
@@ -5,6 +5,7 @@
import org.jaxen.JaxenException;
import org.jaxen.dom.DOMXPath;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* Provides assertion methods related to an HTML page.
@@ -13,34 +14,43 @@
*/
public class PageAssertion extends DOMAssertion {
- /**
- * @param content
- * The DOM tree to interpret as an HTML page.
- */
- public PageAssertion(Document content) {
- this.context = content.getDocumentElement();
- }
+ private Element headContext;
- /**
- * Assert that the page should have the specified title.
- *
- * @param expectedTitle
- * The expected title.
- */
- public void shouldHaveTitle(String expectedTitle) {
- try {
- String title = new DOMXPath("/HTML/HEAD/TITLE/text()")
- .stringValueOf(context);
- Assert.assertEquals(expectedTitle, title);
- } catch (JaxenException e) {
- throw new RuntimeException(e);
- }
- }
+ /**
+ * @param content
+ * The DOM tree to interpret as an HTML page.
+ */
+ public PageAssertion(Document content) {
+ try {
+ context = (Element) new DOMXPath("/HTML/BODY")
+ .selectSingleNode(content);
+ headContext = (Element) new DOMXPath("/HTML/HEAD")
+ .selectSingleNode(content);
+ } catch (JaxenException e) {
+ throw new RuntimeException(e);
+ }
+ }
- /**
- * Returns a handle for making assertions related to link elements.
- */
- public LinkAssertion shouldHaveLink() {
- return new LinkAssertion(context);
- }
+ /**
+ * Assert that the page should have the specified title.
+ *
+ * @param expectedTitle
+ * The expected title.
+ */
+ public void shouldHaveTitle(String expectedTitle) {
+ try {
+ String title = new DOMXPath("TITLE/text()")
+ .stringValueOf(headContext);
+ Assert.assertEquals(expectedTitle, title);
+ } catch (JaxenException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Returns a handle for making assertions related to link elements.
+ */
+ public LinkAssertion shouldHaveLink() {
+ return new LinkAssertion(context);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|