How to pick values from CSV file and manipulate them


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

// Parse Session ID

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



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

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 =
.exec( session => {
val strSocket_URL = session(“Session_ID”).as[String]

val strSocketSplit = strSocket_URL.split(separator)


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.