简体   繁体   中英

Parse the response string of a request into another method in gatling

I'm trying to parse a response header value (which is a string) of one request into another method or function in gatling. Here is what I tried

val scn = scenario("DeviceAuth")
.feed(csvFeeeder)
.exec(http("Request1")
  .post("endpoint")
  .headers(headers_0)
  .formParam("key", "value")
  .check(headerRegex("header","pattern.*)").saveAs("value"))
  .check(status.is(401)))
object getHeader{
def authenticationHeader: String = {
val header: String = "${value}"
val s = header.split("")
     --so on and so forth--
}
}

So, when I tried to print the header value, it's just printed "${value}. How can we pass that value into my function?

Please try this solution

val scn = scenario("DeviceAuth")
.feed(csvFeeeder)
.exec(http("Request1")
  .post("endpoint")
  .headers(headers_0)
  .formParam("key", "value")
  .check(headerRegex("header","pattern.*)").saveAs(value))
  .check(status.is(401)))
object getHeader{
def authenticationHeader: String = {
val header: String = `$value`
val s = header.split("")
     --so on and so forth--
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM