简体   繁体   中英

How can I access JMeter variables inside a custom java sampler?

I have a java sampler that extends AbstractJavaSamplerClient. I would like to access the thread group loop counter value {__counter} from inside the java sampler. How can I achieve this?

ctx.getParameter("{__counter}"); doesn't seem to work where ctx is JavaSamplerContext

Thanks in advance.

__counter is a buildin function and not a parameter.

I would suggest to use it in one of the Pre-Processors such as User Parameters and store the returned value to parameter counterValue . Then you can get the value in your java sampler with ctx.getParameter("counterValue");

I believe that ctx.getVariables().get("{__counter}"); is what you're looking for.

See JavaDoc on JMeterContext ( ctx is a shorthand for JMeterContext).

There is also some useful information on using JMeter API for different purposes in How to use BeanShell: JMeter's favorite built-in component guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM