0

I have a loop controller in my test plan with a counter called fileNumber.

Counter fileNumber

I also have a groovy script which fetches keys and uploadIds from the response of an API call. This is the script I have:

def uploadId = vars.get("uploadId");
def fileKey = vars.get("key");
def fileNumber = vars.get("fileNumber");

if (!uploadId.isEmpty() && !fileKey.isEmpty()) {
    vars.put("key_" + fileNumber, fileKey);
    vars.put("uploadId_" + fileNumber, uploadId);
}

I expected this to create variables for key as key_1, key_2...key_5. What I get, is that key_1 is stored correctly in the first call of the API in the loop:

value for key_1

But in the 2nd to 5th iterations of the loop, the variables for the 2nd to 5th values are stored.

value for key_2 to key_5

The variable key_1 is not set at all.

When I give the start value as 0 and maximum value as 4, then I get key_0, key_2, key_3, key_4. But still no key_1

Why is this happening?

When I changed the variable name to fileKey, it worked. I'm assuming it's because key_1 is saved somewhere but I have not defined key_1 as a variable elsewhere

1 Answer 1

0

You have this condition:

if (!uploadId.isEmpty() && !fileKey.isEmpty()) {

please check the values of the given variables, it might be the case one of them is not set.

Use Debug Sampler to see which variables are defined in each loop.

Also it is not required to define the counter, Loop Controller has built-in counter and exposes variable called __jm__Loop Controller__idx which holds current iteration number

Sign up to request clarification or add additional context in comments.

1 Comment

I added logging statements to verify if the condition returns true and it does. The debug sampler also showed that uploadId and fileKey values were not empty strings or null.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.