You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Marc Anthony Winoto <ma...@netregistry.com.au> on 2006/09/26 02:30:57 UTC

How do I use print() with variables?

While trying to reproduce Philip's BeanShell problem, I found some strange behaviour.

HTTP Sampler
|
|-Regex: test, (the), $1$, 1, "fout"
|
BeanShell PostProcessor or PreProcessor: print(${test}); or print(""+${test});
|
|
HTTP Sampler: go to http://${test}

The bean shell never got a value for test. I can print out hardcoded strings and predefined 
variables though.

The 2nd HTTP sampler does get a correct value from the test variable and tries to go to 
http://the (and fails).

I also tried putting the beanshell as a child of the first http sampler. Nothing. What's going on?

Marc

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How do I use print() with variables?

Posted by sebb <se...@gmail.com>.
On 26/09/06, Marc Anthony Winoto <ma...@netregistry.com.au> wrote:
> While trying to reproduce Philip's BeanShell problem, I found some strange behaviour.
>
> HTTP Sampler
> |
> |-Regex: test, (the), $1$, 1, "fout"
> |
> BeanShell PostProcessor or PreProcessor: print(${test}); or print(""+${test});

This would be interpreted as

print(the); or print(""+the);

which is not valid unless you define the BeanShell variable "the".

JMeter variables are replaced *before* the script is passed to Beanshell.

To print a JMeter variable in BeanShell, you need to use:

print("${VAR}"); or print(vars.get("VAR"));

> |
> |
> HTTP Sampler: go to http://${test}
>
> The bean shell never got a value for test. I can print out hardcoded strings and predefined
> variables though.
>
> The 2nd HTTP sampler does get a correct value from the test variable and tries to go to
> http://the (and fails).
>
> I also tried putting the beanshell as a child of the first http sampler. Nothing. What's going on?

See also other thread - Post-Processors are run in reverse order
(don't know why yet).

>
> Marc
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org