How to use session variable in StringBody of gatling?
I have defined my exec
like,
val migrateAsset = exec(_.set("assetId", AssetIdGenerator.generateRandomAssetId()))
.exec(http("Migrate Asset")
.post(s"$url/asset/metadata")
.header("Content-Type", "application/json")
.header("Authorization", s"Bearer ${authToken}")
.body(StringBody(
s"""
|{
| "objectType" : "DocumentType",
| "fileName" : "main.xml",
| "locations" : [
| {
| "region" : "eu-west-1",
| "url" : "https://s3-eu-west-1.amazonaws.com/${bucketName}/${assetId}"
| },
| {
| "region" : "us-east-1",
| "url" : s"https://s3.amazonaws.com/${bucketName}/${assetId}"
| }
| ],
| "format" : "MAIN",
| "mimeType" : "text/plain"
|}
""".stripMargin
))
.check(status.is(200)))
In the body, I want same assetId
to be passed for both eu-west and us-east regions. Since, assetId is randomly generated, I have stored it in session variable so as to make sure, I use same assetId for both locations.
But I cant pass assetId
in StringBody format. It keeps giving me error like,
AssetsMigrationLoadSimulation.scala:31: not found: value assetId | "url" : "https://s3-eu-west-1.amazonaws.com/${bucketName}/${assetId}"
As Hans-Peter mentioned - your IDE has seen the ${...} that you're using to reference a gatling session parameter and decided that you are trying to do regular scala string interpolation - so it's put the 's' in front of the string.
remove the 's' and this should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With