Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting ViewState when testing JSF with JMeter

Tags:

java

jsf

jmeter

I'm using JMeter to do some load tests on my JSF application and I'm having trouble passing the ViewState along the pages. The ViewState variable doesn't get extracted at all or it doesn't get passed along the pages.

I've recorded my test steps with a proxy server and this is what it looks like:

First GET Request

I've added the Regex extractor in the first GET request. Tested the regex and it is correct.

First POST Request

In every POST request I replace the hardwired View IDs with my variable.

And what I get when I send the request is the following:

Request sent

The POST parameters are incorrect, as it sends the name of the variable.

POST data:

loginForm%3ArequestToken=&loginForm%3Ausername=heller&loginForm%3Apassword=%21QAYxsw2%A7EDC&loginForm%3AloginButton=Anmelden&com.sun.faces.VIEW=%24%7BjsfViewState%7D&loginForm=loginForm

Could you tell what I'm doing wrong here?
Thanks!

like image 277
al. Avatar asked Feb 28 '13 10:02

al.


People also ask

How to test a single method with JMeter?

With JMeter you should not plan to test a single method. JMeter is supposed to be used for functional testing or Loap&Performance testing. For that you only "simulate a normal user" and then repeat that simulation... The easiest way to do that is to use JMeter's transparent recording proxy (see JMeter doc).

How to get the VIEWSTATE value from the response?

Extract ViewState value from the response using a suitable JMeter Post-Processor, for normal web pages the best option is CSS Selector Extractor. This way you will get the ViewState from the response and save it into a JMeter Variable Request 2 - replace recorded hard-coded ViewState value with the JMeter Variable from the previous step.

How to extract all available occurrences in JMeter?

The regex is not much different: I’ve just used a different name and a negative occurrence number. This will tell JMeter to extract all available occurrences. Note that occurrence 0 tells JMeter to extract one occurrence randomly amongst all that are available.

What is JMeter regular expression extractor and how to use it?

Let’s have some fun! JMeter Regular Expression Extractor is designed to extract content from server responses using Regular Expressions. It is part of JMeter’s Post Processors family. As you can see, there are many other useful post-processors as well like: JSR223: run groovy / javascript / java scripts on the sample result. How do we use it?


1 Answers

The ViewState parameter is an encoded value (Base64 I believe?) and may contain values that would be inappropriate if passed in a GET request through the url. URL parameters are typically encoded so that special values (Eg. space -> %20) can be represented and decoded when the request reaches the server.

The issue here is that the following request is a POST meaning that the parameters do not need to be URL encoded.

com.sun.faces.VIEW=%24%7BjsfViewState%7D&loginForm=loginForm

The above shows that JMeter or some other process is URL encoding the ViewState in the request which is incorrect. The value of the ViewState should simply be sent as is.

like image 184
maple_shaft Avatar answered Nov 12 '22 20:11

maple_shaft