|
From: Kent T. <ke...@cp...> - 2005-03-13 05:22:38
|
Hi,
Here is a test html file:
<html>
<body>
<script language="JavaScript"><!--
function foo() {
document.form1.onsubmit=bar;
}
function bar() {
alert('aaa');
return false;
}
window.onload=foo
// --></script>
<form name="form1">
<input type="Submit" name="OK" value="OK"/>
</form>
</body>
</html>
When I click OK, the browser will display an alert. But I don't know
why no alert (zero) is captured when htmlunit is used to simulate
the action:
public void testOnSubmit() throws Exception {
WebClient client = new WebClient();
CollectingAlertHandler handler = new CollectingAlertHandler();
client.setAlertHandler(handler);
URL url = new URL("http://localhost:8080/TDDCalc/Test.html");
HtmlPage page = (HtmlPage) client.getPage(url);
HtmlForm form = (HtmlForm) page.getAllForms().get(0);
HtmlSubmitInput ok = (HtmlSubmitInput) form.getInputByName("OK");
ok.click();
assertEquals(handler.getCollectedAlerts().size(), 1);
}
|