-
1. Testing dynamically rendered component
ssilvert Mar 7, 2011 4:36 PM (in response to dele)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 Mar 9, 2011 10:13 AM (in response to ssilvert)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.