1 38 package com.gargoylesoftware.htmlunit.jelly; 39 40 import org.apache.commons.jelly.JellyTagException; 41 import org.apache.commons.jelly.XMLOutput; 42 43 49 public class AssertTitleTag extends HtmlUnitTagSupport { 50 private String expectedText_; 51 private String startsWithText_; 52 53 58 public void doTag(final XMLOutput xmlOutput) throws JellyTagException { 59 invokeBody(xmlOutput); 60 if( expectedText_ == null && startsWithText_ == null ) { 61 throw new JellyTagException("One of 'text' or 'startsWith' must be specified"); 62 } 63 64 final String actualText = getHtmlPage().getTitleText(); 65 if( expectedText_ != null && actualText.equals(expectedText_) == false ) { 66 throw new JellyTagException("Expected text ["+expectedText_+"] but got ["+actualText+"] instead"); 67 } 68 69 if( startsWithText_ != null && actualText.startsWith(startsWithText_) == false ) { 70 throw new JellyTagException("Expected text to start with [" 71 +startsWithText_+"] but got ["+actualText+"] instead"); 72 } 73 } 74 75 76 80 public void setText( final String text ) { 81 expectedText_ = text; 82 } 83 84 85 89 public void setStartsWith( final String text ) { 90 startsWithText_ = text; 91 } 92 } 93 94 | Popular Tags |