-
1. Re: Rich DropDownMenu click
bgregory Sep 12, 2008 7:56 AM (in response to chrisachilli)This is a good case for using a little of the HtmlUnit API directly. You need to get the div tag and click on it.
// Find the div element using the JSFClientSession class // and cast as clickable (HtmlUnit API class) ClickableElement divElement = (ClickableElement)client.getElement("ChiamataCallActionDiv"); // click on it (will do all normal js actions, such as mouseDown, etc) divElement.click();
Brian -
2. Re: Rich DropDownMenu click
chrisachilli Sep 12, 2008 8:55 AM (in response to chrisachilli)Brian, tks for replying. It happens that the client cannot find the Div element: divElement is null thus resulting in a null pointer exception.
The server (UIDiv divCallAction = (UIDiv)server.findComponent("ChiamataCallActionDiv")) can dig it out.
--
Christian -
3. Re: Rich DropDownMenu click
bgregory Sep 12, 2008 9:28 AM (in response to chrisachilli)Unfortunately you can't click() on a component in the server component model, you can only perform user actions from the browser (and therefore the client interface).
Something else you can try is grab the parent element (ChiamataDropDown) with client.getElement(), which most likely be a div since most richfaces components have a surrounding div (com.gargoylesoftware.htmlunit.html.HtmlDivision), and then call toXml() to dump the markup. (This would be the same as "view source" on a regular browser for that sub-section - except this source is normallized to valid xml) This will allow to make sure the htm:div is actually rendered, and discover if richfaces or JSF has mangled the id.
I've noticed that richfaces in particular sometimes doesn't generate ids in a way that makes it easy to search for. JSFUnit element lookup will do a pattern match for the end of an id, but some rf components add to the end or middle of an id. -
4. Re: Rich DropDownMenu click
chrisachilli Sep 12, 2008 11:11 AM (in response to chrisachilli)I got why the client returned null. Sorry I didn't tell you the whole thing!
The matter is that after the login completes the following js code is executed:
open_window_max('homePage.faces','dialogo');
that opens a new window. To retrieve elements from the new window, where ChiamataDropDown resides, I need to get the focus on it. Do you know how can I make the client do that?
At the moment I workarounded with:
window.location='homePage.faces';
Thanks. -
5. Re: Rich DropDownMenu click
bgregory Sep 12, 2008 2:32 PM (in response to chrisachilli)The JSFUnit - HtmlUnit integration isn't great (yet) when it comes to handling multiple browser windows, so if the client isn't seeing the new page it may very well be a bug.
I'll have to put together a simple example and try it out. (if you have a simple project that illustrates the problem it would be very helpful) -
6. Re: Rich DropDownMenu click
chrisachilli Sep 16, 2008 8:25 AM (in response to chrisachilli)Hi Brian,
I prepared a very simple example that shows the problem.
Here are 2 jsp pages:
(index.jsp)<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>PAGE ONE - i'm gonna be closed :(</title> </head> <script> function open_window_max( aURL, aWinName ) { var wOpen; var sOptions; sOptions = 'status=no,menubar=no,scrollbars=yes,resizable=no,toolbar=no,location=no'; sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0'; wOpen = window.open( '', aWinName, sOptions ); wOpen.location = aURL; wOpen.focus(); wOpen.resizeTo( screen.availWidth, screen.availHeight ); wOpen.moveTo(0,0); return wOpen; } </script> <body> <h1>click to open a new page</h1> <form id="contentForm"> <input type="submit" id="button_ok" value="click to close this" onclick="open_window_max('newPage.jsp','hallo');"/> </form> </body> </html>
and newPage.jsp<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hallo!</title> </head> <script> window.opener.close(); </script> <body> <h1 id="title">HERE I AM!</h1> </body> </html>
And here's the unit test:
(test.JSFUnitTest.java)package test; import java.io.IOException; import junit.framework.Test; import junit.framework.TestSuite; import org.jboss.jsfunit.framework.WebClientSpec; import org.jboss.jsfunit.jsfsession.JSFClientSession; import org.jboss.jsfunit.jsfsession.JSFServerSession; import org.jboss.jsfunit.jsfsession.JSFSession; import org.xml.sax.SAXException; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.html.ClickableElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class JSFUnitTest extends org.apache.cactus.ServletTestCase { public static Test suite() { return new TestSuite( JSFUnitTest.class ); } public void testOpenNewPage() throws IOException, SAXException { WebClientSpec wcSpec = new WebClientSpec("/",BrowserVersion.INTERNET_EXPLORER_7_0); wcSpec.getWebClient().setThrowExceptionOnScriptError(false); JSFSession jsfSession = new JSFSession(wcSpec); JSFClientSession client = jsfSession.getJSFClientSession(); JSFServerSession server = jsfSession.getJSFServerSession(); ClickableElement button = (ClickableElement)client.getElement("button_ok"); HtmlPage newPage = (HtmlPage)button.click(); assertEquals("HERE I AM!", newPage.getTitleText()); } }
Hth, thanks