Cannot pass attribute name in ElFileBody

Cannot pass attribute name in ElFileBody

val writeTestIDs_writer = {
val fos = new java.io.FileOutputStream(“Test_writer.csv”)
new java.io.PrintWriter(fos, true)
}

.foreach("#{TestIDs}", "TesterID") {
  exec(
    http("Testing API")
      .post("/testing")
      .body(ElFileBody(session =>
        s"""{
           |"id": "",
           |"TypeId": "000000004532-0000-3421-121212",
           |"legs":[{
           |      "RateTypeId": "030000004532-0000-3421-124444",
           |      "testerID": "${TesterID}" // Error :  Cannot resolve symbol AssetID
           |    }]
       }""".stripMargin)).asJson
      .check(jsonPath("$.id").saveAs("resultID"))
      .check(status.is(201)))
  .exec(session => {
    writeTestIDs_writer.println(session("resultID").as[String])
    session
  })
 }

Please help me with a solution

Why are you passing a function to ElFileBody?

  • you don’t need it as you don’t use the session parameter
  • you can’t use Gatling EL inside functions as previously explained

Also, you’re confusing Scala String interpolation (prefixed with s) and Gatling Expression Language (now using #{} so there’s no confusion).

.body(ElFileBody(
        """{
           |"id": "",
           |"TypeId": "000000004532-0000-3421-121212",
           |"legs":[{
           |      "RateTypeId": "030000004532-0000-3421-124444",
           |      "testerID": "#{TesterID}"
           |    }]
       }""".stripMargin))
1 Like

Thank you for the clear explanation & solution