Session and conditional statement

Hello gatling users,

I have a test case where

  1. I am setting session variables to initial values

  2. call the grPC method,

  3. extract values of variables from response

  4. update the session variables with values from response

  5. Call the gRPC method until the value of session2 variable becomes 0

    group(“test case”) {
    session => {
    session.set(“session1”, “*”).set(“session2”, 1)
    extract session 1 and session 2 and update initial values of the variables
    } <<do it until session2 is 0>>

How can I achieve this?

How about something like this, the value of session2 will be evaluated at the end of the loop (Gatling - Scenario)

group("test case")(
  doWhile(session => session("session2").as[Int] != 0)(
     exec(yourGrcpChain) //you extract session1 and session2 in this chain

Thank you. Your solution helped me get past the first hurdle.

Now I am having issues making use of the session variable in the grpc method

I have tried “#{session2}” but it does not get the session2 value.

what am I doing wrong?

Are there any other way to get the session2 value inside of the grpc method?

Can you give an example of your code, that shows the use of session2. I can’t help much without seeing. I misplaced my crystal ball, trust me it’s been difficult to debug my own code lately :stuck_out_tongue_closed_eyes:

group("TestCase1") {
    session => {
      session.set("session1", "xyz")
      session.set("session2", 1)
    doWhile(session => {
      val session2 = session.attributes("session2").asInstanceOf[Int]
      session2 != 0 }) (
        .extract(_. responseVariable1.some)(_ saveAs ("session1"))
        .extract(_. responseVariable1.size.some)(_ saveAs ("session2")))

grpcMethod is the helped method that passes this session2 variable to the actual gRPC call. It is in passing that session2 variable as a parameter I am facing issues.I think I am not using it the right way as a result instead of replacing with the value of session2, the function passes the exact string
“#{session2}” thereby failing the grpc call

Change the following

    session => {
      session.set("session1", "xyz")
      session.set("session2", 1) // only this one is set, last statement in a function is the return statement


    session => {
      session.setAll(("session1", "xyz"),("session2", 1))

I’m not too familiar with the grpcMethod, I think it may not evaluate Expressions.