Invocation of dynamically added JavaScript event handlers
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <B70880B308FD6D4C921FFFA8AA88846B2B7EED@S01B1F4D.flur.zuerich.ubs.ch> |
My web application adds most of the JavaScript event handlers in an init
method. I noticed that those dynamically added handlers are not
executed.
When running the attached example with HttpUnit I only see the alert
message "initForm". When running it in the browser I see "initForm" and
as soon as I click the checkbox "my_checkbox clicked". This is what I
would expect with HttpUnit as well.
Is this kind of JavaScript coding not supported by HttpUnit?
Any ideas how to work around this problem?
Best regards,
Daniel
--- HttpUnit output of example code (see further down)
$ /d/programs/j2sdk1.4.2/bin/java -classpath
".;d:/programs/junit3.8.2/junit.jar;d:/programs/httpunit-1.6.2/lib/httpu
nit.jar;d:/programs/httpunit-1.6.2/jars/js.jar;d:/programs/httpunit-1.6.
2/jars/nekohtml.jar;d:/programs/httpunit-1.6.2/jars/xercesImpl.jar;d:/pr
ograms/httpunit-1.6.2/jars/xmlParserAPIs.jar" junit.textui.TestRunner
AddHandlerTest
.ALERT: initForm
Time: 0.484
OK (1 test)
--- File: add-handler.html
<html>
<head><title>Test</title>
<script type="text/javascript">
<!--
function initForm() {
alert("initForm");
document.my_form.my_checkbox.onclick = checkBoxOnClickHandler;
}
function checkBoxOnClickHandler() {
alert(this.name + " clicked");
}
//-->
</script>
</head>
<body onLoad="initForm();">
<form name="my_form" action="select.html">
<input type="checkbox" name="my_checkbox" value"1">My Checkbox
</form>
</body>
</html>
--- File: AddHandlerTest.java
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebResponse;
import junit.framework.TestCase;
public class AddHandlerTest extends TestCase {
public void testAddHandler() throws Exception {
WebConversation wc = new WebConversation();
WebResponse testPage =
wc.getResponse("http://localhost:8080/add-handler.html");
assertEquals("Test", testPage.getTitle());
WebForm form = testPage.getFormWithName("my_form");
form.setCheckbox("my_checkbox", true);
form.toggleCheckbox("my_checkbox");
while (true) {
String alert = wc.popNextAlert();
if (alert.equals("")) break;
System.err.println("ALERT: " + alert);
}
}
}
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642