In this recipe, we will discuss an important issue that appears when we try to develop a JMeter test for a JSF application. The main problem is that JSF is a bit special because of the special request parameters needed and the requirement for POST requests. In this recipe, you will see how to fix that in an elegant approach.
If you are not familiar with JMeter or you want to download a JMeter distribution please go through the JMeter main page at http://jakarta.apache.org/jmeter/. A short definition from there says:
Apache JMeter is open source software, a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.
We can resume the discussed issue to two requirements:
ViewState
request parameter.To accomplish the first requirement, we create a JMeter Regex Extractor (you could also use the XPath extractor instead of the Regex). We can apply the extractor to the Thread Group so it applies across the whole test script. The extractor will find the ViewState
parameter and store it in a JMeter variable named jsfViewState
. The necessary parameters are:
Parameter |
Value |
---|---|
Reference name |
|
Regular expression |
|
Template |
|
Match no. |
|
Usually, the first request is a GET request and will be free of JSF, therefore we are more interested in the rest of the requests (that follow after the first request). For this, we need to create an HTTP request using the POST method for all JSF requests. This is possible if we 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
, and then the parameter name. For example, let's suppose a form is named "jsfForm", and here is the minimum set of parameters:
Parameter |
Value |
---|---|
|
1 |
|
none |
|
use the recorded value (if it is a must) |
|
|