问题
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