0

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.

Peter
  • 855
  • 2
  • 15
  • 35

2 Answers2

1

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

Requests that you fetch 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.

Moreover, the username have always the same random number for each user.

.formParam("j_username", username + ThreadLocalRandom.current.nextInt(endNum))

If you want a different random number for each user you need to pass a function to formParam like this:

.formParam("j_username", _ => username + ThreadLocalRandom.current.nextInt(endNum))
FlavienBert
  • 1,674
  • 3
  • 16
  • 17
0

You will need to use a session to get that like this:

  1. Declare a global variable:

    var accountIDString = "";
    var workspaceIDString = "";
    
  2. Create another exec the following way:

    .exec(session =>{
     accountIDString = session.get("accountID").asOption[String].toString();
    
    workIDString = session.get("workID").asOption[String].toString();    
    })
    
    .exec(http("Logout")
       .post("/logoutcontroller")
       .headers(headers_9)
       .formParam("action", "logout")
       .formParam("undefined", "")
                //Here it works and fetches value
       .formParam("current_account_id", "${accountIDString}")
       .formParam("current_workspace_id", "${workspaceIDString}"))
    

And it would work.

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
  • Nope, What I have mentioned is it works for .exec(http("Logout") request. It does not work with .exec(http("Login"). Ids which I have saved are okay but In same .exec() it wont fetch. – Peter Nov 21 '16 at 07:16
  • @Peter Ok. But with the method I showed it would always work. – Pritam Banerjee Nov 21 '16 at 09:32