Passing feeder values to my own method

I am learning to use feeder along with my own method. In my sample script below, I am trying to print out user and pwd values from feeder. However, the function printIt is never called thus no user and pwd values will be printed. The “pause(5)” is called though. What do I miss?

class MyTest extends Simulation {
val loginsFeeder = csv("logins.csv").circular
val httpProtocol = http.baseUrl("http://www.google.com")

def printIt(user: String, pwd: String) = {
.exec(session => {
println(s"user=" + user + ";pwd=" + pwd)
session
})
.exec(http("get_url").get("/"))
}

val scnRunExec = scenario("MyTest")
.feed(loginsFeeder)
.exec(session => {
printIt(session("user").as[String], session("pwd").as[String])
session
})
.pause(5)

setUp(scnRunExec.inject(constantConcurrentUsers(1).during(10)).protocols(httpProtocol))
}

Your printIt is wrong.
You’re calling it from inside an exec(f) block where calling Gatling DSL methods has no effect.
Please read https://gatling.io/docs/current/general/scenario/

This is correct:

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class MyTest extends Simulation {
  val loginsFeeder = csv("logins.csv").circular
  val httpProtocol = http.baseUrl("[http://www.google.com](http://www.google.com)")

  val scnRunExec = scenario("MyTest")
    .feed(loginsFeeder)
    .exec(session => {
      println(session("user").as[String], session("pwd").as[String])
      session
    })
    .pause(5)

  setUp(scnRunExec.inject(constantConcurrentUsers(1).during(10)).protocols(httpProtocol))
}

Thanks Stephane.
I have also tried a few more things, and v2 of the following works. Is v2 the right way to do it if I need to do some complicate processing of data before/after sending a request? Does that mean I need to save (session.set) all such data as session data?

//////////////
v0: This is the original one I posted yesterday, and it doesn’t work.

def printIt(user: String, pwd: String) = {
.exec(session => {
println(s"user=" + user + ";pwd=" + pwd)
session
})
.exec(http("get_url").get("/"))
}
val scnRunExec = scenario("MyTest")
.feed(loginsFeeder)
.exec(session => {
printIt(session("user").as[String], session("pwd").as[String])
session
})

//////////////

v1: Hardcode the values for user and pwd. This will print out “a” and “b”, but not very useful as feeder data are not used.

.exec(printIt("a", "b"))

//////////////

v2: Instead of passing feeder data to my method, I call session data (from feeder) directly in my method. This works.

def printIt2() = {
exec(session => {
println(s"user=" + session("user").as[String] + ";pwd=" + session("pwd").as[String])
session
})
.exec(http("get_url").get("/"))
}

def scnRunExec = scenario("MyTest")
.feed(loginsFeeder)
.exec(printIt2())

v0 can’t work because, as explained in the documentation mentioned above, the Gatling methods don’t work in your own functions.

Remember that the Gatling DSL components are merely definitions. They only are effective when chained with other DSL components and ultimately passed to the setUp . In particular, they have no effect when used inside functions.