0
votes

I'm trying to extract a security_token from this response :

{}&&{"containers":{"userID":"p8admin","connected":true,"desktop":"icm"},
     "userid":"p8admin",
     "user_displayname": "p8admin",
     "security_token":"-1829880900612241155",
     "messages":[{"adminResponse":null,
                  "moreInformation":null,
                  "explanation":null,
                  "number":"0",
                  "userResponse":null,
                  "text":"p8admin connect\u00e9."
                 }]
     }

I've tried combining transform and jsonPath :

.check(bodyString.transform(_.split("&&")(1)).jsonPath("&.security_token").saveAs("security_token"))

but i get this error :

value jsonPath is not a member of com.excilys.ebi.gatling.core.check.MatcherCheckBuilder

Let me know if there is a simple way to achieve this.

Thanks

2

2 Answers

0
votes

From the documentation on checks:

This API provides a dedicated DSL for chaining the following steps:

  1. defining the check
  2. extracting
  3. transforming
  4. verifying
  5. saving

Since the response isn't valid JSON, you'll need to use bodyString as the type. You can then transform and then save, but you can't go back to step 1. You can parse the value you need out of the JSON during the transform step.

As Stéphane pointed out, the easiest way to get the value is to use a regex check and extract the security_token value directly, as long as you don't need the rest of your JSON object for any logic.

0
votes

I have the same problem, I used the regex() function like this :

.check(regex(""""security_token":"(.*)",""").saveAs("security_token"))