2 Replies Latest reply on Mar 9, 2011 10:13 AM by dele

    Testing dynamically rendered component

    dele

      Hi

       

      A button in my form (form A) that is bound (component binding) to a property in the backing bean, is conditionally set to "not

      rendered" ( createStatusButton.setRendered(false) ) by the backing bean after the form is submitted.  Please advise on how I can use

      JSFUnit to verify that the the button has been changed from rendered to "not rendered" after form submission. 

       

      I noticed that JSFUnit calls my action method after the render response phase.

       

      Please note:  The same form (form A) is rendered after submission.

       

      Thank you.

        • 1. Testing dynamically rendered component
          ssilvert

          I really like this question because it demonstrates what can be done with JSFUnit that you simply can't do with black-box tools like Selenium.

           

          BTW, JSFUnit doesn't actually call your action method.  The action method is called in the normal course of your JSF request.

           

          So if you've used JSF for awhile you know that every view has a "vew tree" on the server side that has a UIComponent object for every component.  You can search the view tree for a component by its ID with JSFServerSession.findComponent().  Then you just call UIComponent.isRendered() to see if the component was rendered during the last request.  If you need to do more complex queries you can also use the JSF API.  Just get the root component with JSFServerSession.getFacesContext().getViewRoot() and go from there.

           

          An example of testing for "rendered" on a server side component is included in the Getting Started page at http://www.jboss.org/jsfunit/gettingstarted.html

           

          Stan

          • 2. Testing dynamically rendered component
            dele

            Stan,

             

            Thanks a lot for your response.  As a result of your directions, I have now got the test working. 

             

            What I did wrong was to have retrieved the component (JSFServerSession.findComponent(Constants.createStatusButton) ) that is to be tested, before submitting the form (JSFClientSession.click() ).  I assumed that the component will simply be updated after submission.  Now I have realized that after submission a brand new component  is created/updated (for the same component id).  Therefore, I now retrieve the component again, after submission.