A JSF and JMeter issue

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.

Getting ready

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.

How to do it...

We can resume the discussed issue to two requirements:

  • We must simulate the JSF ViewState request parameter.
  • We must include all form elements in a POST request.

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

jsfViewState

Regular expression

<input type="hidden" name="javax.faces.ViewState"

id="javax.faces.ViewState" value="(.+?)" />

Template

$1$

Match no.

0

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

jsfForm %3A_SUBMIT

1

jsfForm %3A_link_hidden_

none

jsfForm %3A_idcl

use the recorded value (if it is a must)

javax.faces.ViewState

${jsfViewState}

Note

In addition, we will add parameters in the same format for all form elements that are part of our request. Check the Encoded box for the extracted view, otherwise the view will not be restored in the server.

How it works...

I think that the previous solution is pretty self explanatory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset