How to set variable and its value in Jmeter container like User Parameters using script

社会主义新天地 提交于 2019-12-11 08:53:44

问题


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:

https://ufile.io/7r6tk

Please refer and let me know if I missed anything

Reference Screenshots:

User Parameter

JSR233 Assertion


回答1:


This one works for me - I have cleared up your script



来源:https://stackoverflow.com/questions/48499435/how-to-set-variable-and-its-value-in-jmeter-container-like-user-parameters-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!