6 Replies Latest reply on Jan 24, 2011 3:05 AM by testvogel

    Unable to run a simple JSFUnit test

    shuklarajesh

      We are unable to run a simple JSFUnit Test and are seeing the error pasted below while trying to execute a test on a very simple JSF/facelet Page. Please Help ?


      TIA.



      TypeError: Cannot find function navigate in object [object]. (script in http://localhost:8080/App2/ from (13, 9) to (27, 10)#23)


      ======= EXCEPTION START ========

      EcmaError: lineNumber=[23] column=[0] lineSource=[null] name=[TypeError] sourceName=[script in http://localhost:8080/App2/ from (13, 9) to (27, 10)] message=[TypeError: Cannot find function navigate in object [object]. (script in http://localhost:8080/App2/ from (13, 9) to (27, 10)#23)]

      com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function navigate in object [object]. (script in http://localhost:8080/App2/ from (13, 9) to (27, 10)#23)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:604)

      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)

      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:534)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)

      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:195)

      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:214)

      at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:735)

      at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:866)

      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)

      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)

      at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:871)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1162)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:202)

      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:308)

      at com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:58)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1276)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:216)

      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:308)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:370)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:355)

      at org.jboss.jsfunit.framework.SimpleInitialRequestStrategy.doInitialRequest(SimpleInitialRequestStrategy.java:48)

      at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:259)

      at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:81)

      at test.jsfunit.JSFUnitTest.testBasicAuth(JSFUnitTest.java:36)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)

      at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)

      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:94)

      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:225)

      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:1)

      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:102)

      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:225)

      at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:1)

      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)

      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:73)

      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:225)

      at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:1)

      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:119)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)

      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)

      at java.lang.Thread.run(Thread.java:662)

      Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function navigate in object [object]. (script in http://localhost:8080/App2/ from (13, 9) to (27, 10)#23)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3750)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3778)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3797)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3861)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2346)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2313)

      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1515)

      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)

      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)

      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:429)

      at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:267)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3162)

      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)

      at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:80)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:562)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:527)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:598)

      ... 63 more

      Enclosed exception:

      net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function navigate in object [object]. (script in http://localhost:8080/App2/ from (13, 9) to (27, 10)#23)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3750)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3778)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3797)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3861)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2346)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2313)

      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1515)

      at script.nWin(script in http://localhost:8080/App2/ from (13, 9) to (27, 10):23)

      at script(onload event for HtmlBody[<body onload="nWin()">] in http://localhost:8080/App2/)

      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)

      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)

      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:429)

      at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:267)

      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3162)

      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)

      at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:80)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:562)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:527)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:598)

      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)

      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)

      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:534)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)

      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:195)

      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:214)

      at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:735)

      at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:866)

      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)

      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)

      at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:871)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1162)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:202)

      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:308)

      at com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:58)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1276)

      at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:216)

      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:308)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:370)

      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:355)

      at org.jboss.jsfunit.framework.SimpleInitialRequestStrategy.doInitialRequest(SimpleInitialRequestStrategy.java:48)

      at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:259)

      at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:81)

      at test.jsfunit.JSFUnitTest.testBasicAuth(JSFUnitTest.java:36)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)

      at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)

      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:94)

      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:225)

      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:1)

      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:102)

      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:225)

      at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:1)

      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)

      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:73)

      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:225)

      at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:1)

      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:119)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)

      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)

      at java.lang.Thread.run(Thread.java:662)

      == CALLING JAVASCRIPT ==

      function () {

      [native code, arity=0]

      }


      ======= EXCEPTION END ========


      We did looked at the other threads and have tried  both HtmlUnit 2.9 Snapshot as well as HtmlUnit 2.8, but are getting the same exception.


      The app is deployed on Tomcat 6 The libraries we are using are

      cactus 1.8.1

      htmlunit 2.8 also tried with 2.9 Snapshot

      junit 4.6

      cargo 0.6


      and here is the test class


      public class JSFUnitTest extends org.apache.cactus.ServletTestCase {


          public static Test suite() {

              return new TestSuite(JSFUnitTest.class);

          }


          public void testBasicAuth() throws IOException {

              final WebClientSpec wcSpec = new WebClientSpec("/TestPage.jsf");

              final JSFSession jsfSession = new JSFSession(wcSpec);

              final JSFServerSession server = jsfSession.getJSFServerSession();

              assertEquals("/TestPage.jsf", server.getCurrentViewID());

              final JSFClientSession client = jsfSession.getJSFClientSession();

              assertTrue(client.getPageAsText().contains("Enter"));

           }

      }


      and the testPage.xhtml is


      <ui:composition xmlns="http://www.w3.org/1999/xhtml"

          xmlns:f="http://java.sun.com/jsf/core"

          xmlns:h="http://java.sun.com/jsf/html"

          xmlns:rich="http://richfaces.org/rich"

          xmlns:ui="http://java.sun.com/jsf/facelets">


          <ui:define name="content">

          <div>


          <h:form id="form1">   


            <h:outputText value="Enter your name:" rendered="#{empty foo.text}" id="prompt"/>

            <h:outputText value="Hello #{foo.text}" rendered="#{!empty foo.text}" id="greeting"/>


            <h:inputText value="#{foo.text}" id="input_foo_text"/>

            <h:message for="input_foo_text" styleClass="errorMessage"/>

            <br/>

            <h:commandButton value="Submit" action="/TestPage.jsf" id="submit_button"/>

            <h:commandButton value="Goodbye" action="/finalgreeting.jsp" id="goodbye_button"/>


          </h:form>

          </div>

          </ui:define>

      </ui:composition>



      Filters Mapping in the Web.xml


      <filter>

            <filter-name>JSFUnitFilter</filter-name>

            <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>

          </filter>


          <filter-mapping>

            <filter-name>JSFUnitFilter</filter-name>

            <servlet-name>ServletTestRunner</servlet-name>

          </filter-mapping>   


          <filter-mapping>

            <filter-name>JSFUnitFilter</filter-name>

            <servlet-name>ServletRedirector</servlet-name>

          </filter-mapping>


          <servlet>

            <servlet-name>ServletRedirector</servlet-name>

            <servlet-class>org.jboss.jsfunit.framework.JSFUnitServletRedirector</servlet-class>

          </servlet>


          <servlet>

             <servlet-name>ServletTestRunner</servlet-name>

             <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>

          </servlet>


          <servlet-mapping>

            <servlet-name>ServletRedirector</servlet-name>

            <url-pattern>/ServletRedirector</url-pattern>

          </servlet-mapping>


          <servlet-mapping>

             <servlet-name>ServletTestRunner</servlet-name>

             <url-pattern>/ServletTestRunner</url-pattern>

          </servlet-mapping>