Hello everyone.
I must be send 2 request the same time.
I must get “trid” in the response of first request .
I must use the “trid” in the second request.
Single test is ok.
When I do load test.
I have 2 problem.
One problem is some times first request does not work correctly and I cant get “trid”.
Second problem is Some times First request work, but work multipal time then work second request. This time only I get of the last request “trid”.
I want to the request work the as below example
- work first request
- I must get the “trid”
- I must use “trid” on the second request.
- must be work the second request
My code is below
Please help me
package com.gatling.tests.Alltest
import com.google.common.base.Charsets.UTF_8
import com.google.common.hash.Hashing
import com.google.common.io.BaseEncoding
import io.gatling.core.Predef.*
import io.gatling.core.scenario.Simulation
import io.gatling.core.structure.ChainBuilder
import io.gatling.http.Predef.*
import io.gatling.http.response.*
import io.gatling.http.response.NoResponseBody.Empty.bytes
import io.gatling.jdbc.Predef.*
import org.apache.commons.*
import java.io.{FileOutputStream, PrintWriter}
import java.nio.charset.StandardCharsets
import java.nio.charset.StandardCharsets.UTF_8
import java.security.*
import java.text.SimpleDateFormat
import java.time.{LocalDateTime, LocalTime}
import java.util.{Base64, Calendar, Random, TimeZone}
import javax.crypto.SecretKey
import javax.crypto.spec.SecretKeySpec
import javax.xml.bind.DatatypeConverter
import javax.xml.ws.ResponseWrapper
import scala.concurrent.duration.*
import scala.language.postfixOps
class Alltest extends Simulation {
val response_writer = {
val fos = new FileOutputStream("src/test/resources/data/writeResponse.csv")
new PrintWriter(fos, true)
}
val response_writer4 = {
val fos = new FileOutputStream("src/test/resources/data/writeResponseData.csv")
new PrintWriter(fos, true)
}
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")
private val headers_0 = Map(
"sec-ch-ua" -> """Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"""
)
val age = "30"
val name = "Test Name"
val description = "Test Request"
var request_date = ""
var time = ""
var nonce = ""
var calculate_text = ""
var date_time = ""
var text = ""
var desc = ""
var trid = ""
val first_req = scenario("auth_0")
.exec(session => {
date_time = format_date.format(Calendar.getInstance.getTime).toString()
request_date = format.format(Calendar.getInstance.getTime).toString() + Random().nextInt(999999).toString()
time = format.format(Calendar.getInstance.getTime).toString()
nonce = Random().nextInt(999999).toString()
text = name.length + name + age.length + age + description.length + description + request_date.length + request_date + time.length + time + nonce.length + nonce
calculate_text = date_time + request_date + time + nonce + text + age + name + description
session
})
.exec(
http("request_0")
.post("/test/test")
.headers(headers_0)
.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"))
)
.exec(session => {
desc = session("desc").as[String]
trid = session("trid").as[String]
session
})
.exec(session => {
response_writer.println(session("resp").as[String])
session
})
.exec(session => {
response_writer4.println("first_req, desc = " + desc + ", trid" + trid )
session
})
var request_date_2 = ""
var time_2 = ""
var nonce_2 = ""
var calculate_text_2 = ""
var date_time_2 = ""
var text_2 = ""
var desc_2 = ""
val second_req = scenario("auth_0")
.exec(session => {
date_time_2 = format_date.format(Calendar.getInstance.getTime).toString()
request_date_2 = format.format(Calendar.getInstance.getTime).toString() + Random().nextInt(999999).toString()
time_2 = format.format(Calendar.getInstance.getTime).toString()
nonce_2 = Random().nextInt(999999).toString()
text_2 = name.length + name + age.length + age + description.length + description + request_date_2.length + request_date_2 + time_2.length + time_2 + nonce_2.length + nonce_2
calculate_text_2 = date_time_2 + request_date_2 + time_2 + nonce_2 + text_2 + age + name + description
session
})
.exec(
http("request_1")
.post("/test/test")
.headers(headers_0)
.formParam("age", _ => age)
.formParam("name", _ => name)
.formParam("description", _ => description)
.formParam("date_time", _ => date_time_2)
.formParam("time", _ => time_2)
.formParam("nonce", _ => nonce_2)
.formParam("calculate_text", _ => calculate_text_2)
.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"))
)
.exec(session => {
desc = session("desc").as[String]
trid = session("trid").as[String]
session
})
.exec(session => {
response_writer.println(session("resp").as[String])
session
})
.exec(session => {
response_writer4.println("second_req, desc = " + desc + ", trid" + trid)
session
})
val admins = scenario("Admins").exec(first_req, second_req)
{
setUp(
admins.inject(rampUsers(4).during(10))
).protocols(httpProtocol)
}
}