Gatling:在 .check(regex
Gatling: Extracting multiple groups in .check(regex
我正在尝试使用单个 .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)
gatling EL 支持元组,因此您可以使用像
这样的调用
"${description._1}"
访问产品,例如
要获取该值以便在除采用表达式的 dsl 调用之外的其他地方使用它,您可以在会话操作中检索它(您不能使用 EL)
exec(session => {
println(session("description").as[(String, String, String)]._1)
session
})
我正在尝试使用单个 .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)
gatling EL 支持元组,因此您可以使用像
这样的调用"${description._1}"
访问产品,例如
要获取该值以便在除采用表达式的 dsl 调用之外的其他地方使用它,您可以在会话操作中检索它(您不能使用 EL)
exec(session => {
println(session("description").as[(String, String, String)]._1)
session
})