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}"