File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ADF MyFaces and HttpUnit testing

Andrew Och
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all

Does anybody know how to test ADF Faces. Any tool would be of interest to me although Opensource and Free Software is


My task is to write a set of unit tests to test an Oracle ADF and Apache MyFaces application. I have attempted to use both

Cactus and HttpUnit. However I am struggling with a simple test case which should simulate a login.

The problem I have is that ADF Faces produces the following dynamic javascript file (I am guessing it is dynamic because I

can not find this in either adf-faces-impl-10_1_3_0_4.jar or adf-faces-api-10_1_3_0_4.jar which are the two jars I am

implementing in my project.):


Which when parsed by js.jar (Rhino javascript engine) I get the following error:

com.meterware.httpunit.ScriptException: Event 'submitForm('maincontent:loginForm',1, {source:'maincontent:submit'});return

false;' failed: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "split" of undefined
at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.handleScriptException (

(This file is in excess of 5000 lines long and so I do not want to post it as this posting is already quite long).

Downloading the file directly after it has been built and modifying it and fixing the error by ensuring the split function is

called on a strongly typed String variable, then commenting out from the web.xml below I tried the HttpUnit test again.


<!-- servlet-mapping>
</servlet-mapping -->

This time I get no error, but the original login page simply gets served again.

login.jsp (which is called as login.jsf)

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="" prefix="c"%>
<%@ taglib uri="" prefix="h"%>
<%@ taglib uri="" prefix="f"%>
<%@ taglib uri="" prefix="tiles"%>
<%@ taglib uri="" prefix="afh"%>
<%@ taglib uri="" prefix="af"%>

<!-- Content -->
<afbjectSeparator />
<af:panelBox text="#{msg['']}" width="100%" background="transparent">
<af:form id="loginForm">
<afbjectSpacer height="10px" />
<af:panelGroup layout="vertical">
<af:panelForm labelWidth="5%">
<!--User Name-->
<af:panelLabelAndMessage for="username">
<af:inputText label="User Name:"
shortDesc="#{msg['global.user.userName']}" />
<af:panelLabelAndMessage for="password">
<af:inputText label="Password:"
shortDesc="#{msg['global.user.password']}" />
<afbjectSpacer height="10px" />
<!--Login Button-->
<af:commandButton id="submit"
action="#{userBean.login}" />


package com.siemens.pse.wmstesting;


import junit.framework.TestCase;
import junit.framework.TestSuite;

import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

public class LoginTest extends TestCase {

* The URL of the Login page for all login tests
public static final String URL = new String( "http://localhost/WMS/pages/login.jsf" );

public static void main( String args[] ) { suite() );

public static TestSuite suite() {
return new TestSuite( LoginTest.class );

public LoginTest( String s ) {
super( s );

public void testGetLogin() throws Exception {
response = new WebConversation( ).getResponse( request );

// Test the result
assertContains( response, "Login Management" );

public void testLoginSuccess() throws Exception {
response = new WebConversation( ).getResponse( request );

WebForm form = response.getFormWithID( "maincontent:loginForm" );
assertNotNull( "No form found with ID 'maincontent:loginForm'", form );

form.setParameter( "maincontent:username", "admin" );
form.setParameter( "maincontent:password", "pass" );

WebLink submit = response.getLinkWithID("maincontent:submit");

response =;

System.out.println( response.getText());

// Test the result
assertContains( response, "Welcome to the Temperature Measurement System" );

* Convenience function that asserts that a substring can be found in
* the returned HTTP response body.
* @param theResponse the response from the server side.
* @param theSubstring the substring to look for
public void assertContains( WebResponse response, String s ) {
String target = new String("");

try {
target = response.getText(); }
catch (IOException e) {
e.printStackTrace(); }

if ( target.indexOf( s ) < 0 ) {
// Error showing which string was NOT found
fail( "Response did not contain the substring: [" + s + "]" );

private WebRequest request = new GetMethodWebRequest( LoginTest.URL );
private WebResponse response;
Andrew Och
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

Well I found the solution to my testing requirements. HtmlUnit is able to deal with the dynamic Javascript that is generated by the ADF Faces application. The strange part is that HtmlUnit uses the Rhino Javascript engine just as HttpUnit and Cactus, however these two could not deal with the javascript whereas HtmlUnit could.

I include two of the test cases that I wrote that now work.

public void testLoginSuccess() throws Exception {
final WebClient webClient = new WebClient( BrowserVersion.INTERNET_EXPLORER_6_0 );
final URL url = new URL("http://localhost/WMS/pages/login.jsf");
final HtmlPage page = (HtmlPage)webClient.getPage(url);

// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page.getFormByName("maincontent:loginForm");

final HtmlTextInput usernameField = (HtmlTextInput) form.getInputByName("maincontent:username");
final HtmlPasswordInput passwordField = (HtmlPasswordInput) form.getInputByName("maincontent assword");

final ClickableElement button = (ClickableElement) form.getHtmlElementById("maincontent:submit");

// Change the value of the text field

// Get the submitted form
final HtmlPage welcomePage = (HtmlPage);

System.out.println( welcomePage.getWebResponse().getContentAsString() );

assertEquals( "Temperature Measurement System", welcomePage.getTitleText() );
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic