4 Replies Latest reply on Jun 18, 2009 12:04 PM by Stan Silvert

    JSFUnit Navigation Problem

    Darrel Riekhof Newbie

      New to and JSFUnit and somewhat new to JSF. Having a problem in the first 'real world' test case I'm trying to write. My goal in this test case is to Navigate from our webapp's intial screen to its login screen, then put some bad values in the username and password fields, and to verify that it fails to login. I'm stuck at getting it to navigate to the login screen. It just stays at the banner page after clicking the button.

      Here's my test case so far, trying to just get it to navigate to login page. client.getPageAsText(), viewId, currentView, they all never change after click.

       /**
       * Test to make sure a bad userName fails login
       */
       public void testBadUser()
       {
       try {
       JSFSession jsfSession = new JSFSession("/ui/Banner.jsf");
       JSFClientSession client = jsfSession.getJSFClientSession();
       JSFServerSession server = jsfSession.getJSFServerSession();
      
      log.fine( "\nserver currentViewID=" + server.getCurrentViewID() );
      log.fine( "\nserver facesContext.viewRoot.viewId=" + server.getFacesContext().getViewRoot().getViewId() );
      log.fine( "\n============================ client page =======================\n" + client.getPageAsText() );
      
      log.fine( "\n========== clicking ================" );
      // client.click( "formBanner:btnAgree" );
       client.click( "btnAgree" );
      log.fine( "\n========== after click ================" );
      
      log.fine( "\nserver currentViewID=" + server.getCurrentViewID() );
      log.fine( "\nserver facesContext.viewRoot.viewId=" + server.getFacesContext().getViewRoot().getViewId() );
      log.fine( "\n============================ client page =======================\n" + client.getPageAsText() );
      
       } catch ( Exception e ) {
       e.printStackTrace();
       fail( "Unexpected Exception in testBadUser(): " + e.toString() );
       }
       }



      Here's the button's HTML returned from getPageAsText() that I need to click to get to the login page:

       <input id="formBanner:btnAgree" name="formBanner:btnAgree" onclick="A4J.AJAX.Submit('j_id_id2','formBanner',event,{'parameters':{'formBanner:btnAgree':'formFederalBanner:btnAgree'} ,'actionUrl':'/foo/ui/Banner.jsf'} );return false;" value="I Agree" style="cursor:pointer" type="submit"/>
      


      See anything obvious I am doing wrong? Or maybe I just don't understand how it works--should clicking the button change what is returned by getCurrrentViewID(), getViewId() and getPageAsText()?