简体   繁体   中英

How to Login with Random users everytime with gatling?

my scenario is like, I have to create a script for which randomly takes 10 users for login and logout . The code I have written logins same user 10 times it does not take random number. How to do this?

Below is my code outputs same user login 10 times instead of taking different users.

// 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))

The problem is that your random generator inside the scenario val is only called once when the scenario is generated.

What you want to do is use a feeder, that injects random values in each execution of your scenario.

Gatling has a very nice documentation with examples for feeder which you can find here: http://gatling.io/docs/2.0.0-RC2/session/feeder.html

and here (step 03): http://gatling.io/docs/2.0.0-RC2/advanced_tutorial.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM