Using session attributes inner Checks


I want to do something like this

.xpath(“A valid path to obtain an id for an appointment”) aMethodForDeterminingAppointmentId( session(“user”).as[String] ) )

…"user" is currently in session ( csv feeder )

Appart that I personally would rather go with validate instead of as, your code looks fine to me. What’s your problem exactly?

I dont know how to pass the session attribute “user” to the method “aMethodForDeterminingAppointmentId

session(“user”).as[String] ← that’s exactly what you did here

Thank you for your response, my code is something like this

.check( citas_dia_coincidan( ((session: Session) => { session(“fl_usuario”).as[String] }) ) )


def citas_dia_coincidan(fl_usuario: String) = {


Then, when running simulation I get:

type mismatch;

found : io.gatling.core.Predef.Session => String
required: String

I don’t know how to pass the attribute fl_usuario. Any suggestion?

Thanks in advance :slight_smile:

Check is a full API, not just a bare function.
Can you elaborate on what you're trying to check, like, what your
*citas_dia_coincidan* method would look like, so I can help you?

Thank you Stéphane :slight_smile:

citas_dia_coincidan is as follows

def citas_dia_coincidan(folio_usuario: String) = {
var user_appointment = getAppointment(fl_usuario)


I only want to calculate user_appointment from folio_usuario (using method getAppointment ), then check if xpath for calculate FL_APPOINTMENT match witch expected user_appointment

Am I missing something?


So you were overcomplicating things :wink:

check(xpath("//FL_APPOINTMENT/text()") => session(“user”).validate[String].map(folio_usuario => getAppointment(folio_usuario)))

and actually, you can write this much more shortly:


  • removed find because it’s the default
  • replaced session => session with the scala _ wild card, because the function parameter was only used once and not in an inner call (like in foo(bar(session))
  • getAppointment is a method that takes a String and returns a String, so it can be “lifted” into a function that takes a String and returns a String, which is exactly what map method expects here

But well, if you don’t want to learn a few functional tricks, the following would work too (with the limitations of .as compared to .validate):

check(xpath("//FL_APPOINTMENT/text()").is(session => getAppointment(session(“user”).as[String]))

Get it?

Thank you very much it works !!! And I think, I already understand about the placeholder “_”
My final code was:

.check( citas_dia_coincidan )


def citas_dia_coincidan() = {
xpath("//FL_APPOINTMENT/text()").is( _(“fl_usuario”).validate[String].map(getAppointment) )


:smiley: :smiley:

You don’t even need the curly braces as there’s only one instruction:

def citas_dia_coincidan() = xpath("//FL_APPOINTMENT/text()").is( _(“fl_usuario”).validate[String].map(getAppointment) )

Have fun!

And you don’t even need to make it a def:

val citas_dia_coincidan() = xpath("//FL_APPOINTMENT/text()").is( _(“fl_usuario”).validate[String].map(getAppointment) )