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?
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})}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With