Rectangle 27 1

I would recommend use Groovy instead of Beanshell as:

  • Well-behaved Groovy scripts can be compiled into bytecode therefore performance will be much higher

So given you have JSON Response like:

  "elements": [
      "id": 123456,
      "name": "TEST"
      "id": 7890,
      "name": "TEST2"

You can extract random ID along with its index using the following example Groovy code in the JSR223 PostProcessor:

import groovy.json.JsonSlurper

import java.util.concurrent.ThreadLocalRandom

String response = prev.getResponseDataAsString()

def jsonSlurper = new JsonSlurper()
def json = jsonSlurper.parseText(response)

int size = json.elements.size

if (size > 0){
    def randomIndex = ThreadLocalRandom.current().nextInt(size)
    def value = json.elements.get(randomIndex).id'Index: ' + randomIndex)'Value: ' + value)

jsonpath - Obtain index of random element from json array in JMeter Js...

jmeter jsonpath
Rectangle 27 0

I wouldn't recommend using Beanshell as it has known performance problems so consider switching to JSR223 Test Elements and Groovy language.

The relevant groovy code you can use in JSR223 PreProcessor or JSR223 PostProcessor would be something like:

def url = sampler.getUrl();

def protocol = url.getProtocol()
def host = url.getHost()
def path = url.getPath()'Full URL: ' + url.toString())'URL you want: ' + protocol + '://' + host + path)

Thanks Dmitri. But this will again gives the current path. I actually want the path before replacing the jmeter variables.

Jmeter http path value finder using beanshell - Stack Overflow

jmeter beanshell
Rectangle 27 0

Well-behaved JMeter test should be able to loop single user without any problem, most likely you have a problem with your test design or mismatch with the application under test behaviour. General recommendation would look like:

First of all switch to iterations on Thread Group level, JMeter configuration elements don't respect iterations originated from elsewhere as "iterations"

  • Inspect request and response details, identify missing/extra/different parameters and fix them. See How to Debug your Apache JMeter Script for more details on JMeter test troubleshooting techniques.

Blind shot: your test includes login request and the virtual user is already logged in therefore it doesn't require login on 2nd loop. In this case you have 2 options:

Clear cookies each iteration

adding Iterations to the Loop count at the Thread Group Level instead of having Loop controller in the Thread Group, has increased the failures

Running Jmeter for Https app with single user for multiple times throu...

Rectangle 27 0


Remember that using Beanshell for scripting is not recommended, starting from JMeter 3.1 users are encouraged to switch to JSR223 Test Elements and Groovy language, check out Apache Groovy - Why and How You Should Use It for details.

Thanks for the info. These methods sadly do not work as it still performs the main sampler. I have not tried System.exit(1); yet, does this shut down my entire system or just the JMeter instance? I did not know the JSR223 thing yet, will definatly look into that! Thanks!

It shuts down JVM instance. Immediately. As a side effect you may loose results which are kept in memory and not still written to the .jtl file. If you will go this way make sure you set property somehow, see Configuring JMeter and/or Apache JMeter Properties Customization Guide] to learn about the ways of setting it.

Thanks! System.exit(1); works, though I would prefer a solution where the main sampler just does not get executed based on results from the preProcessor. But apparently that is not possible. Thanks for the info though and pointing out the JSR223.

java - Stop JMeter test in Beanshell PreProcessor - Stack Overflow

java jmeter preprocessor beanshell
Rectangle 27 0

I would recommend implementing your scenario using JSR223 PostProcessor and Groovy language. Example code to extract the elements and build a new JSON out of the filtered data will look something like:

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

def json = new JsonSlurper().parseText(prev.getResponseDataAsString())

def fictionBooks = {it.category == "fiction"}
def redBikes ={it.color="red"}

JsonBuilder builder = new JsonBuilder(fictionBooks + redBikes)


The above code will replace the parent sampler response data with the filtered JSON

How to join two json path query in json path extractor of jmeter? - St...

json jmeter jsonpath