无法在同一请求的 formParam 中传递保存的值
Unable to pass Saved values in formParam of same request
我保存了'current_account_id'
和'current_workspace_id'
在下面的代码中。想在下一个请求中使用这些 ID,因为我必须使其动态化,所以我用 "${accountID}"
替换了“505520”,用 "${workspaceID}"
替换了“505519”,但它不起作用并抛出 "No attribute named 'accountID' is defined"
但是它适用于 'Logout' 请求。 谁能告诉我如何解决这个问题?
.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}")
)
谢谢。
您将需要使用一个会话来获取它:
声明一个全局变量:
var accountIDString = "";
var workspaceIDString = "";
按以下方式创建另一个 exec:
.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}"))
它会起作用的。
在您的情况下,您无法使用会话中的 'accountID',因为它尚未设置。
您从资源块中获取的请求是并行执行的。这意味着如果两个请求都在同一个资源块中,则不能将从请求中保存的变量重用到另一个请求中。
此外,每个用户的用户名始终具有相同的随机数。
.formParam("j_username", username + ThreadLocalRandom.current.nextInt(endNum))
如果您想为每个用户使用不同的随机数,您需要像这样将一个函数传递给 formParam:
.formParam("j_username", _ => username + ThreadLocalRandom.current.nextInt(endNum))
我保存了'current_account_id'
和'current_workspace_id'
在下面的代码中。想在下一个请求中使用这些 ID,因为我必须使其动态化,所以我用 "${accountID}"
替换了“505520”,用 "${workspaceID}"
替换了“505519”,但它不起作用并抛出 "No attribute named 'accountID' is defined"
但是它适用于 'Logout' 请求。 谁能告诉我如何解决这个问题?
.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}")
)
谢谢。
您将需要使用一个会话来获取它:
声明一个全局变量:
var accountIDString = ""; var workspaceIDString = "";
按以下方式创建另一个 exec:
.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}"))
它会起作用的。
在您的情况下,您无法使用会话中的 'accountID',因为它尚未设置。
您从资源块中获取的请求是并行执行的。这意味着如果两个请求都在同一个资源块中,则不能将从请求中保存的变量重用到另一个请求中。
此外,每个用户的用户名始终具有相同的随机数。
.formParam("j_username", username + ThreadLocalRandom.current.nextInt(endNum))
如果您想为每个用户使用不同的随机数,您需要像这样将一个函数传递给 formParam:
.formParam("j_username", _ => username + ThreadLocalRandom.current.nextInt(endNum))