I'm facing an issue while running a recorded test scenario of an application login using a single user on JMeter.

I've used JMeter's proxy server to record all the requests of the login scenario. The proxy server records all the requests fine. When i play the recorded scenario, the login step gives response data that contains "Your session has expired". It seems that the JSF ViewState value is getting hard-coded when I record the requests due to which when the steps are played the new ViewState values generated from the server do not match.

I tried using solutions given in these links to handle ViewState values:

But still it doesn't work.
Am i missing something?
Or is it something other than the ViewState that's causing the recorded steps to fail?

Screenshots below:

screen #1 screen #1

screen #2 screen #2

screen #3 screen #3

  • I used the procedure in your first link and it worked. Jun 5, 2012 at 8:24
  • it's not working. These are the steps i followed: 1. Recorded the steps using the proxy server. 2. Added a user-defined variable 'jsfViewState' to the Thread Group. 3. Added a RegEx Extractor to the Thread Group with reference name 'jsfViewState' and value as <input type="hidden" name="javax\.faces\.ViewState" id="javax\.faces\.ViewState" value="(.+?)" /> 4. Modified the javax.faces.ViewState Request Parameter for the login steps as ${jsfViewState} and any further requests that are using the ViewState parameter. 5. Played the steps. Jun 5, 2012 at 9:23
  • Are these the steps you followed too? Jun 5, 2012 at 9:29
  • You have to keep changing the "ViewState" in every POST. You extract the ViewState and insert it in the next POST. This is allways changing. Dec 28, 2017 at 4:43

2 Answers 2


1) You have to extract viewState value BEFORE the usage.
I.e. if you send viewState value along with login-request so you have to extract this value from response to PREVIOUS request.

Thread Group
    HTTP Request 01 : /login GET
        XPath Extractor : extract jsfViewState
    HTTP Request 02 : /login POST (send previously extracted jsfViewState as param)
        XPath Extractor : extract jsfViewState for next request
    . . .

2) You are extracting viewState to the variable ${Var_ViewState} (screen #1) but refer it as ${ViewState} (screen #3).
Be careful.

3) In your XPath Extractor (screen #1) you have to check Use Tidy (tolerant parser) checkbox on the element's control panel - since you are using xpath against html, not xml (presume that some kind of warning should also appear in jmeter.login this case).

XPath query itself looks good, although string() is redundant.

4) Add HTTP Cookie Manager to your test-plan to handle session variables (jsessionid).

  • Sorry about refering to the Var_ViewState variable as ${ViewState}. I did realize that after posting my query here. But correcting the reference still didn't help me. I haven't tried the steps 1,3,4 you mentioned. Will check that and revert back. Thanks a lot for your help. Jun 5, 2012 at 9:34
  • I enabled the Use Tidy (tolerant parser) checkbox. And also used the HTTP Cookie Manager. But I have just added a HTTP Cookie Manager to the Thread Group. Do i have to make any changes / add any cookies in the Cookie Manager? It's still not working. Jun 5, 2012 at 10:58
  • @ Abhijeet, HOW it's not working? Is jsfViewState extracted? What's in jmeter.log? Simply add HTTP Cookie Manager at the top level (Test Plan), that's should be enough. Have you encoded jsfViewState value upon sending along with request ("Encoded" checkbox, wiki.apache.org/myfaces/PerformanceTestingWithJMeter -> Some Notes)? Jun 5, 2012 at 11:05
  • jmeter.log: pastebin.com/yAij3w5H Yes, i've added HTTP Cookie Manager at the top level (Test Plan). And i've set the encoded checkbox for jsfViewState to checked. I have referenced jsfViewState as ${jsfViewState} in the parameters (after the login request) of any requests that contain ViewState in their headers. I'm very much confused as to what's exactly not working. I'm completely a JMeter newbie, so please bear with me. Jun 5, 2012 at 11:42
  • Okay. Once more. See point #1 in answer above - I've added schema to use. To send jsfViewState value along with login POST request you need somehow extract it (ViewState) before - e.g. send login GET first. You will extracted jsfViewState value on each request to use it in the NEXT one - but not in the same. Jun 5, 2012 at 11:58

Just one change worked for me Jmeter 2.13.

In Screen 1 change ${Var_ViewState} to ${jsfViewState}
since you are using ${ViewState} in Screen 2 change that to ${jsfViewState}


  1. Checking Tidy (tolerant parser) doesn't work.
  2. my xpath query was string(//input[@id='javax.faces.ViewState']/@value)
  3. I used the jmeter proxy recording to generate the test plan. https://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf
  4. No changes were made on the encoding on the recorded script
  5. Change the javax.faces.ViewState parameter to ${jsfViewState} in all the recored files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.