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

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

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)

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

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”))

You are AWESOME, sir!

Glad could help :slight_smile: