How to use xpath extractor conditionally in Jmeter?

50 views Asked by At

I have a jmx file in which there is an HTTP request inside which there are XPath Extractors and JSR223 sampler. I want to trigger the XPath Extractors and JSR223 sampler only if the HTTP request is a success. As whenever the HTTP request fails in can see errors in JMeter command prompt Sample of How the scripts looks like The error

1

There are 1 answers

1
Dmitri T On

Unfortunately there is no way to execute Post-Processors conditionally, they are always executed after each Sampler in their scope.

For the JSR223 PostProcessor you can add a clause like:

if (prev.isSuccessful()) {
    //your code here
}

where prev stands for previous SampleResult, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands which are available for the JSR223 Test Elements

also be aware that Groovy has certain XML processing capabilities so you might want to move your extraction logic into the JSR223 PostProcessor.