Oh! My!
So many things!!!
- Why global variables?
- Why
var
usage? - Why do you use scala language ? Do you know we support Java and Kotlin as well?
- Did you follow the Gatling Academy?
- Did you read (and understand) the tutorial?
- A scenario should not contains another scenario (
admins
scenario containsfirst_req
declared as a scenario)
So, below will be an example of what I think will work for you. It use the concept of:
- Feeder (generate data for user)
- Use data from session
import io.gatling.core.Predef._
import io.gatling.core.feeder.Feeder
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
import java.text.SimpleDateFormat
import java.util.{Calendar, TimeZone}
import scala.language.postfixOps
import scala.util.Random
class Alltest extends Simulation {
val format = new SimpleDateFormat("yyyyMMddHHmmss")
format.setTimeZone(TimeZone.getTimeZone("UTC"))
val format_date = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS")
format_date.setTimeZone(TimeZone.getTimeZone("GMT+4"))
private val httpProtocol = http
.baseUrl("https://test.ss.com")
val Age = "30"
val Name = "Test Name"
val Description = "Test Request"
def generateOneEntry: Map[String, String] = {
val dateTime = format_date.format(Calendar.getInstance.getTime)
val requestDate = format.format(Calendar.getInstance.getTime) + Random.nextInt(999999).toString
val time = format.format(Calendar.getInstance.getTime)
val nonce = Random.nextInt(999999).toString
val text = Name.length + Name + Age.length + Age + Description.length + Description + requestDate.length + requestDate + time.length + time + nonce.length + nonce
Map(
"date_time" -> dateTime,
"request_date" -> requestDate,
"time" -> time,
"nonce" -> nonce,
"calculate_text" -> (dateTime + requestDate + time + nonce + text + Age + Name + Description)
)
}
val myFeeder: Feeder[String] = Iterator.continually(generateOneEntry)
val first_req = http("request_0")
.post("/test/test")
.formParam("age", Age)
.formParam("name", Name)
.formParam("description", Description)
.formParam("date_time", "#{date_time}")
.formParam("time", "#{time}")
.formParam("nonce", "#{nonce}")
.formParam("calculate_text", "#{calculate_text}")
.check(bodyString.saveAs("resp"))
.check(xpath("//desc").saveAs("desc"))
.check(xpath("//action").saveAs("action"))
.check(xpath("//trid").saveAs("trid"))
.check(status.is(200))
.check(xpath("//desc").is("Approved"))
.check(xpath("//action").is("0"))
val second_req = http("request_1")
.post("/test/test")
.formParam("age", Age)
.formParam("name", Name)
.formParam("description", Description)
.formParam("date_time", "#{date_time}")
.formParam("time", "#{time}")
.formParam("nonce", "#{nonce}")
.formParam("calculate_text", "#{calculate_text}")
.formParam("trid", "#{trid}")
.check(bodyString.saveAs("resp"))
.check(xpath("//desc").saveAs("desc"))
.check(xpath("//action").saveAs("action"))
.check(xpath("//trid").saveAs("trid"))
.check(status.is(200))
.check(xpath("//desc").is("Approved"))
.check(xpath("//action").is("0"))
val admins = scenario("Admins")
.feed(myFeeder)
.exec(first_req)
.feed(myFeeder)
.exec(second_req)
{
setUp(
admins.inject(rampUsers(4).during(10))
).protocols(httpProtocol)
}
}
Hope it helps!
Cheers!