How to execute Scenarios in Sequence in Gatling?

Hi,
I have two scenarios 1st “getAssets” scenario will fetch all asset IDs and save it in a list, 2nd scenario “fetchMetadata” will iterate those IDs.

I have to execute “getAssets” scenario only once to fetch all the IDs, and “fetchMetadata” scenario till given time duration only after completion of 1st scenario.

How can I execute both scenarios in Chain (Sequentially)? I am using Gatling Ver. 2.1.7

Here is the code but it doesn’t execute scenarios in sequence.

import java.util.concurrent.ThreadLocalRandom
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class getAssetsMetadata extends Simulation {
    val getAssetURL = System.getProperty("getAssetURL", "https://performancetesting.net")
    val username = System.getProperty("username", "performanceuser")
    val password = System.getProperty("password", "performanceuser")
    val limit = Integer.getInteger("limit", 1000).toInt
    val userCount = Integer.getInteger("userCount", 100).toInt
    val duration = Integer.getInteger("duration",1).toInt //in minutes

    var IdList: Seq[String] = _   

    val httpProtocol = http
        .basicAuth(username, password)
        .baseURL(getAssetURL)
        .contentTypeHeader("""application/vnd.v1+json""")

    val getAssets = exec(http("List of Assets")
            .get(s"""/api/assets;limit=$limit""")
            .check(jsonPath("$.assets[*].id").findAll.transform {v => IdList = v; v }.saveAs("IdList"))
            )

    val fetchMetadata = exec(_.set("IdList", IdList))
        .exec(http("Metadata Request")
            .get("""/api/assets/${IdList.random()}/metadata""")
            )

    .exec(session => {
                val printID = session.get("IdList").asOption[String]
                println("======================================================")
                println("Session ====>>>> " + session)
                println("Asset ID: =====>> " + printID.getOrElse("COULD NOT FIND Asset ID"))
                println("======================================================")
                session})       

    val scn1 = scenario("scenario1")
            .exec(getAssets)
    val scn2 = scenario("scenario2")
            .exec(fetchMetadata)
    setUp(scn1.inject(atOnceUsers(1)), scn2.inject(constantUsersPerSec(userCount) during(duration minutes))).protocols(httpProtocol)
}       

You could execute one by one and after that consolidate the simulation result file. Another option could be calculate the time you’re going to execute first scenario and wait (doing nothing) for that time before execute second in the setup simulation.

Thanks for the reply Ignacio.

Yes you are right,I’ve added .inject(nothingFor(120 seconds) for 2nd scenario but what I want to do is, it will not execute 2nd scenario until 1st scn gets completed. I mean execute step wise. It would be great if you have some code for this.

Maybe you could define a single scenario with a rendezvouz point that checks that all users finish the initial sequence of requests.

Take a look http://gatling.io/docs/current/general/scenario/