2

I'am try to use single .check(regex to extract multiple values. Code below represent extracting 3 groups.

 val goToProduct = http("""GoTo_${product}""")
.get("""${product}""")
.headers(headers_0)
.check(regex("""name="([\s\S]+?)" value="(.+)" id="(.+)"""").ofType[(String,String,String)].saveAs("description")

After this I'am trying to use extracted values separately (e.g. description._1 as Tuple3, or description(1) as Collection). But it's always fails.

This works, but maybe there is more convenient way to do this (like 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)

Trying this

.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

This line

println(session("description").as[String])

Shows Tuple3: (addtocart_37.EnteredQuantity,1,/addproducttocart/details/37/1)

1 Answers1

1

the gatling EL supports tuples so you can use calls like

"${description._1}"

to access the product, for example

To get the value in order to use it somewhere other than in a dsl call that takes an Expression, you can just retrieve it in a session action (where you can't use EL)

exec(session => {
  println(session("description").as[(String, String, String)]._1)
  session
})
James Warr
  • 2,552
  • 2
  • 7
  • 20
  • I'am trying print this value to the console. Will this work for passing it as a value (e.g. .get("${description._1}") ?? Because in console it shows error (I've edited the question). – Nickolay Averyanov Jun 27 '19 at 08:56
  • updated answer - you were close. Because the gatling session is a Map(String->Any) you need to specify that you're pulling out a tuple before you can use the ._1 syntax – James Warr Jun 27 '19 at 11:05
  • Thanks. I was wondering why, when I print "description" it print me 3 values in (). Now I see. – Nickolay Averyanov Jun 28 '19 at 06:55