Is there a possibility to pass dynamic params in subsequent requests

val r1 = exec(http(“req1”)
.get("/request1/")
.headers(h1)
.check(regex(“somepattern”).findAll.saveAs(“valueSource”))
.resources(http(“req2”)
.get("/request2/"),
http(“req3”)
.post(url)
.headers(h2)
.formParam(“item1”, “”"[{“param1”:“value1”, “param2”: “value2”}]""")

value2 needs to be derived dynamically as per the below computations:

Computations:

  • valueSource : Map[key,value]

  • Based on some calculations add more values into valueSource

  • Fetch value2 using a key ==> get a value by passing a key

Question: Where can be the above computations happen to fetch the value2 during run time dynamically either using

  • session variables
  • separate method → doesnt work since method gets executed first before “req1” is executed. so valueSource is empty in first place!
  • anything else?

Please suggest.

Firstly - are you sure the .resources request shouldn’t really be a separate http request? It doesn’t seem sensible (simulation-wise) to have the resources on a request determined by the response from that request

If you break the ‘req2’ request out into a separate exec statement you could either…

do the manipulation at the time of doing the extraction of “valueSource” with a .transform (this might work if you really need to make req2 as part of .resources, but I haven’t tried it)

.check(regex("somepattern").findAll..findAll.transform(

  (values, session) => {
    //do your calculations
).saveAs("value2")

or do it as part of a separate session action after req1

`
.exec(session => {
//do your calculations
})

`

which option you choose