Combine all similar checks into one method

I’m sorry to ask such question, but I’m still newbie to scala and really need some quick solution.

The system under test is distributed among several servers. Thus to check if the whole system works well I need to perform several checks for every page. I would like to extract these checks to one method, but cannot manage to find out how to do it in scala.

Below is my test scenario sample:

class SimpleTest extends Simulation {
val httpConf = httpConfig
.baseURL(“https://192.168.1.21:443”)
.acceptHeader("/")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-us”)
.connection(“Keep-Alive”)
.userAgentHeader(“Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)”)

val userCredentials = csv(“user_credentials.csv”).queue

val headers_Content_Length_0 = Map(
“Content-Length” → “0”)

val chain_login = exec(http(“Login request”)
.post("/sys/loginBrowser/login")
.param(""“login”"", “${username}”)
.param(""“passwd”"", “${password}”)
.check(status.is(200))
.check(regex(""“Please contact your personal manager”"").notExists)
.check(regex(""“NotAcceptingRequests”"").notExists)
)

val chain_welcome = exec(http(“Welcome page”)
.get("/sys/external/welcome")
.check(status.is(200))
.check(regex(""“Please contact your personal manager”"").notExists)
.check(regex(""“NotAcceptingRequests”"").notExists)
)
.pause(30 milliseconds)
.exec(http(“Business day status”)
.get("/sys/external/business_day_status")
.check(status.is(200))
.check(regex(""“Please contact your personal manager”"").notExists)
.check(regex(""“NotAcceptingRequests”"").notExists)
)
.pause(300 milliseconds)
.exec(http(“Account list”)
.post("/sys/external/account-list")
.headers(headers_Content_Length_0)
.check(status.is(200))
.check(regex(""“Please contact your personal manager”"").notExists)
.check(regex(""“NotAcceptingRequests”"").notExists)
)

val chain_logout = exec(http(“Logout request”)
.get("/sys/logout")
.check(status.is(200))
.check(regex(""“Please contact your personal manager”"").notExists)
.check(regex(""“NotAcceptingRequests”"").notExists)
)

val scn = scenario(“Simple scenario”)
.feed(userCredentials)
.repeat(1) {
exec(chain_login)
.pause(500 milliseconds)
.exec(chain_welcome)
.pause(500 milliseconds)
.exec(chain_logout)
}

setUp(
scn.inject(
ramp(100 users) over (30 seconds)
).protocolConfig(httpConf)
)
}

Hi,

The following code :

val chain_logout = exec(http(“Logout request”)
.get("/sys/logout")
.check(status.is(200))
.check(regex(""“Please contact your personal manager”"").notExists)
.check(regex(""“NotAcceptingRequests”"").notExists)
)

can be rewritten this way :

import com.excilys.ebi.gatling.http.request.builder.AbstractHttpRequestBuilder

def execWithStdChecks(httpRequest: AbstractHttpRequestBuilder[_ <: AbstractHttpRequestBuilder[_]]) = {
exec(httpRequest.check(
regex(""“Please contact your personal manager”"").notExists,
regex(""“NotAcceptingRequests”"").notExists))
}

val chain_logout = execWithStdChecks(http(“Logout request”).get("/sys/logout"))

‘def’ beeing the Scala keywork for defining a function … the type is a bit tricky to guess without Eclipse.

Note that the check about “status.is(200)” is not necessary, this is the only predefined check in Gatling.

does this help ?

cheers
Nicolas

cheers
Nicolas

Thanks! It helps!