View Javadoc

1   /*
2       Jameleon HtmlUnit plug-in - A plug-in that uses HtmlUnit to drive web sites
3       Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111AssertLevel.NO_FUNCTION07 USA
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   *     &lt;htmlunit-record-alerts
37   *            functionId="Start recording alerts"
38   *            alertsContextName="alerts"/&gt;
39   *     ...
40   *     &lt;ju-assert-equals
41   *            functionId="verify the # of alerts"
42   *            expected="3"
43   *            actual="${alerts.size()}"
44   *            /&gt;
45   *     &lt;ju-assert-equals
46   *            functionId="verify the 1st alert message"
47   *            expected="First Name is required"
48   *            actual="${alerts.get(0)}"
49   *            /&gt;
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  }