Get resources from functions

Hello,

in my scenario I have different calls to pages loading stuff in resources that are always pretty much the same, so I’d like to use an external functions with a parameter to get them. For instance :

val scn = scenario(“Simulation”)
.feed(userCredentials)
.group(“DC”) {
exec(http(“Loading " + landingPage)
.get(”/" + storagePrefix + “/” + landingPage + “.html?” + remoteUidSuffix + “=${userId}”)
.headers(headers_html)
.check(status.in(304, 200)))
.exec(http(“Load mashup”)
.get(“http://” + serverIP + “:” + app_port + “/” + presentationWebContext + “/mashup?” + remoteUidSuffix + “=${userId}”)
.resources(
http(“Load print”)
.get(“http://” + serverIP + “:” + app_port + “/” + presentationWebContext + “/print?” + remoteUidSuffix + “=${userId}”),
http(“Load initFilters.js”)
.get(“http://” + serverIP + “:” + web_port + “/” + staticContentPrefix + “/js/initFilters.js?”)
.headers(headers_xhtml),
[…]
)
)
}

Here in resources I have a dozen of different JS files. I’d like to have this kind of function :

def loadJS(jsFile:String) : Unit = {
http(“Load " + jsFile + “.js”)
.get(“http://” + serverIP + “:” + web_port + “/” + staticContentPrefix + “/js/” + jsFile +”.js?")
.headers(headers_xhtml)
}

But I don’t know how to make it work. I’ve seen that resources takes AbstractHttpRequestBuilder[_]* as argument but I didn't find the syntax to build this array and return it to append it in resources()

def loadJS(jsFile:String) : ```AbstractHttpRequestBuilder[] = { resources = new```` AbstractHttpRequestBuilderT```
resources :+ http("Load " + jsFile + ".js")
.get("http://" + serverIP + ":" + web_port + "/" + staticContentPrefix + "/js/" + jsFile +".js?")
.headers(headers_xhtml)
}
Any hint would be great, I'm very new to Gatling and Scala :)

Thank you!

The Gatling DSL components are builders that have to be chained together so that they can be resolved (once, when the Simulation is loaded) into a scenario workflow.

So, the logic of your loadJS, which is a procedure (doesn’t return anything/Unit and only side-effects), is wrong.