01: // Copyright © 2002-2007 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps.verify;
03:
04: import com.canoo.webtest.interfaces.ITableLocator;
05: import com.canoo.webtest.self.AntTest;
06: import com.canoo.webtest.steps.BaseStepTestCase;
07: import com.canoo.webtest.steps.Step;
08:
09: /**
10: * Tests for {@link VerifyText}.
11: * @author Dierk Koenig, Carsten Seibert
12: * @author Denis N. Antonioli
13: * @author Marc Guillemot
14: * @author Paul King
15: */
16:
17: public class VerifyTextTest extends BaseStepTestCase {
18: private VerifyText fStep;
19:
20: protected void setUp() throws Exception {
21: super .setUp();
22: fStep = (VerifyText) getStep();
23: }
24:
25: protected Step createStep() {
26: return new VerifyText();
27: }
28:
29: public void testTableNesting() {
30: AntTest.nested(VerifyText.class, "Table");
31: }
32:
33: public void testLocatorUsage() throws Exception {
34: final ITableLocator tableLocator = (ITableLocator) mock(
35: ITableLocator.class, "tableLocator");
36:
37: tableLocator.locateText(getContext(), fStep);
38: modify().returnValue("");
39: startVerification();
40:
41: fStep.addTableInternal(tableLocator);
42: fStep.setText("");
43: executeStep(fStep);
44: }
45:
46: public void testLocatePlainText() throws Exception {
47: final String htmlContent = "<html><body>" + "<h1>header</h1>"
48: + "</body></html>";
49: getContext().saveResponseAsCurrent(getDummyPage(htmlContent));
50:
51: fStep.setText("header");
52: executeStep(fStep);
53: }
54:
55: public void testLocateI18nText() throws Exception {
56: final String htmlContent = "<html><head>" + "</head><body>"
57: + "<h1>你</h1>" + "</body></html>";
58: getContext().saveResponseAsCurrent(getDummyPage(htmlContent));
59:
60: fStep.setText("\u4f60");
61: assertFailOnExecute(fStep, "Numeric entity not found", "");
62: fStep.setText("你");
63: executeStep(fStep);
64: }
65:
66: public void testLocateI18nNamedEntitiesText() throws Exception {
67: final String htmlContent = "<html><head>" + "</head><body>"
68: + "<h1>ü</h1>" + "</body></html>";
69: getContext().saveResponseAsCurrent(getDummyPage(htmlContent));
70:
71: fStep.setText("\u00fc");
72: assertFailOnExecute(fStep, "Named entity not found", "");
73: fStep.setText("ü");
74: executeStep(fStep);
75: }
76:
77: public void testLocateTextAndElement() throws Exception {
78: final String htmlContent = "<html><body>" + "<h1>header</h1>"
79: + "</body></html>";
80: getContext().saveResponseAsCurrent(getDummyPage(htmlContent));
81:
82: fStep.setText("<h1>header</h1>");
83: executeStep(fStep);
84: }
85:
86: public void testNestedText() throws Exception {
87: testNestedTextEquivalent(fStep, "text");
88: }
89: }
|