01: // Copyright © 2002-2007 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps.verify;
03:
04: import com.canoo.webtest.engine.StepFailedException;
05:
06: /**
07: * Verifies the title of an HTML document.
08: * @author Marc Guillemot
09: * @author Paul King
10: * @webtest.step
11: * category="Core"
12: * name="verifyTitle"
13: * alias="verifytitle"
14: * description="This step verifies whether the text enclosed by the <key>HTML</key> title tag (<TITLE> ... </TITLE>) matches some specified text. The specified text can represent a <key>regex</key>."
15: */
16: public class VerifyTitle extends AbstractVerifyTextStep {
17: /**
18: * Does the verification work.
19: * @see com.canoo.webtest.steps.Step#doExecute()
20: */
21: public void doExecute() throws Exception {
22: final String strTitle = getContext().getCurrentHtmlResponse(
23: this ).getTitleText();
24:
25: if (!verifyText(strTitle)) {
26: throw new StepFailedException(
27: "Wrong document title found!", getText(), strTitle,
28: this );
29: }
30: }
31:
32: /**
33: * Called by Ant to set the text nested between opening and closing tags.
34: * @param text the text to set
35: * @webtest.nested.parameter
36: * required="no"
37: * description="Alternative way to set the 'text' attribute."
38: */
39: public void addText(final String text) {
40: if (getText() == null)
41: setText(getProject().replaceProperties(text));
42: }
43: }
|