01: package org.jzonic.webtester.commands;
02:
03: import org.jzonic.webtester.WebTestContext;
04: import org.xml.sax.SAXException;
05:
06: /**
07: * This command will check if the title of the page
08: * matches the required title.
09: *
10: * <br/>
11: * parameter: text
12: * <br/>
13: * example:
14: * <br/>
15: * check_title | Page Title
16: *
17: * @author Mecky
18: */
19: public class CheckTitleCommand implements WebTestNode {
20:
21: public static final String COMMAND_NAME = "check_title";
22: private String title;
23:
24: public WebTestNodeResult execute(WebTestContext context) {
25: title = context.replaceVar(title);
26: WebTestNodeResult result = new WebTestNodeResult(COMMAND_NAME,
27: title);
28: result.setSuccess(true);
29: try {
30: if (!context.getTitle().equals(title)) {
31: result.setSuccess(false);
32: result.setErrorMessage("check_title: The title:'"
33: + title + "' was expected but '"
34: + context.getTitle() + "' was found");
35: }
36: } catch (SAXException e) {
37: result.setSuccess(false);
38: result.setException(e);
39: }
40: return result;
41: }
42:
43: public void setParameter(String value) {
44: title = value;
45: }
46:
47: public String getName() {
48: return COMMAND_NAME;
49: }
50:
51: }
|