user187205
user187205

Reputation: 330

JMeter simple BeanShell PreProcessor

I'm new to JMeter BeanShell PreProcessor function.

For a test I'm trying to print sample URL address. From the tutorial I have the follownig code:

org.apache.jmeter.samplers.SampleResult;

String currentURL = SampleResult.getUrlAsString();
print(currentURL)

But I get error "Attempt to resolve method: getUrlAsString() on undefined variable", how to define this variable first?

Upvotes: 2

Views: 456

Answers (2)

Dmitri T
Dmitri T

Reputation: 168002

  1. Be aware that since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language for any form of scripting in JMeter tests. So consider migrating to Groovy as soon as possible.
  2. If you are using a PreProcessor it means that you don't have any SampleResult as sampler has not been yet executed. So you need to use sampler shorthand which is resolved into HTTPSamplerProxy like:

    sampler.getUrl() as String
    

Demo:

JMeter Get Current Sampler URL

More information: Apache Groovy - Why and How You Should Use It

Upvotes: 0

pmpm
pmpm

Reputation: 705

This means the SampleResult does not exist.

You need to use prev as per this doc:

Which references this javadoc:

Upvotes: 1

Related Questions