Menu

Problem with link.onclick and form.submit

2002-08-12
2002-08-27
  • Stefano Malimpensa

    I found a strange behavior: when I run the following javascript code in HTTPUnit, an exception is thrown by the javascript interpreter. I wonder where is the problem...

    This is the my JUnit test:

        public void testFormOnClick() throws Exception {
            defineResource(  "test1.html", "<HTML><HEAD></HEAD><BODY>"+
                "<FORM name=\"foobar\" action=\"test2.html\"></FORM>"+
                "<A href=\"#\" name=\"testClick\" onclick=\"document.foobar.submit();\">test click</A>"+
                "</BODY></HTML>");

            WebConversation wc = new WebConversation();
            WebResponse response = wc.getResponse( getHostPath() + "/test1.html" );
           
            response = response.getLinkWith("test click").click();
            assertNotNull(response);
        }

    And this is the exception thrown by rhino just after the click method call:

    TypeError: undefined is not a function.
        at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:496)
        at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:467)
        at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1203)
        at org.mozilla.javascript.gen.c2.call(httpunit:0)
        at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:96)
        at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:40)
        at com.meterware.httpunit.WebLink.click(WebLink.java:85)
        at test.TestLinkClick.testOnClick(TestLinkClick.java:31)
        at java.lang.reflect.Method.invoke(Native Method)
        at junit.framework.TestCase.runTest(TestCase.java:166)
        at junit.framework.TestCase.runBare(TestCase.java:140)
        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:131)
        at junit.framework.TestSuite.runTest(TestSuite.java:173)
        at junit.framework.TestSuite.run(TestSuite.java:168)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:202)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:116)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:68)

    I've used the last CVS version.

    Thanks.

    Stefano

     
    • Russell Gold

      Russell Gold - 2002-08-25

      form.submit support was not added until 5 days after you tried this. This should now work.

       
      • Stefano Malimpensa

        Thanks a lot, I'm going to use HTTPUnit as unit testing tool for my web applications. In fact I've seen the features when you checked in cvs and now it works.

         

Log in to post a comment.

Auth0 Logo