Gatling skips requests in scenario

Hello.
I am trying to open multiple links in a loop. (the list of links is stored in the session). But gatling only opens one link. Why?

requests:

package task.http

import io.gatling.core.Predef._
import io.gatling.http.Predef._

object requests {
  val name = "Arcade Alien"

  val characters = http("character")
    .get("https://rickandmortyapi.com/api/character?page=2")
    .check(jsonPath("$.results[?(@.name=='" + name + "')].id").saveAs("id"))

  val characterById = http("characterById")
    .get("https://rickandmortyapi.com/api/character/#{id}")
    .check(jsonPath("$.location.url").saveAs("location"))
    .check(jsonPath("$.image").saveAs("image"))

  val image = http("image")
    .get("#{image}")

  val location = http("location")
    .get("#{location}")
    .check(jsonPath("$.residents[*]").findAll.saveAs("residents"))
    .check(jsonPath("$.residents[*]").findRandom.saveAs("randomResident"))

  val random = http("randomResident")
    .get("#{randomResident}")

}

scenario:

package task.http

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import task.http.requests._

object scenarios {

  val testScenario = scenario("testScenario")
    .exec(characters)
    .exec(characterById)
    .exec(image)
    .exec(location)
    .exec(random)
    /*
    .exec { session =>
      session("residents").as[Seq[String]].toArray
        .foreach(println(_))
      session
    }
    */
    **.foreach(session => session("residents").as[Seq[String]], "myResident") {**
**      exec { session =>**
**        System.out.println(session("myResident").as[String])**
**        session**
**      }**
**        .exec(http("#{myResident}").get("#{myResident}"))**
**    }**
}

simulation:

package task.simulations

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import task.http.scenarios.testScenario

class TestSimulation extends Simulation {
  setUp(
    testScenario.inject(
      atOnceUsers(1)
    ).protocols(
      http
    )
  )
}

pom…xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>lt.gatling</groupId>
  <artifactId>gatling-nkt</artifactId>
  <version>1.0</version>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <gatling.version>3.9.5</gatling.version>
    <gatling-plugin.version>4.0.1</gatling-plugin.version>
    <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
    <scala-maven-plugin.version>4.3.0</scala-maven-plugin.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>dev.code-n-roll.gatling</groupId>
      <artifactId>jdbc-gatling_2.12</artifactId>
      <version>2.3.0</version>
    </dependency>
  </dependencies>
  <build>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>${maven-jar-plugin.version}</version>
      </plugin>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>${scala-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <jvmArgs>
                <jvmArg>-Xss100M</jvmArg>
              </jvmArgs>
              <args>
                <arg>-target:jvm-1.8</arg>
                <arg>-deprecation</arg>
                <arg>-feature</arg>
                <arg>-unchecked</arg>
                <arg>-language:implicitConversions</arg>
                <arg>-language:postfixOps</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-plugin.version}</version>
        <executions>
          <execution>
            <id>execution1</id>
            <configuration>
              <simulationClass>task.simulations.TestSimulation</simulationClass>
              <configFolder>${project.basedir}/src/test/resources</configFolder>
              <dataFolder>${project.basedir}/src/test/resources/data</dataFolder>
              <resultsFolder>${project.basedir}/target/gatling/results</resultsFolder>
              <bodiesFolder>${project.basedir}/src/test/resources/bodies</bodiesFolder>
              <simulationsFolder>${project.basedir}/src/test/scala</simulationsFolder>
              <runDescription>This-is-the-run-description</runDescription>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Caching?

2 Likes