Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter : Use a props.get of String array inside a HTTP request

Tags:

jmeter

In my BeanShell PreProcessor of my POST request, I have the below code:

    String[] serversName = new String[]{"FrontEnd", "BackEnd"};
    props.put("serversName",serversName);

Now, in the Body Data of my POST request, I need to call serverNames (let's say, I only need the first element). I tried to call it as below:

{
    "properties": {
        "name": ${props.get(serversName[${serverIndex}])},
        "ram": 1024,
        "cores": 1,
        "cpuFamily": "AMD_OPTERON",
        "availabilityZone": "AUTO"
    }

using ${props.get(serversName[0]) but it complains with BAD Request 400!

When I check my request in the listener, it is as below:

POST data:
{
    "properties": {
        "name": ${props.get(serversName[0])},
        "ram": 1024,
        "cores": 1,
        "cpuFamily": "AMD_OPTERON",
        "availabilityZone": "AUTO"
    }

How to access props variable inside my request?

like image 208
Jeff Avatar asked May 06 '26 07:05

Jeff


1 Answers

You can do it the JMeter's way, by setting Strings ordered with serversName_[sequence_number]

String[] serversName = new String[]{"FrontEnd", "BackEnd"};
for (int i=0; i < serversName.length; i++) {
    props.put("serversName_" + i, serversName[i]);
}

And then just get property ${__P:

${__P(serversName_${serverIndex})}
like image 95
user7294900 Avatar answered May 11 '26 15:05

user7294900



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!