1

I'm new in gatling/scala The main idea of my scenario: I need to pass each item from some prepared List of String into the method, and check that response correct

so it's my scenario

object ForeachScenario extends Scenario {

 override def profile(): OpenInjectionStep = {
    atOnceUsers(3)
  }

  val rules_new = List("one", "two", "three")
  val custom_feed = rules_new.map(el=> Map("expressions_rules" -> el)).iterator

  override def createScenario(): ChainBuilder = {
    group(name()) {
      tryMax(SCENARIO_MAX_RETRIES) {
        tryMax(NUMBER_OF_ATTEMPTS) {
          // Creating a user and his context
          exec(
            UserCreator.createUser(
              "userName", "userUid" 
            )
          )
        }.exitHereIfFailed
          .tryMax(NUMBER_OF_ATTEMPTS) {
           feed(custom_feed)
              .exec(
                someClassWithMethod.method("${userName}", "${userUid}", "request-bodies/rulesDS/rules-expressions.json")
                  .requestBuilder
                  .check(status.is(200))
                  .check(jsonPath("$.evaluations[0].result").find.is("100"))                  
              )

          }
      }
    }
  }
}

in general, it works as expected, but... I would like to change this code for using only one virtual user, I have some separate scenario for checking functionality related to UserCreator.createUser and in this case, the main task create a user and under his context check another API, so, for this task user creation for each element in my list is redundantly

 override def profile(): OpenInjectionStep = {
    atOnceUsers(1)
  }

I can't understand how can I realize this, because feeder uses only the first item from the list in the case with one virtual user (atOnceUsers(1)), probably I can save somehow userName and UserUid

          exec(
            UserCreator.createUser(
              "userName", "userUid" 
            )
          )

and use them further OR probably have to use another approach for iteration? can somebody help me with that?

Dmytro
  • 65
  • 1
  • 6
  • Your code samples are too complicated and your questions too confusing. You should rewrite your code samples so they compile without any missing piece AND only include what's relevant to your questions. Also, if you're a Scala beginner, you really should go with the new Java DSL introduced in Gatling 3.7 instead. – Stéphane LANDELLE Jan 04 '22 at 21:35

0 Answers0