Peter Peter - 1 year ago 93
Scala Question

Unable to pass Saved values in formParam of same request

I have saved

'current_account_id'
and
'current_workspace_id'


in below code. Want to use those IDs in next request as I have to make it dynamic so I replaced "505520" with
"${accountID}"
and "505519" with
"${workspaceID}"
but it doesnt work and throws "No attribute named 'accountID' is defined"

However it works on 'Logout' request. Can anyone tell how to solve this?

.exec(http("Login")
.post("/j_security_check")
.headers(headers_9)
.formParam("j_username", username + ThreadLocalRandom.current.nextInt(endNum))
.formParam("j_password", password)
.resources(
http("Fetch_IDs")
.get("/desktop/side_nav.jsp")
.check(regex("""current_account_id=(\d+)""").saveAs("accountID"))
.check(regex("""current_workspace_id=(\d+)""").saveAs("workspaceID"))
.headers(headers_5),
http("request_11")
.get("/desktop/dashboard/index.jsp")
.headers(headers_5),
http("request_12")
.get("/global_nav.jsp")
.headers(headers_5),
http("request_13")
.post("/eventDataController")
.headers(headers_9)
.formParam("action", "viewevents")
.formParam("objectId", "")
.formParam("type", "Desktop")
.formParam("dashboardType", "desktop_events")
.formParam("forceReplace", "true")
// Doesnt work
.formParam("current_account_id", "${accountID}")
.formParam("current_workspace_id", "${workspaceID}")
.formParam("skipAccountCheck", "")
.formParam("skipWorkspaceCheck", ""),
http("request_14")
.post("/savedsearchdatacontroller")
.headers(headers_9)
.formParam("action", "dashboard_view")
.formParam("dashboardType", "Desktop")
.formParam("current_account_id", "505520")
.formParam("current_workspace_id", "505519"),
http("request_15")
.post("/wizardDataController")
.headers(headers_9)
.formParam("action", "view")
.formParam("current_account_id", "505520")
.formParam("current_workspace_id", "505519")))

.exec(http("Logout")
.post("/logoutcontroller")
.headers(headers_9)
.formParam("action", "logout")
.formParam("undefined", "")
//Here it works and fetches value
.formParam("current_account_id", "${accountID}")
.formParam("current_workspace_id", "${workspaceID}")
)


Thanks.

Answer Source

In your case, you can't use 'accountID' from the session because it's not set yet.

Requests fetches from resources block are executed in parallel. That means you can't reuse a variable saved from a request into an other request if both are in the same resources block.