# Combine all similar checks into one method

**URL:** https://community.gatling.io/t/combine-all-similar-checks-into-one-method/349
**Category:** Gatling (Open-Source)
**Created:** [April 29, 2013, 7:26pm UTC](https://community.gatling.io/t/combine-all-similar-checks-into-one-method/349 "2013-04-29T19:26:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![natalja.librante](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@natalja.librante](https://community.gatling.io/u/natalja.librante)
#### Post date: [April 29, 2013, 7:26pm UTC](https://community.gatling.io/t/combine-all-similar-checks-into-one-method/349/1 "2013-04-29T19:26:18Z")

</div>

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](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)  
)  
}

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 29, 2013, 7:48pm UTC](https://community.gatling.io/t/combine-all-similar-checks-into-one-method/349/2 "2013-04-29T19:48:10Z")

</div>

Hi,

The following code :

val chain\_logout = exec(http(“Logout request”)  
.get("/sys/logout")  
.check([status.is](http://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](http://status.is)(200)” is not necessary, this is the only predefined check in Gatling.

does this help ?

cheers  
Nicolas

cheers  
Nicolas

---

<div class="post-metadata">

### Author: ![natalja.librante](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@natalja.librante](https://community.gatling.io/u/natalja.librante)
#### Post date: [May 2, 2013, 11:48am UTC](https://community.gatling.io/t/combine-all-similar-checks-into-one-method/349/3 "2013-05-02T11:48:52Z")

</div>

Thanks! It helps!
