[英]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)
}
.formParam("j_username", session => username + ThreadLocalRandom.current.nextInt(endNum))
问题在于,场景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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.