-
1. Re: JSFUnit how to test rich:panelBar in combination with a:support
testvogel Dec 6, 2010 7:53 AM (in response to testvogel)Nobody has an idea?
Is it possible to test these RichFaces / Ajax components with JSFUnit?
edit: Why there is no more Ajax4jsfClient?
-
2. Re: JSFUnit how to test rich:panelBar in combination with a:support
ssilvert Dec 6, 2010 8:43 AM (in response to testvogel)Is "onenter" a real event name? I don't see it listed here:
http://en.wikipedia.org/wiki/DOM_events
A4J is now part of RichFaces. We only need one utility class to cover both.
Stan
-
3. Re: JSFUnit how to test rich:panelBar in combination with a:support
testvogel Dec 6, 2010 9:49 AM (in response to ssilvert)I dont't know what you mean with "real" event name.
the onenter event works in my application. I don't remember where I found the onenter event, but onclick didn't worked.
Here is my complete xhtml:
<a:form id="navigationForm" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:rich="http://richfaces.org/rich" xmlns:a="http://richfaces.org/a4j"> <rich:panelBar id="navigationPanel" width="100%" headerClassActive="current" selectedPanel="#{currentNavigationPanel}"> <rich:panelBarItem id="test2" styleClass="navigationLink" label="#{messages['home.navigation.overview.label']}" name="home" contentStyle="display:none"> <a:support event="onenter" action="/pages/home.xhtml"/> </rich:panelBarItem> </rich:panelBar>
edit: I think I have the same problem: http://community.jboss.org/message/71014
-
4. Re: JSFUnit how to test rich:panelBar in combination with a:support
ssilvert Dec 6, 2010 10:21 AM (in response to testvogel)You could try something like this:
JSFClientSession client = jsfSession.getJSFClientSession(); HtmlElement panel = (HtmlElement)client.getElement("navigationPanel:test2") ; panel.fireEvent("onenter");
Stan
-
5. Re: JSFUnit how to test rich:panelBar in combination with a:support
testvogel Dec 6, 2010 11:33 AM (in response to ssilvert)Hi,
thanks for your answer but it isn't the solution.
I got the XPath term with Firebug and I'm using this term now hardcoded in my tests and it works.
Here the code:
HtmlForm form = (HtmlForm) client.getElement("navigationForm"); HtmlElement naviElement = (HtmlElement) form.getFirstByXPath("/html/body/div[4]/div[3]/form/div/div[2]/div"); naviElement.click();
If you have any nicer solution please tell me.
regards,
ole
-
6. Re: JSFUnit how to test rich:panelBar in combination with a:support
ssilvert Dec 6, 2010 1:05 PM (in response to testvogel)The click() does fire your event, so this is just a RichFaces rendering problem. You need a simpler way to find the correct HtmlElement that responds to the click(). The code you showed is very brittle because it will break if your page changes. You will need to write a better XPath query. You will need to look at how RichFaces renders the rich:panelBar. My best advice is to use FireBug to help construct a more generic query that finds the element you are looking for without resorting to a hard-coded full path.
If you think you have a really good one and you can boil it down to an API call that works with any rich:panelBar, then please consider contributing your code back to the project. See the RichFacesClient source code for examples of several of these API implementations:
Stan
-
7. Re: JSFUnit how to test rich:panelBar in combination with a:support
testvogel Dec 8, 2010 9:45 AM (in response to ssilvert)Hi,
I've implemented a short method with a relative XPath term. Maybe you can add this to the RichFacesClient:
public void clickPanelBarItem(String componentID) throws IOException { HtmlPage page = (HtmlPage) jsfClient.getContentPage(); HtmlElement panelBarItem = (HtmlElement) page.getFirstByXPath("//*[@id=\"" + componentID + "\"]/div"); panelBarItem.click(); }
I think it is necessary to get the full page because rich:panelBar isn't always in <form>.
greetz,
ole
-
8. Re: JSFUnit how to test rich:panelBar in combination with a:support
ssilvert Dec 8, 2010 9:29 AM (in response to testvogel)Great! Thanks for your contribution. Can you click through the CLA so I can add your code to the JSFUnit project?
http://www.jboss.org/contributor
I already created a Jira task for it: https://jira.jboss.org/browse/JSFUNIT-262
Stan
-
9. Re: JSFUnit how to test rich:panelBar in combination with a:support
testvogel Dec 8, 2010 10:03 AM (in response to ssilvert)Hi,
I've clicked through the CLA but I've entered the wrong link in the form.
http://community.jboss.org/message/574933 instead of https://jira.jboss.org/browse/JSFUNIT-262
I'm sorry but I hope it's ok.
regards,
ole
-
10. Re: JSFUnit how to test rich:panelBar in combination with a:support
ssilvert Dec 8, 2010 1:29 PM (in response to testvogel)No problem. I've approved the CLA. Thanks again for your contribution. I'll try to get it integrated into the code base before the end of the week.
Stan
-
11. Re: JSFUnit how to test rich:panelBar in combination with a:support
blabno Feb 6, 2011 12:51 PM (in response to testvogel){code}HtmlElement panelBarItem = (HtmlElement) page.getFirstByXPath("//*[@id=\"" + componentID + "\"]/div");{code}
Above will not work after panelBar is re-rendered.
Components that come from ajax request cannot be selected by XPath with tag selectors. Use following instead:
{code}HtmlElement panelBarItem = (HtmlElement) page.getFirstByXPath("//*[@id=\"" + componentID + "\"]/*[@class=\"rich-panelbar-header\"]");{code}
-
12. Re: JSFUnit how to test rich:panelBar in combination with a:support
ssilvert Feb 7, 2011 8:18 AM (in response to blabno)Hi Bernard,
I tried your change and it breaks the testRichPanelBarTest at http://anonsvn.jboss.org/repos/jsfunit/trunk/jboss-jsfunit-examples/jboss-jsfunit-examples-richfaces/src/test/java/org/jboss/jsfunit/test/richfaces/RichPanelBarTest.java
I don't have time to dig into it right now. Maybe your XPath needs to be refined a bit?
Stan