1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.plugin.htmlunit.tags;
20
21 import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
22
23 import net.sf.jameleon.plugin.htmlunit.HtmlUnitFunctionTag;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /***
29 * A tag that starts recording alert messages and stores them in the context.
30 *
31 * If the alerts are already being recorded, then the existing alerts will be cleared
32 * and the recording will start over again.
33 * <br/>
34 * To start recording alert boxes:
35 * <pre><source>
36 * <htmlunit-record-alerts
37 * functionId="Start recording alerts"
38 * alertsContextName="alerts"/>
39 * ...
40 * <ju-assert-equals
41 * functionId="verify the # of alerts"
42 * expected="3"
43 * actual="${alerts.size()}"
44 * />
45 * <ju-assert-equals
46 * functionId="verify the 1st alert message"
47 * expected="First Name is required"
48 * actual="${alerts.get(0)}"
49 * />
50 *
51 * </source></pre>
52 * @jameleon.function name="htmlunit-record-alerts"
53 */
54 public class HtmlUnitRecordAlertsTag extends HtmlUnitFunctionTag{
55
56 /***
57 * The name of the context variable to store the list of collections in.
58 * @jameleon.attribute required="true"
59 */
60 protected String alertsContextName;
61
62 public void testBlock(){
63 List alerts = new ArrayList();
64 helper.getDelegate().getWebClient().setAlertHandler(new CollectingAlertHandler(alerts));
65 setVariable(alertsContextName, alerts);
66 }
67
68 }