Using feeders to construct a StringBody (2.0.0-M3a)

Okay, I’ve got another feeder/http POST body question. Thank you for all of your help so far - Gatling is an awesome tool, and I feel like I’m so close to getting it to work for our project.

I’m continuing to work on my registration load test, and now I’m running into the following issue when attempting to use a feeder to generate my JSON POST body - some lines don’t seem to be correctly handling double quotes in my CSV file. (Of three requests, one worked, two mysteriously didn’t.)

Relevant script pieces:
val userData = csv(“test.csv”).queue

val httpConf = http.baseURL(“http://myappurl.com/api”)

val scn = scenario(“Register user”)
.feed(userData)
.exec(
http(“POST registration”)
.post("/user/register")
.headers(headers_1)
.body(StringBody("""{“username”:${username}, “email”:${email}, “imei”:${imei}, “gcmId”:${gcmId}, “age”:${age},“albumSelection”:${albumSelection},“latitude”:${latitude},“longitude”:${longitude},“emailOptIn”:${emailOptIn},“termsOptIn”:${termsOptIn} }""")))

My CSV file looks like this:

username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email
““tester7105408553"",true,"“clean”",false,"“62"”,"“7105408553"”,0,45,"“999997105408553"”,""tester7105408553@mailinator.com””
““tester7317165156"",true,"“clean”",true,"“59"”,"“7317165156"”,176,65,"“999997317165156"”,""tester7317165156@mailinator.com””
““tester6271383680"",true,"“explicit”",true,"“37"”,"“6271383680"”,-42,-82,"“999996271383680"”,""tester6271383680@mailinator.com””

It seems like everything is correct there, but when I run with logging turned on, I see the following messages:

Session:
Session(Register user,1,Map(latitude → 65, email → “tester7317165156@mailinator.com”, username → tester7317165156", imei → “999997317165156”, age → “59”, longitude → 176, termsOptIn → true, emailOptIn → true, gcmId → “7317165156”, albumSelection → “clean”),1382385464346,0,List(),List(KO),List(),List())

Hi,

Except if gmail did something funny with your original message, it seems your csv file is still messed up: double quotes inside a field have to be escape, and the whole field has to be surrounded with double quotes:

  • "“tester7105408553"” => bad
  • "“tester7105408553"” => good
    We use opencsv underneath, and it silently does weird stuff with malformed csv.

Anyway, why don’t you handle JSON string value quotes inside your JSON template?

You csv file would look like:

username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email
tester7105408553,true,clean,false,62,7105408553,0,45,999997105408553,tester7105408553@mailinator.com

and your template like this:
“”"{
“username”:"${username}",
“email”:"${email}",
“imei”:"${imei}",
“gcmId”:"${gcmId}",
“age”:"${age}",
“albumSelection”:"${albumSelection}",
“latitude”:${latitude},
“longitude”:${longitude},
“emailOptIn”:${emailOptIn},
“termsOptIn”:${termsOptIn}
}"""

WDYT?

That totally did the trick - I based the “double double quotes” off of some random CSV documentation I found, but your solution is better and more elegant, and works, to boot.

Thanks again for the prompt responses, much appreciated.

Thanks,
Hank

Was glad to help :slight_smile:

Have fun!