[jsfunit-dev] ClientFacade.clickLink not working for h:commandLink

Pieter Kuijpers pieter.kuijpers at luminis.nl
Wed Aug 8 04:22:47 EDT 2007


Hi Stan,

Thanks for the quick response. I've tried commenting out the two  
lines you indicated, but still no luck. HttpUnit doesn't seem to be  
able to cope with the JavaScript that is generated for the  
commandLink. The error I get is:

com.meterware.httpunit.ScriptException: Event 'if(typeof jsfcljs ==  
'function'){jsfcljs(document.forms['form'],'form:link,form:link','');} 
return false' failed: TypeError: undefined is not a function.  
(httpunit; )
at com.meterware.httpunit.javascript.JavaScript 
$JavaScriptEngine.handleScriptException(JavaScript.java:202)
at com.meterware.httpunit.javascript.JavaScript 
$JavaScriptEngine.performEvent(JavaScript.java:175)
at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent 
(ScriptableDelegate.java:56)
at com.meterware.httpunit.WebRequestSource.submitRequest 
(WebRequestSource.java:232)
at com.meterware.httpunit.WebLink.click(WebLink.java:98)

I'm using JBoss 4.2.0GA, that in turn uses the JSF reference  
implementation, so that may explain why this fix is working for you  
but not for me.

The HTML/Javascript that is generated for link.jsp is:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<title>Link test</title>
</head>

<body>
	<form id="j_id_jsp_918822224_1"
			name="j_id_jsp_918822224_1"
			method="post" action="/JsfTest/link.faces" enctype="application/x- 
www-form-urlencoded">
		<input type="hidden" name="j_id_jsp_918822224_1"  
value="j_id_jsp_918822224_1" />
		<script type="text/javascript" language="Javascript">
		//<![CDATA[
		function dpf(f) {
			var adp = f.adp;
			if (adp != null) {
				for (var i = 0;i < adp.length;i++) {
					f.removeChild(adp[i]);
				}
			}
		};
		function apf(f, pvp) {
			var adp = new Array();
			f.adp = adp;
			var ps = pvp.split(',');
			for (var i = 0,ii = 0;i < ps.length;i++,ii++) {
				var p = document.createElement("input");
				p.type = "hidden";
				p.name = ps[i];
				p.value = ps[i + 1];
				f.appendChild(p);
				adp[ii] = p;i += 1;
			}
		};
		function jsfcljs(f, pvp, t) {
			apf(f, pvp);
			if (t) {
				f.target = t;
			}
			f.submit();
			dpf(f);
		};
//]]>
</script>
		<a id="j_id_jsp_918822224_1:link" href="#"
			onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms 
['j_id_jsp_918822224_1'],'j_id_jsp_918822224_1:link,j_id_jsp_918822224_1 
:link','');}return false" name="j_id_jsp_918822224_1:link">click me</a>
			<input type="hidden" name="javax.faces.ViewState"  
id="javax.faces.ViewState" value="j_id1:j_id2" />
	</form>
</body>
</html>

My JavaScript knowledge is not very deep, so I'm having trouble  
understanding the error message from HttpUnit.

Regards,
Pieter.


Op 8-aug-2007, om 2:41 heeft Stan Silvert het volgende geschreven:

> Hi Pieter,
>
> The fix is taking a little longer than I expected.  If you comment  
> out two lines of code in WebConversationFactory then the  
> client.clickLink() on a commandLink will work (at least with  
> MyFaces 1.1).  The two lines are:
>
> HTMLParserFactory.useJTidyParser();
> HttpUnitOptions.setScriptingEnabled(false);
>
> The problem is, that will break AJAX support.  So I'm not sure what  
> the final solution will be.
>
> Stan
>
> Pieter Kuijpers wrote:
>> I'm trying to test a commandLink in a page with  
>> ClientFacade.clickLink, but this does not seem to be working.
>> link.jsp:
>> <html xmlns="http://www.w3.org/1999/xhtml">
>> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
>> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
>> <f:view>
>> <head>
>> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>> <title>Link test</title>
>> </head>
>> <body>
>> <h:form>
>> <h:commandLink id="link" value="click me" action="target"/>
>> </h:form>
>> </body>
>> </f:view>
>> </html>
>> target.jsp:
>> <html xmlns="http://www.w3.org/1999/xhtml">
>> <head>
>> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>> <title>Link test successful</title>
>> </head>
>> <body>
>> Success.
>> </body>
>> </html>
>> Test code:
>> public class LinkTest extends TestCase {
>>     public void testClickLink() throws Exception {
>>         ClientFacade client = new ClientFacade("/link.faces");
>>         client.clickLink("link");
>>         assertEquals("Link test successful", client.getWebResponse 
>> ().getTitle());
>>     }
>> }
>> The HTML that is returned using client.getWebResponse().getText is  
>> that of link.jsp. When I try the same test by hand, it is working OK.
>> How is this supposed to work?
>> Thanks,
>> Pieter Kuijpers.
>> --------------------------------------------------------------------- 
>> ---
>> _______________________________________________
>> jsfunit-dev mailing list
>> jsfunit-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/jsfunit-dev
>

--
  Pieter Kuijpers
Senior software engineer luminis®
-------------------------------------------------
06 174 185 34
pieter.kuijpers at luminis.nl
www.luminis.nl
-------------------------------------------------



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jsfunit-dev/attachments/20070808/07831b95/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: onbekend.jpg
Type: image/jpeg
Size: 1397 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/jsfunit-dev/attachments/20070808/07831b95/attachment.jpg 


More information about the jsfunit-dev mailing list