Reputation: 1
Using JMeter
I need to extract the JSF view state value. I am able to extract the value.
Below is the viewstate form response:
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id4" />
My Regular expression extractor is as below:
<input\s+type="hidden"\s+name="javax\.faces\.ViewState"\s+id="javax\.faces\.ViewState"\s+value="([^"]+)".*/>
This works fine. I get j_id4
value correctly and places.
But my big problem is for every API call the value changes. First API call the view state value is j_id4
, but the next API call view state will be j_id5
How do I handle this?
Upvotes: 0
Views: 1134
Reputation: 168092
Parsing HTML with Regular Expressions is not the best idea, I would recommend going for CSS/JQuery Extractor instead, the relevant configuration would be as simple as:
viewstate
input[name=javax.faces.ViewState]
value
If your test assumes 2 (or more) HTTP Request samplers you will need to either apply a CSS/JQuery Extractor to each of them as ViewState will change on each call so you will need to extract it each time. Alternatively you can put CSS/JQuery Extractor at the same level as your HTTP Request samplers, JMeter's Post-Processors are obeying Scoping Rules so single Extractor will be applied to all the Samplers it its scope. Something like:
Upvotes: 1
Reputation: 983
You can add 2 regular expression extractors, one will extract j_id, the expression will be as below:
The second will extract the number 4, the expression will be as below:
Now add a beanshell post processor for each of your API's with the following code:
String j_id = vars.get("j_id");// j_id is the reference name of the first regular expression extractor
int num = Integer.parseInt(vars.get("num"));// num is the reference name for the second regular expression extractor
num = num + 1;
vars.put("num",String.valueOf(num));
vars.put("JSF", j_id + num);
For the first API you can use the same regular expression you were using, after adding the above beanshell post processor to all of the API's that you need to extract the JSF view state value from, use ${JSf} which will hold the value j_id5 for the second API and j_id6 for the third API and so on.
Upvotes: 0