Jmeter - Creating a new variable if variable already exists using Java -
i'm using jmeter , want use java update variables,
i have variable called xxvono stores values , adds number suffix when executed in loop. example:
xxvono_1 = value1 xxvono_2 = value2 xxvono_3 = value3
these variables contains values automatically stored when loop executed. however, trying make code checks if variable empty or not, if true, save new values, if false, create new variable (xxvono_4) , save value there without overwriting existing variables.
how go doing this? use while loop?
if (vars.get("vono_2") != "") { if (vars.get("xxvono_" + vars.get("aps200_count_3")) == "") { vars.put("xxvono_" + vars.get("aps200_count_3"), vars.get("vono_2")); vars.put("xxjrno_" + vars.get("aps200_count_3"), vars.get("jrno_2")); } else { while (vars.get("xxvono_" + vars.get("aps200_count_3")) != "") { vars.put("new_count", vars.get("aps200_count_3")); integer temp = integer.parseint(vars.get("new_count")) + 1; vars.put("new_count", temp.tostring()); } vars.put("xxvono_" + vars.get("new_count"), vars.get("vono_2")); vars.put("xxjrno_" + vars.get("new_count"), vars.get("jrno_2")); } }
you can try using map instead of creating variables @ runtime
map<string,object> map = new hashmap<>();
inside loop
if(map.get("dynamicvariablename")!=null){ map.put("dynamicvariablename"+autogeneratednumbersuffix,valuetobestored) } else{ map.put("dynamicvariablename",valuetobestored) }
Comments
Post a Comment