HtmlUnitRecordAlertsTag.java from Jameleon at Krugle
Show HtmlUnitRecordAlertsTag.java syntax highlighted
/*
Jameleon HtmlUnit plug-in - A plug-in that uses HtmlUnit to drive web sites
Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111AssertLevel.NO_FUNCTION07 USA
*/
package net.sf.jameleon.plugin.htmlunit.tags;
import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
import net.sf.jameleon.plugin.htmlunit.HtmlUnitFunctionTag;
import java.util.ArrayList;
import java.util.List;
/**
* A tag that starts recording alert messages and stores them in the context.
*
* If the alerts are already being recorded, then the existing alerts will be cleared
* and the recording will start over again.
* <br/>
* To start recording alert boxes:
* <pre><source>
* <htmlunit-record-alerts
* functionId="Start recording alerts"
* alertsContextName="alerts"/>
* ...
* <ju-assert-equals
* functionId="verify the # of alerts"
* expected="3"
* actual="${alerts.size()}"
* />
* <ju-assert-equals
* functionId="verify the 1st alert message"
* expected="First Name is required"
* actual="${alerts.get(0)}"
* />
*
* </source></pre>
* @jameleon.function name="htmlunit-record-alerts"
*/
public class HtmlUnitRecordAlertsTag extends HtmlUnitFunctionTag{
/**
* The name of the context variable to store the list of collections in.
* @jameleon.attribute required="true"
*/
protected String alertsContextName;
public void testBlock(){
List alerts = new ArrayList();
helper.getDelegate().getWebClient().setAlertHandler(new CollectingAlertHandler(alerts));
setVariable(alertsContextName, alerts);
}
}
See more files for this project here