File reading issue with line

Hello,

I am trying to read a csv file with any value which doesn’t contain ‘none’ in column 3, and (eventually) parse the value to my test scenario.

val sec_user = “none”

val SecUserID = scala.io.Source.fromFile("/data/output_live_one_hour.csv")
.getLines()
.filter(line => ! sec_user.contains(line(2)))
.map(line => line(2))
.toArray

However I seem to get a type mismatch error and String does not take parameters error.

Error:(41, 40) type mismatch;
found : String
required: ?{def apply: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Session => io.gatling.core.validation.Validation[T]
are possible conversion functions from String to ?{def apply: ?}
.filter(line => !sec_user.contains(line(2)))
^
Error:(41, 44) String does not take parameters
.filter(line => !sec_user.contains(line(2)))
^

Is it to do with how (line => line(2)) is used?

Thanks

Hi.Why don’t you use gatling build-in feeder feature?
it very useful for use-cases like you mentioned.

Hey Gregory,

Thanks for your reply! I have used feeder for my test so my test is something like this

val LogFile= getClass.getResource("/data/output_live_one_hour.csv").getFile
val Jaccess_log= csv(LogFile).circular

val sec_user = “none”

val SecUserID = scala.io.Source.fromFile("/data/output_live_one_hour.csv")
.getLines()
.filter(line => ! sec_user.contains(line(2)))
.map(line => line(2))
.toArray

val scn = scenario(“Jaccess log one hour scenario”)
.feed(Jaccess_log)
.doIfEqualsOrElse("${sec_user_id}", “none”) {
exec(
http(“Search Flow non login”)
.get("${URL}")
.check(status.is(200))
)
} {
exec(addCookie(Cookie(“sso2”, “”+ SecUserID +"_DK20P7DLYO6383GDYX77DT7V5W23V88X_sn2_ts1430149950239")))
.exec(
http(“Search Flow login”)
.get("${URL}")
.check(status.is(200))
)
}

So I basically need to extract the values in column 3 from a file and parse them into the test whilist using the feeder to get to the URL (column 2) which is on the same line as the extracted values in the csv file. I don’t think it likes ‘line => line(2)’ but not sure what else to use?

Thanks

A Feeder is more or less a Iterator[Map[String, String] where the maps keys are computed for the first header line.
And if your file is CSV, format handling might be more complex than just splitting on comma (which you didn’t do), as you might have to deal with commas inside values.

I advise you use Gatling built-in CSV support for parsing and then filter.

val filteredRecords = csv(“myFile.csv”).records.filterNot(record => record(“nameOf3rdColumn”) == “none”)