3

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

Matt
  • 413
  • 1
  • 10
  • 16

1 Answers1

4

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").

Community
  • 1
  • 1
vins
  • 15,030
  • 3
  • 36
  • 47
  • Thanks for the reply Vinoth! Oh ok cool, I didn't think you could "create" a var using the "vars.put()" method, cool I'll try that! Another quick question that also deals with Vars. If I have a Properties file containing "MYVAR=value1", and in my CookieManager I have this set as the Cookies value --> "${__P(MYVAR)}. When I run the Test its setting the Cookie to **"${__P(MYVAR)}"** instead of setting it to its value of **"value1"**... Can you not use vars or functions in the CookieManager? I'm passing the properties file when running nongui mode but it's still setting it wrong? Any idea why? – Matt Apr 28 '15 at 17:16
  • BTW, that vars.get and vars.put did the trick, thanks AGAIN..!! Any idea about that Cookie thing using the Property File's variable. I am using the double underscore before the P(), so I'm not sure why its not substituting the Variable with the value from the file, and also from setting the variable on the command line with: _"-J MYVAR=value1"_... But same result as not changing the value on the CLI. – Matt Apr 28 '15 at 17:32