Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gatling session variable in triple qouted string

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

like image 539
Aditya Avatar asked Aug 04 '17 10:08

Aditya


1 Answers

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

like image 194
James Warr Avatar answered Oct 29 '22 07:10

James Warr