1
votes

I am new to gatling scripting. I am trying to execute a performance testing against one of our application's POST api. This POST request API required to pass the form-data.

EG : Print-Screen of the postman collection of the request body

enter image description here

For that I have prepared a gatling code piece as below :

      .exec(http("POST Explore JSON")
        .post("/sunrise/explore_json/")
        .header("Content-Type", "application/x-www-form-urlencoded")
        .header("Referer", "https://example.com/sunrise/dashboard/dummy_dashboard/")
        .header("x-csrftoken", "${csrf_token1}")
        .queryParam("form_data","{\"slice_id\":4}")
      //.formParam("form_data","datasource":"2__table") ----------> Tried Method 1
      //.formParamSeq(Seq(("form_data", "datasource":"2__table")))  ----------> Tried Method 2
      //.formParamMap(Map("form_data" ->  "datasource":"2__table")) ----------> Tried Method 3
      //.form("""form_data={"datasource":"2__table"}""") ----------> Tried Method 4

Unfortunately gatling is not passing the form data as I want,currently how gatling pass the form data is :

form_data: {"datasource":"2__table"}

The way I want to pass is : (Please note I have removed the ":" & the following "space")

form_data={"datasource":"2__table"}

I have tried many many ways, but I could not successfully pass form data as above Is there any way that I can pass as form_data={"datasource":"2__table"} ?

3
Leaving aside the fact that you're mixing request methods by sending a JSON object as form-data, typically this is how form data is sent (key: value). Can you check the console on your Postman to verify that it's being sent as key=value?ramdesh

3 Answers

0
votes

Try this

 .formParam("form_data", "{\"datasource\":\"2__table\"}")
0
votes

I would like to share, how we have fixed this issue,I guess it is another way representing form_data ?

    .exec(http("POST Explore JSON")
       .post("/sunrise/explore_json/")
       .header("Content-Type", "application/x-www-form-urlencoded")   
       .header("Referer","https://example.com/sunrise/dashboard/dummy_dashboard/")
       .header("x-csrftoken", "${csrf_token1}")
       .queryParam("form_data","{\"slice_id\":4}")
       .bodyPart(StringBodyPart("form_data", s"""{"datasource":"2__table"}"""))
       .check(status.is(200))

0
votes

I was facing the same 'problem', you can try to use the '.formParam' after yours request. For more information and examples look this: Gatling Documentation: Form Parameters