I need to call a Rest API ONCE to get a SAML Token to use in the Authorization Header for all other Thread Group/Users in my test. What is the preferred way of doing this? I can see where I can add a header manager and use the variables from there, but it looks like the variable is scoped to the thread group. I assume I can use a property. To make it simple I want one thread group that calls the api to get the token, so it will only call once set some property and all the other thread groups will use the property to get the SAML token. I am newbie so please be nice, it seems like this is a standard thing to do. My plan was a JSON Extractor and somehow use that to set a property.
2 Answers
The easier way is using JMeter Functions instead of Beanshell (moreover Beanshell scripting is a kind of performance anti-pattern). Also you don't need this 2nd "property to variable" conversion.
In 1st Thread Group use __setProperty() function in order to convert JMeter Variable into a property like
${__setProperty(token,${token},)}
In 2nd Thread Group use __P() function to get the
token
property value like${__P(token,)}
In general using single SAML token for the multiple threads doesn't seem very good idea to me as normally different users should have different tokens and good load test needs to represent real life situations as close as possible. So I would recommend considering using single token per single virtual user. If you need to pass the tokens across thread groups you can go for Inter-Thread Communication Plugin, it is way easier, moreover you will have confidence that 2nd thread won't start until it receives the token from 1st thread.

- 159,985
- 5
- 83
- 133
-
I appreciate this answer, let me try it your way and see. I see your point on the different user, unfortunately they only give me one user to test with, maybe 2. I will present this theory of yours to my lead to see what he says about that. – Maccurt Jul 23 '18 at 10:35
I found these thread(s) that helped: How to get value from property in BeanShell (jmeter)
Still not sure if this is the correct way, but it worked.
- I called my REST API to get my Token
- I Used a JSON extractor to get the Token
I Set a Global Property to hold my token using a Bean Shell Assertion
props.put("token", vars.get("token"));
In my other thread group I get the token from the property
String token = props.get("token"); vars.put("token",token );
In the HTTP Header Manager I get the token from local variable ${token}
This seems tedious, I am hoping there is better way.

- 12,655
- 7
- 32
- 43