0
votes

I did create a simple testcase in JMeter.

Open a form and all it's content (css, images etc) :

  • GET /
  • GET /css/site.css
  • GET /favicon.ico
  • GET /fonts/specific-fonts.woff
  • GET /images/banner.png

Wait a little...
Post the values

  • POST /

Receive the "Thank You" page. - GET /thanks

In the response on the first GET is a hidden input field which contains a token. This token needs to be included in the POST as well. Now I use the "Regular Expression Extractor" of JMeter to get the token from the response. So far, so good. Then, after retreiving all the other contents I create the POST message, using the variable name in the RegExp-Extractor in the value field of the token parameter. But... when executing the testcase it fills in the default value given and not the actual value of the token.

So... first step in debugging this issue was to add a dummy-HTTP-GET request directly after I get the token. In this GET request I also add the token parameter with the token variable as value, but now I can easily check the parameter by looking at the access-log on my webserver. In this case... the URL looks promising. It contains the actual token value in the GET, but it still uses the default value in the POST.

Second step in debugging was to use the "Debug Sampler" and the "View Results Tree". By moving the Debug Sampler between the different steps I found out the value of the token-variable is back to the default value after I receive the CSS.

So... now the big question is... How can I make JMeter to remember my variable value until the end of my test-script ?

2
Found a way to work around it :-) ... I did put the first GET and the Regular Expression Extractor inside a simple controller. The rest (except for the timer to "Wait a little...") is still in the main stream. This solves the issue. - user3472174

2 Answers

1
votes

JMeter doesn't "forget" variables. However variables scope is limited to the current Thread Group. You can convert JMeter variable to JMeter Property which have "global" scope by i.e. using Beanshell Post Processor with the following code:

props.put("myVar", vars.get("myVar"));

Or by using __setProperty() function. See How to Use Variables in Different Thread Groups guide for details.

1
votes

As you found it your problem comes from a misunderstanding of scoping rules in jmeter.

In your case, just put the post processor of the request that will give you the response containing the child node. Also I think you don't need to share this token with other threads so don't use properties as proposed in the alternate answer.