httpunit - javascript and alert box

2010-05-19
2013-04-26
  • David Crocker
    David Crocker
    2010-05-19

    I have a web page that acts as follows:
    1. login
    2. a page is displayed that allows a user to click an image that toggles between open and closed.
    3.  when the image is clicked an alert box is displayed "click yes to continue" (The "yes" button is the default)

    I have been given a task to automate this process.  My question is can httpunit handle this?  I have been able to login and retrieve the link for the image.  However the link.click() fails with the following error:

    .org.mozilla.javascript.EcmaError: TypeError: Cannot read property "is_enabled" from null
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660)
    at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679)
    at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3692)
    at org.mozilla.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1454)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3021)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.doEventScript(ScriptingEngineImpl.java:131)
    at com.meterware.httpunit.scripting.ScriptableDelegate.doEventScript(ScriptableDelegate.java:70)
    at com.meterware.httpunit.HTMLElementScriptable.handleEvent(HTMLElementScriptable.java:95)
    at com.meterware.httpunit.WebRequestSource.handleEvent(WebRequestSource.java:279)
    at com.meterware.httpunit.WebLink.click(WebLink.java:95)
    at com.markelcorp.pingdom.PingDomCheck.testGoodLogin(PingDomCheck.java:83)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at junit.textui.TestRunner.doRun(TestRunner.java:116)
    at junit.textui.TestRunner.doRun(TestRunner.java:109)
    at junit.textui.TestRunner.run(TestRunner.java:72)
    at com.markelcorp.pingdom.PingDomCheck.main(PingDomCheck.java:34)
    E
    Time: 34.595
    There was 1 error:
    1) testGoodLogin(com.markelcorp.pingdom.PingDomCheck)com.meterware.httpunit.ScriptException: Event 'changePausedState(94115,  '/index.php/member/checks/pause');return false;' failed: org.mozilla.javascript.EcmaError: TypeError: Cannot read property "is_enabled" from null
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.handleScriptException(ScriptingEngineImpl.java:64)
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.doEventScript(ScriptingEngineImpl.java:135)
    at com.meterware.httpunit.scripting.ScriptableDelegate.doEventScript(ScriptableDelegate.java:70)
    at com.meterware.httpunit.HTMLElementScriptable.handleEvent(HTMLElementScriptable.java:95)
    at com.meterware.httpunit.WebRequestSource.handleEvent(WebRequestSource.java:279)
    at com.meterware.httpunit.WebLink.click(WebLink.java:95)
    at com.markelcorp.pingdom.PingDomCheck.testGoodLogin(PingDomCheck.java:83)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at com.markelcorp.pingdom.PingDomCheck.main(PingDomCheck.java:34)

    Even if I could get the click working, I then need to send an <enter> key to the display to process the confirmation message (alert box). 

    Can httpunit help me with this task?

    Thanks for any comments or suggestions…