How to pick values from CSV file and manipulate them

Hi,

I want to get the value from CSV file and split them. But I am not successful. Please help. Below is my code snippet

`
val separator : Array[Char] = Array(’@’, ‘-’, ‘.’)
var strSocketSplit : Array[String] = null
var strSocket_URL : String = “”

val SessionIDFeeder = csv(“data/login SessionIDs.csv”)

// Get and Update self Scehdule

val scn1 = scenario(“Get_Assign_SelfSCH_Websocket1”)

// Get Session ID from feeder
.feed(SessionIDFeeder)

// Parse Session ID

strSocket_URL = “${Session_ID}”
println(strSocket_URL)
strSocketSplit = strSocket_URL.split(separator)
println(strSocketSplit(0))
`

SessionIDFeeder

Session_ID
362@75-1-2.d5ec222f-90ba-f89e-5814-4ad3b88b26f7.jFMhndPnwQtcqdlc
362@75-1-1.d5ec222f-90ba-f89e-5814-4ad34854b5f6.MicaaddoWqodljni
362@75-1-3.d5ec222f-90ba-f89e-5814-4ad31cf8a9f8.kpKgiliImdoiblip
362@75-1-4.d5ec222f-90ba-f89e-5814-4ad3b06a1cfd.mbjdabOmdcinajgr
362@75-1-5.d5ec222f-90ba-f89e-5814-4bd3e0e3b802.AeYTcyiibdaneDqj

When I run the code, I get the following output

Console output is saving to: C:\Users\b.rani\git\Gatling-Self-Schedule-Testing\Simulation Log files\Gatling Logs.log

${Session_ID}
${Session_ID}
Simulation SelfSchedule_Scenarios.WS_TXPSelfSch_GetAssign_Parallel_ReuseSessionIDs started…

Looks like it is not picking values from CSV file. How to get the values from CSV file and manipulate before passing them to post request body. I need to pick the first 4 values from each Session_ID string(For Example: 362, 75, 1, 2)

you need to make sure that on the first row of your csv file you have Session_ID for that column of session id values

Hi Cliffton,

Thanks for the reply. Yes in my csv file first row of session_ID values column is Session_ID. but doesn’t work. CSV feeder works in the post request body. But as I have experienced it doesn’t work if I need to pick a value from CSV feeder and save it to the variable for example.

Can you try with Session.set method and see if that works in this scenario?

What you’re trying to do is not going to work, at least not the way you are doing it. You are mixing build-time code with run time code.

The value of scn1 is an object that describes a scenario. The scenario has not started running yet. So your code that is trying to manipulate the session is executing outside of the context of a running virtual user, and has no access to a session.

In order to do what you want, you have to embed the logic inside of an .exec( Session => Session ) call, like so:

val scn1 =
scenario(“Get_Assign_SelfSCH_Websocket1”)
.feed(SessionIDFeeder)
.exec( session => {
val strSocket_URL = session(“Session_ID”).as[String]

println(strSocket_URL)
val strSocketSplit = strSocket_URL.split(separator)
println(strSocketSplit(0))

session
})

Notice how I did not re-use global variables inside the exec block? This is because this code will be executed by every virtual user, which means if you try to manipulate global variables, they may stomp all over each other.