Testing a JSF Application with JMeter

JMeter is an open-source performance testing tool that is useful for stress-testing web applications. JavaServer Faces presents interesting challenges with scripted testing because of the special request parameters needed and the requirement for POST requests. This document attempts to boil the requirements down in a simple fashion.

There are two main requirements to scripting a JSF application. First, you must simulate the JSF ViewState request parameter. Second, you must include all form elements in a POST request. The easiest way to create the initial script is to set up JMeter to record your request/response streams and use the scripts JMeter creates as a starting point.

ViewState Extractor

To simulate the ViewState parameter create a JMeter RegEx Extractor. The best approach is to apply the extractor to the Thread Group so it applies across the whole test script. Use the following parameters:

Reference Name

jsfViewState

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4cea204f-5b3a-4119-879d-13890ea395f7"><ac:plain-text-body><![CDATA[

Regular Expression

<input type="hidden" name="javax\.faces\.ViewState" id="javax\.faces\.ViewState" value="([^"]+)".*/>

]]></ac:plain-text-body></ac:structured-macro>

Template

$1$

Match No.

0

This extractor will find the ViewState parameter and store it in a JMeter variable called jsfViewState so it can be passed down in future requests.

The First Request

The first request to most applications will be a GET request and will not contain any JSF information. Script this request as you would any initial request for a non-JSF web application.

Subsequent Requests

Create an HTTP Request using the POST method for all JSF requests. Again, the best way to approach this is to record a session with the web application and change the dynamic variables. All JSF requests will have a few request parameters that need to be part of the request. All of these parameter names will start with the name of the form, then a "%3A", then the parameter name. For example if the form is named "myForm" you will see at least the following parameters:

Parameter Name

Parameter Value

myForm%3A_SUBMIT

1

myForm%3A_link_hidden_

(No value)

myForm%3A_idcl

Hard to script. Best to use the recorded value, but you can figure it out if you have to.

javax.faces.ViewState

${jsfViewState}

In addition to the above "standard" variables you will need to add parameters in the same format for all form elements that are part of your request.

Some notes

For the extracted view, remember to check the "Encoded" box, otherwise the view will be sent as-is including special characters and it will not be restored in the server. This leads to unexpected behaviour, one of them is an _ErrorPageWriter.isText exception (as of myfaces 1.1.7), or a "view cannot be restored" message

For the rest of the values, try to use the already encoded id, eg: use: myForm%3A_link_hidden_ and you should leave the "Encoded" checkbox off

You could also use the whole id, eg: Use: myForm_:link_hidden but if you do that, you must remember to mark the Encoded checkbox on JMeter

Alternative

You could also use the xPath extractor instead of the Regex for getting the view information

  • No labels