You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by guo weizhan <gu...@gmail.com> on 2011/11/10 09:55:15 UTC

How to get user defined variables in test plan by java API?

I try to write a java request by extends AbstractJavaSamplerClient,
but I don't know how to get user defined variables in test plan by
java API, can you tell me how?

Thank you!

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


Re: How to get user defined variables in test plan by java API?

Posted by guo weizhan <gu...@gmail.com>.
I try to use the thread context but it can't get the test plan
variables, but it can  get user defiend variables by ${port}.

Thank you for your help.

2011/11/10 Bruce Ide <fl...@gmail.com>:
> In my sampler I'm getting a JMeterThreadContext and then getting the
> variables hash from that;
>
> JMeterContext context = getThreadContext();
> JMeterVariables vars = context.getVariables();
>
>
> Then you can just use vars.put as you would inside a beanshell sampler
>
> vars.put("foo", "bar");
>
> You can also put object references into variables. You can browse any of my
> source online at https://github.com/FlyingRhenquest if you need concrete
> examples. Or just dig around in the JMeter source code (That's what I did
> :-)
>
> --
> Bruce Ide
> FlyingRhenquest@gmail.com
>

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


Re: How to get user defined variables in test plan by java API?

Posted by Bruce Ide <fl...@gmail.com>.
In my sampler I'm getting a JMeterThreadContext and then getting the
variables hash from that;

JMeterContext context = getThreadContext();
JMeterVariables vars = context.getVariables();


Then you can just use vars.put as you would inside a beanshell sampler

vars.put("foo", "bar");

You can also put object references into variables. You can browse any of my
source online at https://github.com/FlyingRhenquest if you need concrete
examples. Or just dig around in the JMeter source code (That's what I did
:-)

-- 
Bruce Ide
FlyingRhenquest@gmail.com