How to pass the Count Integer variable captured from a response to .repeat function

Hi ,

I am trying to make the following work but it is just not recognizing integer of “VARIABLE_count” string in .repeat. Kindly help.

I have captured the count of similar occurring products (same boundaries) from the response using the following statement,


Now I am trying convert “VARIABLE_count” to an Integer and passing it to repeat statement but it is giving a compilation error. Kindly help me identify this issue as what could be wrong and what needs to be changed to use this VARIABLE_Count in repeat statement.

val scn = scenario(“CategorySel”)



.check(regex(" | Woolworths").exists)


.exec(session => {
val counter = session(“VARIABLE_count”).as[Int]
// Get person_ids and convert to List of Int
val Products = session(“VARIABLE”).as[List[Int]]
// Get random personId from personIds List, count of firstNames should be the same as count of ids
// Explicit conversion toString is needed and then get Int value with toInt
val Prod = Products(Random.nextInt(counter)).toString.toInt
// Set personId in session and return it
// Note: if you return ‘session’ old object will be returned and new attribute will be missing
session.set(“Product_ID”, Prod)

Tried following repeat conditions,

.repeat(session(“VARIABLE_count”).as[Int]) -----------This does not work
.repeat(session => {session(“VARIABLE_count”).as[Int]}) ---- Even this does not work
.repeat(counter) ---- obviously this doesnt work saying counter value not found…
exec("----some Request which repeats the “VARIABLE_count” times")


Hi ,

Can anyone help me or suggest a solution for this problem? If you think there is no possible solution pls let me know. So i can think of some alternatives.


Check your syntax

Thanks Vu Nguyen, it works now.