Reputation: 2821
My Gatling version is 2.2.0, for example:
# resource.csv file
===============
user
user1
user2
# object file
===============
object REntity {
val feeder = csv("resources.csv").circular
val entity =
// ==================
// log in
// ==================
feed(feeder)
.exec(
http("example")
.post("/authentication?name=${user}")
.body(session => s"${Utils.getCredential(user)}")
).exitHereIfFailed.pause(Config.ThinkTime)
}
Utils.getCredential(user: String): String
is simply a function which accept a user name, and return a credential string.
As you see, the user name are stored in resources.csv
file. I could simply refer to it by .post("/authentication?name=${user}")
. But how could I refer to it as a variable like ${Utils.getCredential(user))}
, this will raise error.
Any ideas? Thanks for your time!
Upvotes: 3
Views: 8838
Reputation: 2821
I searched Gatling's docs, found out the answer here.
It has two sections introducing 1). setting attributes and 2) getting attributes.
Basically speaking, the way to get attributes should be:
// say resources.csv looks like this:
// =====================
// user,entityID
// Jim,1001
// Mike,1002
val feeder = csv("resources.csv").circular
val name = session("user").as[String] // => "Jim"
The answer should be:
object REntity {
val feeder = csv("resources.csv").circular
val entity =
// ==================
// log in
// ==================
feed(feeder)
.exec(
http("example")
.post("/authentication?name=${user}")
.body(session => Utils.getCredential(session("user").as[String]))
).exitHereIfFailed.pause(Config.ThinkTime)
}
Upvotes: 10