Mercy
Mercy

Reputation: 171

How to get a value from user properties inside java request sampler code

I want to access a value from the user properties which is in jmeter/bin form java request sampler. I could find no method in the JavaSamplerContext. Any help appreciated.

Upvotes: 4

Views: 1567

Answers (2)

Steve Gelman
Steve Gelman

Reputation: 932

I just came across this problem, using JMeter, version 3.2, and the Lazery Maven JMeter plugin, version 2.2.0. This is a really nice plugin, by the way.

I had custom properties defined in my POM.xml file, one being:

<propertiesUser>
    <integration.environment>
        ${integration.environment}
    </integration.environment>
</propertiesUser>

I used the following code in a Java Sampler extending AbstractJavaSamplerClient. In the runTest method, I did this:

JMeterVariables variables = JMeterContextService.getContext().getVariables();
String intEnv = variables.get("integration.environment");

Is there a better way?

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168197

JMeterContext is your friend

How about

JMeterContextService.getContext().getCurrentSampler().getProperty("property.name.here");

See here and here for example usage of JMeter API.

Upvotes: 2

Related Questions