Chain scenarios not running in Sequence

I’m writing a performance test with the following steps :

  • Upload a file, and from the response save the “fileID” in a separate JSON file to be used later to download the file
  • Download the file by feeding the JSON created in the previous step as RawFileBody as body of the request and passing it in the download url
    Both these have to be run in a sequence one after the other

Code as follows :

val uploadFile: ChainBuilder = exec(http("Upload a File to be downloaded later")
  .post("/file") // end-point to be load tested
  .header("username", "abc") // user-name header
  .header("password", "xyz") // password header
  .formUpload("file", testFile1MB) // body params ("key" , "path of the file/name")
  .formParamSeq(Seq(("uploadByID", "1"), ("location", "meetings"), ("personID", "0"), (
  "uploadTimeStamp", "2019-01-15 10:01:04.426"), ("md5Hash", md5Hash1Mb))) // other body params ("key", "value")
  .check( // check assertion for status code
  .exec { session =>
     fileGuid = session("guid").as[String].trim
    if (downlGuidJsonFile.exists()) {
    val guidWriter = new PrintWriter(new FileOutputStream(new File(downloadGuidFilePath), true))
    guidWriter.write("{" + "\"" + "uuid" + "\"" + ":" + "\"" + fileGuid + "\"" + "}")

If you pass a hardcoded file path for the request body, Gatling will try to load it on startup.
In your scenario implementation, this crashes because the file is not there yet.
Don’t pass a hardcoded path, pass a function instead so file is evaluated lazily.