如何每次使用 gatling 登录随机用户?

How to Login with Random users everytime with gatling?

我的场景是这样的,我必须为 创建一个脚本,它随机需要 10 个用户进行登录和注销 我写的代码登录同一个用户 10 次它不采用随机数。 如何做到这一点?

下面是我的代码输出同一个用户登录 10 次,而不是让不同的用户登录。

// Login and Logout random users
import scala.concurrent.duration._
import java.util.concurrent.ThreadLocalRandom
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class random extends Simulation {

 val testServerUrl = System.getProperty("Url", "https://url")
 val username = System.getProperty("username", "TestUser")
 val password = System.getProperty("password", "password")
 val userCount = Integer.getInteger("userCount", 10).toInt
 val startNum = Integer.getInteger("EndNumber", 1).toInt
 val endNum = Integer.getInteger("EndNumber", 100).toInt

 val httpProtocol = http
 .baseURL(testServerUrl)

 val scn = scenario("random")
 .exec(http("Login")
 .post("/security_check")
 .headers(headers_9)
 .formParam("j_username", username + ThreadLocalRandom.current.nextInt(startNum, endNum))
 .formParam("j_password", password)
 .resources(
 http("Fetch_IDs")
 .get("/desktop/s_nav.jsp")
 .check(regex("""current_account_id=(\d+)""").saveAs("accountID"))
 .check(regex("""current_workspace_id=(\d+)""").saveAs("workspaceID"))
 .headers(headers_5)
 ))

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

 setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

问题是场景 val 中的随机生成器仅在场景生成时调用一次。

你想要做的是使用一个馈线,它在你的场景的每次执行中注入随机值。

Gatling 有一个非常好的文档,其中包含 feeder 的示例,您可以在此处找到: http://gatling.io/docs/2.0.0-RC2/session/feeder.html

这里(第 03 步): http://gatling.io/docs/2.0.0-RC2/advanced_tutorial.html

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