Did not write csv file

When the test result is successful, was written resp to the CSV file
When getting the Connection time-out error was not written resp to the CSV file

How can I do this?

val scn = scenario("load test")
    .feed(myFeederFirst)
    .exec(http("request")
      .post("/api/")
      .headers(headers_0)
      .body(StringBody(
        s"""{"amount":"$amount","currency":"$currency","trId":"$trId"}""".stripMargin)).asJson
     
      .check(bodyString.saveAs("resp"))
      .check(jsonPath("$.message").saveAs("message"))
      .check(jsonPath("$.id").saveAs("id"))
      .check(jsonPath("$.code").saveAs("code"))

      .check(status.is(200))
      .check(jsonPath("$.message").is("Success"))
      .check(jsonPath("$.code").is("1000"))
    )
    .exec(session => {
      response_writer.println(session("resp").as[String])
      
      if (session("code").as[String].contains("1000") && session("message").as[String].contains("Success")) {
        response_writer2.println("code = " + session("code").as[String] + ",id = " + session("id").as[String] + ",message = " + session("message").as[String] + ",retult = Passed")
      } else {
        response_writer2.println("code = " + session("code").as[String] + ",id = " + session("id").as[String] + ",message = " + session("message").as[String] + ",retult = Failed")
      }
      session
    })

Hi @Ehtimad,

I’m not sure to understand your question.

I assume you want a way to write in your response_writer or response_writer2 only when the previous request didn’t fail. Am I correct?

In that case, you can use a condition statement based on session state

Or if you don’t need to do anything with that virtual user anymore: exitHereIfFailed before the writing exec.

Cheers!

Hello
I want to write every request

For example
I write
if code =1000 result=success else result=Failed
Written to the CSV file as this
code = 1000,id = 790726e615ed,message = Success,result = Passed
OR
code = 1000,id = 790726e615ed,message = Success,result = Failed

When I run the test and when I get the “Connection time-out” error
Written nothing

I want to write a response to the CSV file.
“Connection time-out”

How do I do it?