Gatling:如何更改保存的整数值
Gatling: How to change saved integer value
Gatling:如何更改保存的整数值
我将获取元素的数量保存为整数值。
val getElements = exec(http("1. get_elements")
.get("/apis/;version=0/elements/items?")
.check(jsonPath("$.totalElements").ofType[Int].saveAs("total_elements"))
.check(status.is(200))
.headers(headers_common))
但是我不能在另一个函数中修改这个值,例如:
.repeat("${total_elements}" / 100){
.....
}
Warning
This Expression Language only works on String values being passed to
Gatling DSL methods. Such Strings are parsed only once, when the
Gatling simulation is being instantiated.
For example queryParam("latitude", session => "${latitude}") wouldn’t
work because the parameter is not a String, but a function that
returns a String.
Also, queryParam("latitude", "${latitude}".toInt) wouldn’t because the
toInt would happen before passing the parameter to the queryParam
method.
The solution here would be to pass a function:
因此您必须在要使用 Session API 的地方传递一个函数。
在你的情况下:
repeat(session => session("total_elements").as[Int] / 100) { ... }
Gatling:如何更改保存的整数值
我将获取元素的数量保存为整数值。
val getElements = exec(http("1. get_elements")
.get("/apis/;version=0/elements/items?")
.check(jsonPath("$.totalElements").ofType[Int].saveAs("total_elements"))
.check(status.is(200))
.headers(headers_common))
但是我不能在另一个函数中修改这个值,例如:
.repeat("${total_elements}" / 100){
.....
}
Warning
This Expression Language only works on String values being passed to Gatling DSL methods. Such Strings are parsed only once, when the Gatling simulation is being instantiated.
For example queryParam("latitude", session => "${latitude}") wouldn’t work because the parameter is not a String, but a function that returns a String.
Also, queryParam("latitude", "${latitude}".toInt) wouldn’t because the toInt would happen before passing the parameter to the queryParam method.
The solution here would be to pass a function:
因此您必须在要使用 Session API 的地方传递一个函数。 在你的情况下:
repeat(session => session("total_elements").as[Int] / 100) { ... }