Peter Peter - 1 year ago 109
Scala Question

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

val scn = scenario("random")
.formParam("j_username", username + ThreadLocalRandom.current.nextInt(startNum, endNum))
.formParam("j_password", password)

.formParam("action", "logout")
.formParam("undefined", "")
.formParam("current_account_id", "${accountID}")
.formParam("current_workspace_id", "${workspaceID}"))


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download