Ho to generate and use dynamic parameter each request in gatling scala?

How to generate and use dynamic parameters for each request in Gatling scala?

Hello every one
I have one problem. Please help me

I generate 2 dynamic parameters (order and time). Again I generate the third dynamic parameter and use the above 2 dynamic parameters.

Commonly I have 5 parameter

I post 5 parameter

When I do load the test first request is ok but the next request is a duplicate.
How do generate dynamic parameters in each request?
For example :
I want
order = “20220830084116213653”
time = “20220830084116”
name = “Test”
surname = “Testov”
def req_param = “20220830084116213653” + “20220830084116” + “Test” + “Testov”

and next request is

order = “20220830084116213654”
time = “20220830084117”
name = “Test”
surname = “Testov”
req_param = “20220830084116213654” + “20220830084117” + “Test” + “Testov”

Real request and response is there

class TestRequest extends Simulation {
val format = new SimpleDateFormat(“yyyyMMddHHmmss”)
format.setTimeZone(TimeZone.getTimeZone(“UTC”))

val order = format.format(Calendar.getInstance.getTime).toString() + Random().nextInt(999999).toString()
val time = format.format(Calendar.getInstance.getTime).toString()
val name = “Test”
val surname = “Testov”
val req_param = order + time + name + surname

val httpProtocol = http
.baseUrl(“https://some url”)

private val headers_0 = Map(
“sec-ch-ua-mobile” → “some parameter”,
)
private val scn = scenario(“RecordedSimulation”)
.exec (
http(“request_0”)
.post("/)
.headers(headers_0)
.formParam(“order”, _ => order)
.formParam(“time”, _ => time)
.formParam(“name”, _ => name)
.formParam(“surname”, _ => surname)
.formParam(“req_param”, _ => req_param)
)
setUp(scn.inject(rampUsers(5).during(1)).protocols(httpProtocol))
}

RESPONSE IS

<?xml version="1.0" encoding="utf-8" ?> Approved 20220830084116213653 20220830084116 Test TestOV 2022083008411621365320220830084116TestTestOV <?xml version="1.0" encoding="utf-8" ?> Repeated 20220830084116213653 20220830084116 Test TestOV 2022083008411621365320220830084116TestTestOV <?xml version="1.0" encoding="utf-8" ?> Repeated 20220830084116213653 20220830084116 Test TestOV 2022083008411621365320220830084116TestTestOV <?xml version="1.0" encoding="utf-8" ?> Repeated 20220830084116213653 20220830084116 Test TestOV 2022083008411621365320220830084116TestTestOV <?xml version="1.0" encoding="utf-8" ?> Repeated 20220830084116213653 20220830084116 Test TestOV 2022083008411621365320220830084116TestTestOV

But must be every request Approved
how do I do it?

val means a final reference.
How can you expect req_param, order and time to be recomputed?
You have to make them def, ie a method.

When I define the parameter with def it happens as below
variable takes on a new value each time it is used
An example is as follows

order = “20220830084116213653”
time = “20220830084116”
name = “Test”
surname = “Testov”
def req_param = “20220830084116213654” + “20220830084117” + “Test” + “Testov”

.formParam(“order”, _ => 20220830084116213655)
.formParam(“time”, _ => 20220830084118)
.formParam(“name”, _ => name)
.formParam(“surname”, _ => surname)
.formParam(“req_param”, _ => “20220830084116213656” + “20220830084119” + “Test” + “Testov”)

But I want it to be like this

order = “20220830084116213653”
time = “20220830084116”
name = “Test”
surname = “Testov”
def req_param = “20220830084116213653” + “20220830084116” + “Test” + “Testov”

.formParam(“order”, _ => 20220830084116213653)
.formParam(“time”, _ => 20220830084116)
.formParam(“name”, _ => name)
.formParam(“surname”, _ => surname)
.formParam(“req_param”, _ => “20220830084116213653” + “20220830084116” + “Test” + “Testov”)

This is for a request
If I do a load test
Then change these parameters for each request

Then, if you want order, time and req_param to be computed together so they are aligned, you have to:

  1. compute then all at once in an exec(function) and store the current values in the current Session
  2. fetch the stored values from the Session when passing them to formParam, typically with Gatling Expression Language

Can you please write this script and show me how to do it?
I just started writing in this language.
I search the internet and can’t find an example

I just started writing in this language.

Are you aware that you don’t have to use Scala and that Gatling also supports Java and Kotlin?
Don’t make learning bits of Scala a blocking step in your path of learning Gatling.
Moreover, your problem here has nothing to do with Scala but learning the Gatling API.

I search the internet and can’t find an example

I advice that you don’t try to take shortcuts and google for a solution to copy-paste.
You should take some time to read the official documentation and do the Gatling Academy free online trainings. Learning the tool will definitely pay off.