Bandita Pradhan - 2008-07-10

Hi,

I am getting error when I run my Httpunit testcase.  It seems like I am missing something.
I added the statement to turn off javascript errors which is HttpUnitOptions.setExceptionsThrownOnScriptError( false );

But I am using javascript in my code. Not sure if I should turn off javascript errors.

Thanks,
Bandita

org.mozilla.javascript.JavaScriptException: [object Error] (httpunit#95)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2461)
    at script(httpunit:95)
    at script(httpunit:379)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:161)
    at org.mozilla.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2172)
    at org.mozilla.javascript.BaseFunction.execIdCall(BaseFunction.java:257)
    at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3085)
    at script(httpunit:420)
    at script(httpunit:18)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)
    at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1132)
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:92)
    at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)
    at com.meterware.httpunit.parsing.NekoDOMParser.runScript(NekoDOMParser.java:151)
    at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:150)
    at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131)
    at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:249)
    at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:367)
    at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1015)
    at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:888)
    at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(HTMLScanner.java:2831)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:809)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:478)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:431)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:48)
    at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:271)
    at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1301)
    at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)
    at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)
    at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
    at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)
    at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:519)
    at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)
    at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
    at com.meterware.httpunit.WebResponse.openNewWindow(WebResponse.java:735)
    at com.meterware.httpunit.WebResponse$Scriptable.open(WebResponse.java:826)
    at com.meterware.httpunit.javascript.JavaScript$Window.jsFunction_open(JavaScript.java:405)
    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 org.mozilla.javascript.MemberBox.invoke(MemberBox.java:145)
    at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:471)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3085)
    at script.redirect(httpunit:21)
    at script.x(httpunit)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:161)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.doEventScript(ScriptingEngineImpl.java:131)
    at com.meterware.httpunit.scripting.ScriptableDelegate.doEventScript(ScriptableDelegate.java:70)
    at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:819)
    at com.meterware.httpunit.javascript.JavaScript.load(JavaScript.java:80)
    at com.meterware.httpunit.javascript.JavaScriptEngineFactory.load(JavaScriptEngineFactory.java:62)
    at com.meterware.httpunit.RequestContext.runScripts(RequestContext.java:44)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:159)
    at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:199)
    at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:125)
    at com.meterware.httpunit.WebClient.getResponse(WebClient.java:96)
    at com.hp.ov.nms.ui.qsw.AbstractNnmTest.setUp(AbstractNnmTest.java:30)
    at junit.framework.TestCase.runBare(TestCase.java:128)
    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:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

---------------------------------------------------------------------------------

package com.hp.ov.nms.ui.qsw;

import com.meterware.httpunit.Button;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.GetMethodWebRequest;

public class SignInTest extends AbstractNnmTest {
    public SignInTest() {
       // super(null, "comm-setup", null);
       
    }
  
    //Test to check Login Form Exists
    public void testLoginForm() throws Exception {
        wc = new WebConversation();
        WebResponse response = wc.getResponse("http://localhost:" + getHttpPort() + "/nnm");
        WebForm form = response.getForms()[0];
        assertTrue("Login page is missing ",response.getFormWithID("contactform") != null);
    }
}

package com.hp.ov.nms.ui.qsw;

import junit.framework.TestCase;
import com.meterware.httpunit.Button;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.*;

public class AbstractNnmTest extends TestCase {
   
     /**
     * system property for passing in the jndi port to use.
     */
    public static final String PORT_JNDI = "com.hp.ov.nms.ui.jboss.jnp.port";
    public static final String PORT_WEB = "com.hp.ov.nms.ui.jboss.http.port";

    protected WebConversation wc;
   
    protected AbstractNnmTest() {
    }

    protected void setUp() throws Exception {
        // Don't let JavaScript errors trip us up !
        HttpUnitOptions.setExceptionsThrownOnScriptError( false );
        super.setUp();
        // importFile("commDefault1161_1secTimeout.xml");
        wc = new WebConversation();
        WebResponse resp = wc.getResponse("http://localhost:" + getHttpPort() + "/nnm");
        WebForm form = resp.getForms()[0];
        form.setParameter("j_username", "system");
        form.setParameter("j_password", "openview");
        Button login = getActionButton(form, "btnSignIn:btnCommandButton");
        login.click();
    }
   
    @Override protected void tearDown()
          throws Exception {
        super.tearDown();
    }
   
    protected String getHttpPort() {
        return System.getProperty(PORT_WEB, "55500");
    }

    protected Button getActionButton(WebForm form, String value) {
        Button[] buttons = form.getButtons();
        for (Button button : buttons) {
            // support both javascript and submit action buttons
            if (value.equals(button.getName())) {
                return button;
            } else if ("action".equals(button.getName()) && value.equals(button.getValue())) {
                return button;
            }
        }
        return null;
    }
   
    protected WebResponse getCurrentPage() {
       
        return wc.getMainWindow().getCurrentPage();
    }

   
   
}