Hi,
I can’t think of a way how do I make it syntactically correct. I have a feeder csv file which looks like:
passNum,passVal
1,aabb
2,bbaa
3,ssdd
and so on
In the beginning of the scenario I feed it:
.exec(feed(feeder))
From one of the replies body I parse a number and save it as a session parameter “paswordNumber”. And in the next request I need to take the appropriate password from the feeder file. For example, if “passwordNumber” was “1” then I need to take “aabb” from the feeder. I also created “password” empty session attribute that will hold my password. Now It looks like this:
def findPassword =
exec(session => session.set(“password”, ${passVal})
)
How do I write that I need such ${passVal} which ${passNum} == ${passwordNumber}? Thank you in advance.
Then, Feeders are not intended for this usage.
What you need is to convert your data to a Map indexed by passNum.
You can still use Gatling facilities:
val passwordsByNumber: Map[Int, String] =
csv(“passwords.csv”).records.map(record => record(“foo”).toInt → record(“bar”)).toMap
// once you have the passwordNumber, fetch and inject the
.exec(session => session(“passNum”).validate[Int].map(number => session.set(“passVal”, passwordsByNumber(number))))
When I tried it out, my “passwordNumber” was parsed as 2. However, “passNum” was 1 and “passVal” was the password for 1 and not for 2. And “password” was empty. Did I miss something?
passwordNumber - the number of password that I need to receive from the csv file (third in this case)
passNum, passVal - two columns of the passwords.csv file
password - this will be set with the appropriate passVal value
After execution:
passwordNumber → 3
passNum → 1
passVal → aabb (first password)
and no attribute for password
I am using Gatling2.0.0-RC3. What could the problem be?
Could you please share a GIST with your WHOLE simulation, please?
Here, you’re calling a .exec(setPassNum) and setpassNum is missing from what you pasted.
Thanks! Got it to work. Another thing is how can I transform session attribute into type Int. Is it something like:
Integer.parseInt(session(“passwordNumber”))
So if I need to make a POST request and put a password as a parameter is there any difference between:
.formParam(“password”, “1111333”)
and
.formParam(“password”, 1111333)