Unable to evaluate EL while creating Gatling scenario

血红的双手。 提交于 2019-12-12 02:16:07

问题


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!!!


回答1:


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).



来源:https://stackoverflow.com/questions/37430417/unable-to-evaluate-el-while-creating-gatling-scenario

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!