0
votes

I'm having some trouble with my JMeter test in regards to passing a variable to other requests in the same thread group.

I have 3 requests and one of them is a login request that is only executed once while other 2 requests are looping for one hour. The other 2 requests need to receive a variable 'access token' that is extracted from a login request response in order for them to return a status 200 response.

However, I notice in request header for those 2 requests that the variable 'access token' is not sent in the header although I receive that variable in login request response, extract it with JSON extractor and then send it in the request header.

This my test plan structure:

enter image description here

This is how I extract the variable from the login request:

enter image description here

...and this is how I send the 'access token' variable in request header for other 2 requests:

enter image description here

Everything worked fine until I added the If controller that executes the login request only once and I use this statement in If controller:

${__groovy(ctx.getThreadNum() == 0 &&  vars.getIteration() == 1,)}

The login request executes correctly and the 'access token' variable is located in the header response.

I can't figure it out, why doesn't variable gets passed to the other two requests?

1

1 Answers

0
votes

Different threads don't share same JMeter variables as accessToken

So you need to saved value in JMeter property, for example add JSR223 Sampler

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

And change your header value to get from JMeter property:

${__P(accessToken)}

vars - JMeterVariables - e.g.

vars.get("VAR1");

props - JMeterProperties (class java.util.Properties) - e.g.

props.put("PROP1","1234");