Modularizing simulation - define checks in separate file / import checks from another file?

I’ve got a simulation that’s doing most of the things I want thus far, and now I am breaking it up into separate modular bits so that I can then call them a variable number of times (i.e. I can simulate a random number of products being added to a cart, etc, by just looping a random number of times and calling the add to cart code repeatedly).

using a mixture of information from https://stackoverflow.com/questions/15568284/modularising-scenarios-to-run-in-sequence-using-gatling and https://github.com/excilys/gatling/wiki/Advanced-Usage this is working for the purposes of running an entire section :

in the imported add to cart file:
object AddToCart {
val mAddToCartAction =
exec((session: Session) => {

}
.exec(
http(…)
)
.exitHereIfFailed
.pause(…)
}

and the main simulation:

val scn = scenario(…)
.exec(…)

.exec(mAddToCartAction)

For purposes of organization / readability, it would be nice if checks that are used to gather data for an action could be separated into the action’s scala file, rather than being in the previous action’s scala file, and just import them and exec similarly. I tried to do this but got errors about “not found: value check”:
AddToCart.scala:18: not found: value check
13:51:19.900 [ERROR] i.g.a.ZincCompiler$ - check(css("#product_addtocart_form",“action”).find.saveAs(“formAction”))

the referenced line being:
15 object AddToCart {
16
17 val mAddToCartChecks =
18 check(css("#product_addtocart_form",“action”).find.saveAs(“formAction”))

I tried wrapping it in exec too but that didn’t change anything…

Is this possible? If so, how?

No, check is a method on http request, you can’t move it around.
What you can move around is the list of checks that you pass to the check method.

Disclaimer: yes, this looks weird, don’t blame me, don’t blame Scala. Blame damn Java’s type erasure.

ex:
.check(
status.is(200),
css("#product_addtocart_form",“action”).find.saveAs(“formAction”)
)

can be turned in:

import io.gatling.http.check.HttpCheck

val myChecks: Seq[HttpCheck] = Seq(
status.is(200),
css("#product_addtocart_form",“action”).find.saveAs(“formAction”)
)

.check(myChecks: _*)

Awesome! This works perfectly, thanks!

Can you combine individual checks and sequences in the call to check()? E.g.:

val myChecks: Seq[HttpCheck] = Seq(
regex(“foo”),
regex(“bar”)
)

…and…

.check(
status.is(200),
myChecks: _*
)

Apparently not:

… no `: *’ annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
15:23:16.784 [ERROR] i.g.a.ZincCompiler$ - .check(status.is(200),mAddToCartChecks:
*)

However, this works:
.check(status.is(200))
.check(mAddToCartChecks:_*)

.check((status.is(200): HttpCheck) +: checks: _*))