• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

ADF MyFaces and HttpUnit testing

Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 (JavaScript.java:202)

(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="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://xmlns.oracle.com/adf/faces/html" prefix="afh"%>
<%@ taglib uri="http://xmlns.oracle.com/adf/faces" prefix="af"%>

<!-- Content -->
<af:objectSeparator />
<af:panelBox text="#{msg['login.info.loginHeader']}" width="100%" background="transparent">
<af:form id="loginForm">
<af:objectSpacer 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']}" />
<af:objectSpacer height="10px" />
<!--Login Button-->
<af:commandButton id="submit"
action="#{userBean.login}" />

TestCase LoginTest.java:

package com.siemens.pse.wmstesting;

import java.io.IOException;

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[] ) {
junit.textui.TestRunner.run( 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 = submit.click();

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) button.click();

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

assertEquals( "Temperature Measurement System", welcomePage.getTitleText() );
    Bookmark Topic Watch Topic
  • New Topic