How to force "exec" to be executed inside the "IF" condition

Hi. I’ve been using Gatling for 2 months and I’m a bit stuck with what seems to be a simple problem. I’m new to scala.

I have such a program code. But I don’t understand why, the condition inside “IF” is not met. At the same time, the output to the “println” log works.
How to make “exec” run inside “if”?

        .group("_UC20")(
          exec { session =>
            val city_proc = session("city_proc").as[String]
            val street_proc = session("street_proc").as[String]
            val building_proc = session("building_proc").as[String]

            if(city_proc != session("deliveryCity") || street_proc != session("deliveryStreet") || building_proc != session("deliveryNumberHome")) {

              exec(LightBuyWithPromAction.api_v3_addresses_reduce_short_address)
                .exec(LightBuyWithPromAction.api_shopping_context)

              println("city_proc", session("city_proc").as[String])
              println("street_proc", session("street_proc").as[String])
              println("building_proc", session("building_proc").as[String])

            } else {}

            session
          }
        )

At the same time, when the output to the log is triggered, it does not execute “exec”, but goes further along the program code and executes the next group “group”.

Hi @GeorgeDev,

Do you know Gatling simulations may be written in Java or Kotlin?

Questions:

  • Did you check what is the type of city_proc? (String, I guess)
  • Did you check what is the type of session("deliveryCity")? (Not String, I guess)

So, the condition is ALWAYS met.

Your real question should be: “Why the gatling step inside my custom function is not run?”
Because gatling DSL is mainly a builder, and calling step in your custom function will never work.

For reference: see the 2nd alert block in Session - Function documentation.

I think you need Conditional statements

Cheers!

1 Like

Because gatling DSL is mainly a builder, and calling step in your custom function will never work.

From exec’s documentation:

Remember that the Gatling DSL components are merely definitions. They only are effective when chained with other DSL components and ultimately passed to the setUp. In particular, they have no effect when used inside functions.

exec { session =>
  // just creates a dandling component, doesn't produce any effect
  http("Gatling").get("https://gatling.io")
  session
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.