本文介绍了创建加特林场景时无法评估EL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建带有重复块的场景.因为我需要生成基于索引的请求.

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

但这不会评估EL $ {index}并给我错误:

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

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

加特林版本:2.0.0-M3a

Gatling Version: 2.0.0-M3a

感谢任何帮助!

推荐答案

"${index}"这样的会话值的便捷插值仅在将字符串隐式转换为加特林表达式时有效. Scala的这种黑魔法将被表达式"${index}".toInt破坏.您可能必须根据会话EL文档:

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 :

例如,queryParam("latitude", "${latitude}".toInt + 24)不会 工作时,程序将在"${latitude}".toInt上吹响,因为此字符串 无法解析为Int.

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

这篇关于创建加特林场景时无法评估EL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 13:19