简体   繁体   中英

Unable to evaluate EL while creating Gatling scenario

I am creating scenario with repeat block. As I need index based request to be generated.

def scnWithLoop() = scenario("scenarioName").repeat(counter, "counter") {
    exec (session => {
    val index: Integer = Integer.getInteger(session.attributes.get("counter").get.toString());
    session.set("index", index)
    session
})

exec(
      http("scenarioName")
        .post(contextPath)
        .headers(headers)
        .body(StringBody(getData("${index}".toInt)))
        .check(status.in(expectedCodes))
    ).pause(20 seconds)
}

But this doesn't evaluate EL ${index} and gives me error:

Caused by: java.lang.NumberFormatException: For input string: "${index}"

Gatling Version: 2.0.0-M3a

Appreciate any help!!!

Convenient interpolation of session values like "${index}" works only when the string is implicitly converted to gatling's expression. This dark magic of scala will be broken by something like your expression "${index}".toInt . You will probably have to work with the gatling's session explicitly, as per the session EL documentation :

....

For example, queryParam("latitude", "${latitude}".toInt + 24) won't work, the program will blow on "${latitude}".toInt as this String can't be parsed into an Int.

The solution here would be to pass a function:

session => session("latitude").validate[Int].map(i => i + 24) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM