Extraction is not working when requests are part of resource

Hi,

I get “No attribute named ‘trackCode’ is defined” when my request is part of the resource group. As shown in the below example.

Is there a way to handle such situation like storing the ‘trackCode’ in session parameter ?

.exec(http("01_Main_Request_Page")
                        .post("/services/app/event/uiClick/json")
                        .headers(headers_0)
                        .body(StringBody("{}"))
                        .resources(http(**"02_Sub_Request**")
                                      .get("/services/app/cme/settings/track/json")
                                      .check(jmesPath("data.trackCode").saveAs("trackCode")),
                                               
                                   http("03_Sub_Request")
                                      .get("/services/app/cme/tracks/json?trackCode=#{trackCode}")
                                      .check(jmesPath("data[0].survey.id").saveAs("surveyId"))
                                         
                                )
                )

Extraction works fine if I take out the sub-requests and place them under new .exec call.

Thanks,
Ashish

Any reason why you want to use resources? resources helps emulate parallel fetches. Now if you think about that, parallel fetches that are done subsequent to your 01_Main_Request_Page should not depend on each other. If they do depend, as in your case 02_Sub_Request and 03_Sub_Request, then they cannot be parallel :slight_smile: . If 03_Sub_Request depends on 02_Sub_Request then it is by nature a sequential call.

I think you might be missing a .asJson in 01_Main_Request_Page call

Maybe you intend to do this instead

.exec(http(**"02_Sub_Request**")
       .get("/services/app/cme/settings/track/json")
       .check(jmesPath("data.trackCode").saveAs("trackCode"))
.resources(http("01_Main_Request_Page")
             .post("/services/app/event/uiClick/json")
             .headers(headers_0)
             .body(StringBody("{}"))
             .asJson)
.exec(http("03_Sub_Request")
       .get("/services/app/cme/tracks/json?trackCode=#{trackCode}")
       .check(jmesPath("data[0].survey.id").saveAs("surveyId")))
2 Likes

Thanks @shoaib42 . Right, extraction is working in the case when requests are executed sequentially.

To your question- Why I am using resources?. Actually, this is how the recorded HAR file was converted into a Gatling script. But I got what you are saying. Thanks for the explanation.