How to use feeder to parameterize a request body before posting it?

Hi,

I’m getting an issue while posting a Json with variables using feeder.

I have a text file AuthenticateBody.txt in the bodies folder:

{“type”:“user”,“user”:{“id”:2,“username”:"${Param_Username}",“password”:"${Param_Password}",“password2”:"${Param_Password}",“email”:"${Param_Username}",“language”:“EN”,“jurisdiction”:null,“url”:null}}

and a csv file in data folder named Param_WebUserCredentials_Grp1.dat:

Param_Username,Param_Password
xyz@xyz.com,password123
abc@abc.com,password123

I’m trying to post this text file and my script looks like this:

val Param_WebUserCredentials_Grp1=csv(“Param_WebUserCredentials_Grp1.dat”).circular

object LoginPage
{
val headers_1 = Map(
“Content-Type” → “application/json; charset=UTF-8”,
“Pragma” → “no-cache”,
“PreferredLangugae” → “EN”,
“Public” → “false”)

val headers_2 = Map(“PreferredLangugae” → “EN”)

val loginPage=exec(http(“authenticate”)
.post("/frontend/loginService/authenticate")
.pause(1)
.feed(Param_WebUserCredentials_Grp1)
.headers(headers_1)
.body(RawFileBody(“AuthenticateBody.txt”))
.check(/regex(""“userAccount”:"(.?)",""").find.saveAs(“Corr_UserAcc”),/
regex(""“token”:"(.
?)",""").find.saveAs(“Corr_token”))
.check(substring(""“success”:true""").find.exists)//check for authentication
.resources(http(“homeCA.html”)
.get("/modules/home/views/homeCA.html")
.headers(headers_2)
.check(regex(""“Authorization: (.?)\n""").saveAs(“Corr_token”),
regex("""UserAccount: (.
?)\n”"").saveAs(“Corr_UserAcc”)),
http(“fetchAuctionDetails”)
.post("/frontend/home/fetchAuctionDetails")
.headers(headers_1)
.body(RawFileBody(“FetchAuctionDetails.txt”)),
http(“privateHeader.html”)
.get("/modules/common/views/privateHeader.html")
.headers(headers_2),
http(“auctionPrivateHome.html”)
.get("/modules/home/views/auctionPrivateHome.html")
.headers(headers_2),
http(“auctionReports.html”)
.get("/modules/home/views/auctionReports.html")
.headers(headers_2),
http(“auctionPrivateInfo.html”)
.get("/modules/home/views/auctionPrivateInfo.html")
.headers(headers_2),
http(“privateFooter.html”)
.get("/modules/common/views/privateFooter.html")
.headers(headers_2),
http(“downloadAuctionReports.html”)
.get("/modules/common/views/downloadAuctionReports.html")
.headers(headers_2)))
.pause(3,5)
}

The problem is that the value of ${Param_Username} and ${Param_Password}" is not being fetched from the csv file and the body is fed as is. This is resulting in error. Can I know that how I can feed this text file such that the parameterized values are resolved before posting it.

Thanks !!!

Hi,

That’s the difference between “RawFileBody” and “ElFileBody”. The latter will resolve the gatling Expression Language in the file before sending it as body.

Thank you for the quick response. Your suggestion solved my issue. :slight_smile: