# It works perfectly, but how do I make it better?

**URL:** https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538
**Category:** Gatling (Open-Source)
**Created:** [October 13, 2014, 9:43pm UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538 "2014-10-13T21:43:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![janne.salinger65](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@janne.salinger65](https://community.gatling.io/u/janne.salinger65)
#### Post date: [October 13, 2014, 9:43pm UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538/1 "2014-10-13T21:43:45Z")

</div>

Hey Guys,

I have made a Gatling test where I have a

Class with my scenario and different exec.

// val = feed out of scenario

val scn = scenario(“Scenario Name”)  
.feed(feeder)  
.exec(http(“request\_1”)  
.get("/"))  
.pause(1)

.exec(http(“request\_2”)  
.get("/" + “${username}” + “/” + “${userID}”))  
.pause(1)

.exec(http(“request\_3”)  
.get("/" + “${username}” + “/” + “${userId}” + “/” + “${userAccount}”)) // it make a json int concatination (11111111-11-111111) as output  
.pause(1)

I use a standard CSV feeder and everything works fine.  
But now I have gotten to the point that where can feed everything but it make all my (.get)'s a gigantic concatenated string with Gatling EL in between.  
Like the third example. I tried to feed outside of the scenario, but that does not work. Is there a way to save my GIGANTIC string (like .get("/" + “${username}” + “/” + “${userId}” + “/” + “${userAccount}”).saveAs(myValue) and use that in later sessions or something different that does not have me repeating this terrible string all the time.

TNX  
Janne

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [October 13, 2014, 9:51pm UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538/2 "2014-10-13T21:51:34Z")

</div>

Why do you concatenate instead of passing a single string???

val scn = scenario(“Scenario Name”)  
.feed(feeder)  
.exec(http(“request\_1”)  
.get("/"))  
.pause(1)

.exec(http(“request\_2”)  
.get("/${username}/${userID}"))  
.pause(1)

.exec(http(“request\_3”)  
.get("/${username}/${userId}/${userAccount}"))  
.pause(1)

And then, if you reaaallllllly want to remove duplicated code, you can define a val:

val usernamePlusUserId = “/${username}/${userID}”

val scn = scenario(“Scenario Name”)  
.feed(feeder)  
.exec(http(“request\_1”)  
.get("/"))  
.pause(1)

.exec(http(“request\_2”)  
.get(usernamePlusUserId))  
.pause(1)

.exec(http(“request\_3”)  
.get(usernamePlusUserId + “/${userAccount}”))  
.pause(1)

---

<div class="post-metadata">

### Author: ![janne.salinger65](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@janne.salinger65](https://community.gatling.io/u/janne.salinger65)
#### Post date: [October 14, 2014, 10:26am UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538/3 "2014-10-14T10:26:00Z")

</div>

Can I pass in an single string and still feed the Gatling EL?

this is my setup. I have a trait to split the scenario from the exec part

import Setup.\_  
import testlogin.\_

import scala.io.Source  
import scala.concurrent.duration.\_  
import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import io.gatling.jdbc.Predef.\_  
import io.gatling.core.feeder.\_

trait tScenarioRunner extends Simulation {

val virtualUsers = 100  
val httpProtocol = new configuration tProtocol  
val search = new tLogin tSearch  
val Credentials = new configuration tUser

def scen: io.gatling.core.structure.ScenarioBuilder  
setUp(scen.inject(atOnceUsers(virtualUsers))).protocols(httpProtocol)  
}

then I have my execution class. I basically do not want to repeat this concatenation the entire time. But i do not know how to put a val / store it in a value during the chain of the scenario? Could you please help I know I am almost there but I still do not see it?

class tAccept extends tScenarioRunner {

override def scen = {  
scenario(“Scenario”).feed(Credentials).feed(Advice)  
.group(“Scenario”) {  
exec(login, search)  
}

.exec(http(“01\_checker”)  
.get("""/web/api/config/""" + “${user}” + “”"/products/""" + “${relation}” + “-” + “${typeproduct}” + “-” + “${productSequence}” + “-”

- “${accountNumber}” + “”"/microsoft""")  
.basicAuth("${username}", “${password}”))

.exec(http(“02\_otherChecker”)  
.get("""/web/api/config/""" + “${user}” + “”"/products/""" + “${relation}” + “-” + “${typeproduct}” + “-” + “${productSequence}” + “-”

- “${accountNumber}” + “”"/apple""")  
.basicAuth("${username}", “${password}”))

//I thought something like delete the dot from the next exec and create a value here. Like

// val A = “”"/web/api/config/""" + “${user}” + “”"/products/""" + “${relation}” + “-” + “${typeproduct}” + “-” + “${productSequence}” + “-”

- “${accountNumber}”""

exec(http(“03\_lastChecker”)  
.get(A + “”"/samsung""")  
.basicAuth("${username}", “${password}”))

}  
}

Or is there an even better option.

Tnx u  
Stéphane

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [October 14, 2014, 11:36am UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538/4 "2014-10-14T11:36:34Z")

</div>

First, I suggested you stop with those ugly concatenations:

“”"/web/api/config/""" + “${user}” + “”"/products/""" + “${relation}” + “-” + “${typeproduct}” + “-” + “${productSequence}” + “-”

- “${accountNumber}” + “”"/apple"""

should be

“/web/api/config/${user}/products/${relation}-${typeproduct}-${productSequence}-${accountNumber}/apple”

Then, I don’t get what your concern is.  
Do you want a way to factor out 01\_checker and 02\_otherChecker, such as:

def req(brand: String) =

http(“Checker” + brand)  
.get("/web/api/config/${user}/products/${relation}-${typeproduct}-${productSequence}-${accountNumber}/" + brand)  
.basicAuth("${username}", “${password}”)

exec(req(“microsoft”))  
.exec(req(“apple”))

---

<div class="post-metadata">

### Author: ![janne.salinger65](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@janne.salinger65](https://community.gatling.io/u/janne.salinger65)
#### Post date: [October 14, 2014, 1:19pm UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538/5 "2014-10-14T13:19:40Z")

</div>

You are AWESOME, sir!

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [October 14, 2014, 1:21pm UTC](https://community.gatling.io/t/it-works-perfectly-but-how-do-i-make-it-better/1538/6 "2014-10-14T13:21:10Z")

</div>

Glad could help 🙂
