1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.jameleon.plugin.jiffie.tags;
21
22 import net.sf.jameleon.plugin.jiffie.IEFunctionTag;
23
24 import java.util.Iterator;
25 import java.util.List;
26
27 /***
28 * Validates the title, text and links on the page.
29 *
30 * If no checks occur, then this tag will fail.
31 *
32 * Some example uses might be:
33 *
34 * To validate the title is 'Jameleon':
35 *
36 * <pre><source>
37 * <ie-validate functionId="Verify the title is 'Jameleon'"
38 * title="Jameleon"/>
39 * </source></pre>
40 *
41 * To validate the title is <b>not</b> 'Jameleon':
42 *
43 * <pre><source>
44 * <ie-validate functionId="Verify the title is NOT 'Jameleon'"
45 * titleNoEquals="Jameleon"/>
46 * </source></pre>
47 *
48 * To check that 'automated testing tool' is on the page:
49 *
50 * <pre><source>
51 * <ie-validate functionId="check that 'automated testing tool' is on the page"
52 * textPresent="automated testing tool"/>
53 * </source></pre>
54 *
55 * To check that a link with the given text 'some link' is on the page:
56 *
57 * <pre><source>
58 * <ie-validate functionId="Validate that 'some link' is on the current page."
59 * linkPresent="some link"/>
60 * </source></pre>
61 *
62 * Most of the attributes can support multiple values.
63 *
64 * For example, to check that 'automated testing tool' and 'book' are on the page:
65 *
66 * <pre><source>
67 * <map-variable toVariable="textPresent" variableType="list">
68 * <variable-value>automated testing tool</variable-value>
69 * <variable-value>book</variable-value>
70 * </map-variable>
71 * <ie-validate functionId="check that 'automated testing tool' is on the page"
72 * textPresent="${textPresent}"/>
73 * </source></pre>
74 *
75 * @jameleon.function name="ie-validate" type="validation"
76 * @jameleon.step Validate that the title is what is expected, if provided
77 * @jameleon.step Check that the given text, if provided, appears on the page.
78 */
79 public class IEValidationTag extends IEFunctionTag {
80
81 /***
82 * Expected title
83 *
84 * @jameleon.attribute required="false" contextName="ieValidationTitle"
85 */
86 protected String title;
87
88 /***
89 * Title that is NOT expected. If multiple titles are passed, then ALL titles are compared.
90 *
91 * @jameleon.attribute required="false" contextName="ieValidationTitleNotEquals"
92 */
93 protected List titleNotEquals;
94
95 /***
96 * Text that should exist on the resulting page
97 *
98 * @jameleon.attribute required="false" contextName="ieValidationTextPresent"
99 */
100 protected List textPresent;
101
102 /***
103 * Text that should NOT exist on the resulting page
104 *
105 * @jameleon.attribute required="false" contextName="ieValidationTextNotPresent"
106 */
107 protected List textNotPresent;
108
109 /***
110 * Link that should exist on the resulting page
111 *
112 * @jameleon.attribute required="false" contextName="ieValidationLinkPresent"
113 */
114 protected List linkPresent;
115
116 public void testBlock() {
117
118 boolean assertOccurred = false;
119
120 if (title != null && title.trim().length() > 0) {
121 assertOccurred = true;
122 assertTitleEquals(title);
123 }
124 Iterator it = null;
125 if (titleNotEquals != null && titleNotEquals.size() > 0) {
126 assertOccurred = true;
127 it = titleNotEquals.iterator();
128 String titleS;
129 while (it.hasNext()) {
130 titleS = (String)it.next();
131 assertTitleNotEquals(titleS);
132 }
133 }
134 if (textPresent != null && textPresent.size() > 0) {
135 assertOccurred = true;
136 it = textPresent.iterator();
137 String text = null;
138 while (it.hasNext()) {
139 text = (String) it.next();
140 assertTextPresent(text);
141 }
142 }
143 if (textNotPresent != null && textNotPresent.size() > 0) {
144 assertOccurred = true;
145 it = textNotPresent.iterator();
146 String text = null;
147 while (it.hasNext()) {
148 text = (String) it.next();
149 assertTextNotPresent(text);
150 }
151 }
152 if (linkPresent != null && linkPresent.size() > 0) {
153 assertOccurred = true;
154 it = linkPresent.iterator();
155 String link = null;
156 while (it.hasNext()) {
157 link = (String) it.next();
158 assertLinkPresent(link);
159 }
160 }
161
162 if (!assertOccurred) {
163 fail("No test occurred on ie-validate tag. You must define a title or textPresent");
164 }
165 }
166 }
167