2016-11-18 1 views
1

내 시나리오는 에 대한 스크립트를 만들어 로그인과 로그 아웃을 위해 임의로 10 명의 사용자를 필요로합니다.. 코드는 동일한 사용자가 10 번 로그인 한 상태에서 임의의 번호를 사용하지 않습니다. 어떻게 수행하나요?gatling을 할 때마다 임의의 사용자와 로그인하는 방법?

아래 코드는 다른 사용자를 복용하는 대신 동일한 사용자 로그인을 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) 
} 

답변

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

개틀링은 여기에서 찾을 수 있습니다 공급에 대한 예제와 함께 아주 좋은 문서를 가지고

관련 문제