我尝试使用单个.check(regex提取多个值。下面的代码表示提取3个组。
val goToProduct = http("""GoTo_${product}""")
.get("""${product}""")
.headers(headers_0)
.check(regex("""name="([\s\S]+?)" value="(.+)" id="(.+)"""").ofType[(String,String,String)].saveAs("description")
此后,我尝试分别使用提取的值(例如,description._1作为Tuple3,或者description(1)作为Collection)。但它总是失败。
这可行,但是也许有更方便的方法(例如val._1)
session("description").validate[(String, String, String)].map { case
(prod_name, prod_value, prod_id) =>
session.setAll("prod_name" -> prod_name, "prod_value" -> prod_value,
"prod_id" -> prod_id)
尝试一下
.exec { session =>
println(session("${description._1}").as[String])
session }
Will give an error: 'hook-1' crashed with 'j.u.NoSuchElementException: No attribute named '${description._1}' is defined', forwarding to the next one
此行
println(session("description").as[String])
Shows Tuple3: (addtocart_37.EnteredQuantity,1,/addproducttocart/details/37/1)
答案 0 :(得分:0)
Gatling EL支持元组,因此您可以使用类似的调用
"${description._1}"
例如,访问产品
要获取值以便在使用表达式的dsl调用之外的其他地方使用它,您可以在会话操作(不能使用EL的情况下)中检索它
exec(session => {
println(session("description").as[(String, String, String)]._1)
session
})