Search code examples
gatling

Gatling - requirement failed: No scenario set up


Im fairly new into programming, i was trying to launch my test but i got : Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: No scenario set up even if i got the scenario set up (which is confusing) i'm pretty sure is something obvious that newbie like me can't figure out unfortunately. i tried invalidating caches, and reloading the project. im using intelij + maven

package simulations

import io.gatling.core.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder

class GatlingDemoStore extends Simulation {

  val domain = "demostore.gatling.io"

  val httpProtocol: HttpProtocolBuilder = http
    .baseUrl("http://" + domain)


  object login {
    def userlogin: ChainBuilder = {
      exec(http("Login User")
        .post("/login")
        .formParam("_csrf", "${csrfValue}")
        .formParam("username", "user1")
        .formParam("password", "pass"))
    }
  }

  object CmsPages {
    def homepage: ChainBuilder = {
      exec(http("Load Home Page")
        .get("/")
        .check(status.is(200))
        .check(regex("<title>Gatling Demo-Store</title>").exists)
        .check(css("#_csrf", "content").saveAs("csrfValue")))
    }

    def aboutus: ChainBuilder = {
      exec(http("Load Home Page")
        .get("/about-us")
        .check(status.is(200))
        .check(substring("About Us")))
    }

    def categories: ChainBuilder = {
      exec(http("Load Categories Page")
        .get("/category/all")
        .check(status.is(200)))
        .pause(10)
    }

    def productpage: ChainBuilder = {
      exec(http("Load Product Page")
        .get("/product/black-and-red-glasses")
        .check(status.is(200)))
        .pause(15)
    }

    def addtocart: ChainBuilder = {
      exec(http("Add Product to Cart")
        .get("/cart/add/19"))
    }

    def viewcart: ChainBuilder = {
      exec(http("View Cart")
        .get("/cart/view"))
    }

    def checkout: ChainBuilder = {
      exec(http("Checkout")
        .get("/cart/checkout"))
    }

    val User: ScenarioBuilder = scenario("DemoStore Simulation")
      .exec(CmsPages.homepage)
      .pause(5)
      .exec(CmsPages.aboutus)
      .pause(5)
      .exec(CmsPages.categories)
      .pause(20)
      .exec(CmsPages.productpage)
      .pause(5)
      .exec(CmsPages.addtocart)
      .pause(2)
      .exec(login.userlogin)


    setUp(
      User.inject(atOnceUsers(1))
    ).protocols(httpProtocol)
  }
}

Solution

  • I've reformatted your code so your error is more obvious: you're calling setUp not in the body of the GatlingDemoStore class but in the body of the CmsPages object, which is never loaded (in Scala, objects are lazily loaded and here you never call it).

    Move setUp in the body of the GatlingDemoStore class.

    Important note: as you're new to programming, you should probably go with Java (supported since Gatling 3.7) instead of Scala.