【发布时间】:2019-06-26 13:03:33
【问题描述】:
我尝试使用单个 .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 scala-gatling