Gatling - Passing Parameters to a simulation

Hi All,

I am new to Gatling and Load Testing.

I have a scenario here where I am calling a webservice for which the input is an XML file. We have to simulate 50 such users per second. If I am not wrong, I would need 50 different XML files with different data. I am confused on how to simulate this situation using 50 different XML files. Please let me know if there is an alternate way to do this.If not, do i need to hard code all the data?

Thanks in advance

If the 50 XML files are all radically different, then yes, you need 50 different files.

However, if the request has a standard format, and you are only changing out the values within the XML, then you can use a single “template” file, and pull the values you need from the session.

Check it out: http://gatling.io/docs/2.1.7/http/http_request.html#request-body

Hi John,

Thank you very much. I will give that a try and post the results here

Regards,
Sowmeeya J

Hi John,

I have exhausted almost all the resources and I am not able to get this working. My script is as follows

class getdecision extends Simulation {

val httpProtocol = http
.baseURL(“http://52.3.151.185:8004”)

val uri2 = “http://52.3.151.185:8004
// val DEXML = XML.load(“bodies/DE.xml”)

val scn = scenario(“getdecision”)
.exec(http(“request_0”)
.get("/"))
.pause(29)

.exec(http(“request_1”)
.post("/")
.body(ELFileBody(“bodies/DE.xml”)).asXML)
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

I am trying to load test a web service. I am calling the url, I need to pass the content of an XML file into a text box and click submit. This will create a new user and the user should reflect in the Database. However, I am not able to accomplish this using the above script. When i pass the content of the xml it works fine. However, if I am calling the file using RawFile,ELFile or any other feeder, it doesnt work. I have tries almost all the feeders and the result is the same.

Please tell me what is wrong.Any help is much appreciated.

Regards,
Sowmeeya

Use Firefox and Firebug, or the Chrome Developer Tools, to inspect the request that is sent to the server when you submit the form manually. Make sure the content of your request body matches. Most notably, a form post is different than an XML upload (e.g. Soap request). It will be in the format:

formElementName=

Which means you will need to url-encode the XML and prepend the field name portion.

Alternatively, my recommendation is to read the file from disk, and pass the contents to .formParam(). Or you could even embed the file right in the code, like this:

`
val xml = “”"

... """.stripMargin

`

There’s always more than one way to do it!

Hi John,

Thank you so much for the reply.

I have tried embedding the code in the file as you said and I am trying to pass the values that I would like to change in the file for every user as parameters. I did it based on the post -https://groups.google.com/forum/#!searchin/gatling/Soap/gatling/gDhbjlQzof4/SwDwLEZ1xEwJ . When I record the script for one user using Gatling recorder, the resultant script contains only formParam(). So I presume I should go with the same. However I have tried using both formParam() and body() and the result is still the same. The script runs fine and no errors are displayed however the users are not getting created. I am sure I am missing out something here. I have tried to find out but no luck. Would like to seek your help with this.

My script looks like this

import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.http.request.Body
import xml._
import scala.io.Source

class getdecision extends Simulation {

val httpProtocol = http
.baseURL(“http://52.3.151.185:8004”)
.inferHtmlResources(BlackList("""..js""", “”"..css""", “”"..gif""", “”"..jpeg""", “”"..jpg""", “”"..ico""", “”"..woff""", “”"..(t|o)tf""", “”".*.png"""), WhiteList())

val uri2 = “http://52.3.151.185:8004

val scn = scenario(“GetDecision”)
.exec(http(“request_0”)
.get("/"))
.pause(29)

.feed(csv(“UserDetails.csv”))
.exec(http(“request_1”)
.post("/")
.body(SAMLAuthenticationSoapRequest)))
// .formParam(“txtAK”,SAMLAuthenticationSoapRequest("${APPID}","${TIN}","${FirstName}","${LastName}"))
// .formParam(“PSButton”,“PS Value”))

def SAMLAuthenticationSoapRequest(APPID: String, TIN: String, FirstName: String, LastName: String) = “”"<?xml version="1.0" encoding="UTF-8"?>


0ef6468d-d44b-4466-b65c-71a5dfb020c6
1.0.0.80

${TIN} $(FirstName} P ${LastName} 19920820 168 WAVERLY ST APT 2 NULL PROVIDENCE DE 02909 US 168 WAVERLY ST APT 2 NULL PROVIDENCE DE 02909 US ................ ..................... ....................... """

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

My CSV is as follows

APPID, TIN, FirstName, LastName
72B4D4F6-EC4C-4BCE-85FB-8B69A446B958, 139933900, RyydvmZX, UgmpgLOn
9BB0D749-0F3B-4F63-84DF-BCA68D418742, 092201415, orfiGAlG, QeyygrTu
D8E4EE7D-5589-45CF-94D9-42CD0D076371, 082323492, kBopjfDF, PxqkxgsX
17332A53-EA86-44A2-AEA8-81C70F0A24F1, 866891404, eVbaSMWc, dgivSyxf
B5842E2A-C8EA-41AC-A989-D4861F0B7EBA, 334840342, kerqBUfC, muaqEdLU

Thanks in advance.

Regards,
Sowmeeya

Hi all,

I am still stuck at the same position.

Any help is much appreciated.

Thanks.

Sowmeeya

You are close.

// define the xml as a static string containing ${placeholders} for session variables where they need to be inserted - not a function, just a value
val XML = “”"…"""

val behavior =
scenario( “submit it” )
.exec(
http( “send XML to server” )
.post( “/” )
.formParam( “txtAK”, XML )
.formParam(“PSButton”,“PS Value”) // experiment with leaving this off
)