01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps.verify;
03:
04: import com.canoo.webtest.engine.StepExecutionException;
05: import com.canoo.webtest.engine.StepFailedException;
06: import com.canoo.webtest.self.TestBlock;
07: import com.canoo.webtest.self.ThrowAssert;
08: import com.canoo.webtest.steps.BaseStepTestCase;
09: import com.canoo.webtest.steps.Step;
10:
11: public class VerifyElementTextTest extends BaseStepTestCase {
12: private static final String HTML_DOC_HEADER = "<html><head><title>foo</title></head><body>";
13: private static final String HTML_DOC_FOOTER = "</body></html>";
14: private static final String HTML_DOCUMENT = HTML_DOC_HEADER
15: + " page text <b>1</b>"
16: + "<form name='radioform' action='/dummy'>"
17: + " <textarea name='Hugo' cols='80' rows='20'>The very large text area named hugo.</textarea>"
18: + " <textarea name='notext' cols='5' rows='10'></textarea>"
19: + " <textarea id='someId' cols='5' rows='10'>The text area with id someId.</textarea>"
20: + "</form>" + "Page text 2" + HTML_DOC_FOOTER;
21:
22: private VerifyElementText fStep;
23:
24: protected static final String ERR_FINGERPRINT = "Wrong contents found in HTML element";
25:
26: protected void setUp() throws Exception {
27: super .setUp();
28: fStep = (VerifyElementText) getStep();
29: getContext().setDefaultResponse(HTML_DOCUMENT);
30: }
31:
32: protected void tearDown() throws Exception {
33: super .tearDown();
34: }
35:
36: protected Step createStep() {
37: return new VerifyElementText();
38: }
39:
40: public void testInsufficientParameters() throws Exception {
41: String expectedErrorMessage = "One of 'htmlId' or 'type' must be set.";
42: String message = ThrowAssert.assertThrows(
43: StepExecutionException.class, new TestBlock() {
44: public void call() throws Exception {
45: fStep.setText("some text");
46: executeStep(fStep);
47: }
48: });
49: assertTrue("expected start <" + expectedErrorMessage
50: + "> but was <" + message + ">", message
51: .startsWith(expectedErrorMessage));
52: }
53:
54: public void testTextAreaWithText() throws Exception {
55: // <verifyElementText type="textarea" name="Hugo" text="The very large text area named hugo."/>
56: fStep.setType("textarea");
57: fStep.setName("Hugo");
58: fStep.setText("The very large text area named hugo.");
59: executeStep(fStep);
60: }
61:
62: public void testTextAreaWithId() throws Exception {
63: // <verifyElementText htmlId="someId" text="The text area with id someId."/>
64: fStep.setHtmlId("someId");
65: fStep.setText("The text area with id someId.");
66: executeStep(fStep);
67: }
68:
69: public void testNegativeTextAreaWithText() throws Exception {
70: // <verifyElementText type="textarea" name="Hugo" text="Deep Blue"/>
71: fStep.setType("textarea");
72: fStep.setName("Hugo");
73: fStep.setText("Deep Blue");
74: final String msg = ThrowAssert.assertThrows(
75: StepFailedException.class, new TestBlock() {
76: public void call() throws Exception {
77: executeStep(fStep);
78: }
79: });
80: assertTrue(msg.indexOf(ERR_FINGERPRINT) != -1);
81: }
82:
83: public void testTextAreaWithoutText() throws Exception {
84: // <verifyElementText type="textarea" name="notext" text=""/>
85: fStep.setType("textarea");
86: fStep.setName("notext");
87: fStep.setText("");
88: executeStep(fStep);
89: }
90:
91: public void testElementWithSubelements() throws Exception {
92: fStep.setType("body");
93: fStep.setText("The very large text area named hugo");
94: fStep.setRegex("true");
95: executeStep(fStep);
96: }
97: }
|