Jmeter - How to assign multiple dynamic values to a variables inside a loop

vlatko606

I have loop like

for (int i = 1; i <= 12; i++) {
    log.warn("opponentA: " + vars.get("ID1_" + i).split(" - ")[0]);
    log.warn("opponentB: " + vars.get("ID1_" + i).split(" - ")[1]);
}

which produces values like:

2021-06-08 11:01:51,649 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: France
2021-06-08 11:01:51,649 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Bulgaria
2021-06-08 11:01:51,649 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Poland
2021-06-08 11:01:51,649 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Iceland
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Senegal
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Cape Verde
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Czech Republic
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Albania
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Hungary
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Republic of Ireland
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Morocco
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Ghana
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Kosovo (FIFA APPR.) U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Andorra U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Sweden U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Luxembourg U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Faroe Islands U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Armenia U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Austria U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Estonia U21
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Ecuador
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Peru
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentA: Baderan Tehran
2021-06-08 11:01:51,650 WARN o.a.j.e.J.JSR223 PostProcessor: opponentB: Esteghlal Mollasani

When I try to assign value so I can use multiple dynamic variables, as

for (int i = 1; i <= 12; i++) {
    vars.put("opponentA" + (i + 1), vars.get("ID1_" + i).split(" - ")[0]);
    vars.put("opponentB" + (i + 1), vars.get("ID1_" + i).split(" - ")[1]);

    log.warn(vars.get("opponentA1"));
    log.warn(vars.get("opponentB1"));
}

I got null.

How to fix this, so I can use multiple dynamic variables as:

opponentA1, opponentA2...opponentA20
Dmitri T

Change this:

vars.put("opponentA" + (i + 1)...

to this:

vars.put("opponentA" + i...

as your loop starts with 1 so then you increment the value by 1 you're getting variables like opponentA2, opponentB2, opponentA3, etc.

You can always check which variables are being generated using Debug Sampler and View Results Tree listener combination

It also worth checking jmeter.log file for any suspicious entries indicating your JSR223 PostProcessor's failure

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to assign multiple localstorage variables inside a loop?

How to create multiple variables in a loop and assign values in VBA

How to assign dynamic variables in a for loop in python

how to assign numerical values to variables inside a product?

How to assign multiple DataFrame variables using a for loop?

How can I dynamically assign multiple values returned from a response to variables in Apache jmeter? (number of elements in array may vary)

How to assign multiple variables in a loop for graphs in Python 3

How to declare dynamic variables inside FOR loop in OR-TOOLS

Assign value to Dynamic variable inside While Loop

How to assign values to multiple variables in command line with bars

How to assign multiple variables different values using one function in Javascript

Shell : create and assign variables inside for loop

Execute dynamic query and assign values into two variables

Create multiple variables inside for loop

Using variables in a for loop to assign legend values in pyplot

Create variables and assign values via loop (bash)

More efficient way to assign multiple variables in a FOR loop?

How to replace outliers with values inside the IQR for multiple variables and individuals

how to read multiple variables values inside html tag in python

Create dynamic scope variables in AngularJs inside loop

Dynamic created variables inside for loop, Javascript

Loop inside loop using multiple variables

Can't assign multiple values to 3 variables

Javascript. Assign array values to multiple variables?

jmeter - how to access dynamic array of variables in scripting?

In JMeter how do I set multiple dynamic variables in User Parameters or CSV Data Set Config

How to assign values to environment variables with dynamic name while parsing similar named XML elements?

assign multiple values to object property with for loop

How to assign variables using dynamic sql