Menu

Issues when submitting a form in JavaScript

2003-04-08
2003-06-20
  • David D. Kilzer

    David D. Kilzer - 2003-04-08

    I'm currently writing a test script for a web application at work.

    I am now at a web page that has a form with a field that has an onChange event.  This onChange event calls a JavaScript function which changes the value of a hidden field on the page, then submits the form from within the JavaScript function using obj.submit().  The net effect of all of this is that the page is reloaded with some values now preset in the form.

    Unfortunately, after the form is submitted within the JavaScript function and the page reloaded, it appears that HttpUnit is no longer able to find JavaScript functions that are loaded from external files using <script> tags.

    The following is the exception I'm seeing while running the test:

    ReferenceError: "getBarName" is not defined. (httpunit; line 89)
        at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:590)
        at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:550)
        at org.mozilla.javascript.ScriptRuntime.getBase(ScriptRuntime.java:1112)
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2006)
        at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:58)
        at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:162)
        at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:55)
        at com.meterware.httpunit.FormControl.sendOnChangeEvent(FormControl.java:226)
        at com.meterware.httpunit.TextFormControl.claimValue(FormControl.java:652)
        at com.meterware.httpunit.FormParameter.setValues(FormParameter.java:91)
        at com.meterware.httpunit.WebForm.setParameter(WebForm.java:522)
        at com.meterware.httpunit.WebForm.setParameter(WebForm.java:515)
        at QATest.testAddFooSaveAsIncomplete(QA01Test.java:262)
        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 QATest.main(QA01Test.java:30)

    Thanks for any help you may provide!

    Dave

     
    • David D. Kilzer

      David D. Kilzer - 2003-04-09

      Hmm...this may be a problem with the HTML and JavaScript I'm using, not httpunit.  Will check into this more today.

      Dave

       
    • David D. Kilzer

      David D. Kilzer - 2003-04-09

      Okay, I feel really stupid now.  The getBarName() JavaScript function really was missing from the HTML page.  It's funny how writing test scripts exposes little bugs.

      Sorry!

      Dave

       
    • Anonymous

      Anonymous - 2003-06-20

      Hi
      My requirement is very similar to mine. But i want to know how to make onchange() event on a textfield within a form fire from httpunit.
      I tried using the form.setParameter() method. Doesnt seem to work? Here is my code snippet.
      there is an onchange() event associated with the field "accountDisplay_text" that needs to be executed.
      Any ideas will be appreciated.

              WebRequest request = new PostMethodWebRequest(
                  "http://hostname/servletname" );
              WebConversation webClient = new WebConversation();
              webClient.addCookie(sessionCookieName,sessionCookie);
              WebResponse resp = webClient.getResponse(request);
              detailForm = resp.getFormWithName("pform");
              Assert.assertNotNull("Display of detail not successful", detailForm);

              request = detailForm.getRequest();
              detailForm.setParameter("accountDisplay_text","4142");
              resp = webClient.getResponse(request);

       

Log in to post a comment.

Auth0 Logo