JMeter - Using Variables from other BeanShell Pre/Post-Processors?

南楼画角 提交于 2019-12-11 03:04:39

问题


Is there a way to reference a variable from one BeanShell Pre/Post-Processor to another BeanShell Processor (they are within the same Thread Group)?

If I create a String variable inside a BeanShell PreProcessor under an HTTP Request, can I then use or reference that variable inside a BeanShell PostProcessor under that same HTTP Request..?

I tried Accessing this variable in the following ways:

    + HTTP Request
       + BeanShell PreProcessor:

String preProcessor1_MYID = "Value_1";

       + BeanShell PostProcessor:

String postProcessor1_MYID = "Value_2";
//Try #1:
String tmp_preProcessor1_MYID = preProcessor1_MYID;
//Try #2:
String tmp_preProcessor1_MYID = ${preProcessor1_MYID};
//Try #3:
String tmp_preProcessor1_MYID = ${__V(preProcessor1_MYID)};
//Try #4:
String tmp_preProcessor1_MYID = vars.get("preProcessor1_MYID");


Is there a different function like ${__V()} or vars.get(), that I'm missing that I'm supposed to be using? I was also wondering if I needed a User Defined Variables object in order to share this variable between BeanShell Pre/PostProcessors but I wasn't sure. I also read about the ${__BeanShell()} function, but didn't think that was what I was looking for either... Any ideas? I would assume this should be possible, but was hoping I didn't need to add anything like the User-Defined Vars object.

Any thoughts or suggestion would be greatly appreciated!

Thanks in Advance,
Matt


回答1:


If you need to use the value in other elements later,

store it in a vairable

vars.put("myvar", "value");

Now you can access it using

${myvar}

or in beanshell

vars.get("myvar").

  • You can also go for user defined variables, properties (share among thread groups).
  • Check this - it is also another option. - jMeter - Beanshell bsh.shared hashmap data in init file?


来源:https://stackoverflow.com/questions/29924947/jmeter-using-variables-from-other-beanshell-pre-post-processors

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