I need to set and get variables in Jmeter for API automation.
I am using the groovy script for same.
I am able to store key-values in Property Files using below code:
props.put("shubhamKey", "shubhamValue")
I do not want to use the main property as it contains so many other keys which may use by Jmeter and we can't place any hardcode key in property directly.
But I am not an able set similar thing in any of below containers :
- User Defined Variables
- User Parameters
The code I am trying is as below:
vars.put("shubhamUserKeyagain","shubhamUservalue")
Use vars.put
and execute the script and click on User Defined Variables. The new key should reflect there but it's not. That is my main issue
I have tried to place User Parameters just below in TestPlan, With-in the request where JSR223 Assertion is present, also tried to place it before and after JSR223 Assertion
My get
value is working fine from these containers but the set is not reflecting over the containers. Below code, I am using to get the value
vars.get("shubhamLocalVariable")
Another code I have tried :
vars.putAll("myNormalValue","changeho")
Is there any other container in which I can set and get key-values using the script as groovy.
Environment :
- OS : Window 10
- Jmeter Version: 3.2 r1790748
- Running bat file as an administrator
I have added my project in below URL:
Please refer and let me know if I missed anything
Reference Screenshots:
User Parameter
JSR233 Assertion