Dynamically read values - RawFileBody

I have a scenario that looks like :

.exec(http(“request_2”)

.post("""/signin""")

.body(RawFileBody(“Test_request_2.txt”))

.check(status.is(200)))

The Test_request_2.txt looks like this:

-----------------------------64407778716977852291061126114

Content-Disposition: form-data; name=“Signin[member_name]”

SellerName

-----------------------------64407778716977852291061126114

Content-Disposition: form-data; name=“Signin[password]”

SellerPassword

-----------------------------64407778716977852291061126114

Content-Disposition: form-data; name=“Signin[submitSignin]”

Sign In

-----------------------------64407778716977852291061126114–

I want to simulate this scenario for 10 different sellers. How do I make the SellerName & Password read dynamically?

Any pointers/help is greatly appreciated. Thank you.

-Sonal

Hi,

You can use Gatling ELFileBody to make this request body dynamic, by allowing Gatling to “inject” data from the user’s session in the request body

.exec(http(“request_2”)
.post("""/signin""")
.body(ELFileBody(“Test_request_2.txt”))
.check(status.is(200)))

And replace, in the request body, “SellerName” by “${SellerName}” and “Password” by “${Password}”.
Then, all you need is to have “SellerName” and “Password” attributes in the user’s session, with the values you need.
For example, those values could be injected in the session by a feeder, or from the result of a previous check + saveAs.

Hope this helps !

Cheers,

Pierre

Thanks Pierre!

So I replaced the content of Test_request_2.txt as:

----------------------------64407778716977852291061126114

Content-Disposition: form-data; name=“Signin[member_name]”

“${SellerName}”

----------------------------64407778716977852291061126114

Content-Disposition: form-data; name=“Signin[password]”

“${Password}”

----------------------------64407778716977852291061126114

Content-Disposition: form-data; name=“Signin[submitSignin]”

Sign In

----------------------------64407778716977852291061126114

And made following changes in the .scala file:

val sellerNameFeeder = csv(“sLogin.csv”)

val scn = scenario(“LoginSimulation”)

.feed(sellerNameFeeder)

.exec(http(“request_2”)

.post("""/signin""")

.body(ELFileBody(“Test_request_2.txt”))

.check(status.is(200)))

setUp(scn.inject(atOnceUsers(5))).protocols(httpProtocol)

}

When I run this script, I get a failure saying “[WARN ] i.g.h.a.AsyncHandlerActor - Request ‘request_2’ failed: status.is(200), but actually found 500”

Could you please tell me what did I miss? Thanks a bunch for your help!

-Sonal

Hi Sonal,

In the case of ELFileBody, you don’t need to put add quotes around EL expressions, ${SellerName} and ${Password} would do.
And about your error… well… that could come from anything… Could be that the quotes you added means that the server is not able to handle request, could be that the server is temporary unavailable…
If you want to get more info, uncomment the following line in logback.xml :

`

`

This will print (a lot of) debug information and can provide enough detail to find out what cause the internal error.
Or you may have to check the logs of your application to find out what causes the error.

Cheers,

Pierre

Thanks Pierre! it certainly helped! I am able to read right values for SellerName & Password from the file. Enabling debugging also helped. I am seeing following error on POST :

Zend_Form::isValid expects an array

Any idea what this could mean? Am I doing my POST correctly through gatling? Please let me know.

Thanks
-Sonal

Hi Sonal,

Sorry, but I can’t help there : This looks like somewhere, you’re sending something that is not a array and it expects one.
This has only to do with the system you’re testing (I guess it is based on Zend Framework, and I haven’t worked with PHP in years :)).
You’re on your own for that one.

Cheers,