Gatling:如何在scala脚本中传递用户定义的变量(值)?

时间:2017-01-11 07:14:31

标签: performance scala performance-testing load-testing gatling

我正在为创建新用户创建Gatling脚本。 我将用户定义的值(fName =“newuser”,emailDomain =“@ perftestorg.com”)传递给下一个请求。

但是,作为回应,它没有返回定义的值,也没有打印时间戳。请在这里建议我做错了什么?

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import java.util.Calendar
import java.util.Date
import java.text.SimpleDateFormat

class CreateNewUser extends Simulation {


val fName = "newuser"
val emailDomain = "@perftestorg.com"

val sdfDate = new SimpleDateFormat("ddMMyy.HH.mm.ss.SSS")
val now = new Date()
val timeStamp = sdfDate.format(now)

val httpProtocol = http
    .baseURL("https://abcxyz.com")
    .acceptHeader("application/json, text/javascript, */*; q=0.01")
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("en-US")
    .userAgentHeader("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
    .disableCaching
    .doNotTrackHeader("1")

val scn = scenario("CreateNewUser")
    .exec(http("LogIn")
        .post("https://" + uri1 + "/login-page")
        .headers(headers_0)
        .formParam("_58_redirect", "")
        .formParam("_58_rememberMe", "false")
        .formParam("_58_login", "newuser002@perftestorg.com")
        .formParam("_58_password", "scOrpiO")
    .exec(http("checkUserAlreadyExist")
        .post("/api/checkUserAlreadyExist")
        .headers(headers_2)
        .formParam("emailAdd", "$fName+timeStamp+$emailDomain"))
    .exec(http("CreateNewUser")
        .post("/api/UserSubscription")
        .headers(headers_2)
        .formParam("UserSubscription", """{"userEmail":"$fName+timeStamp+$emailDomain", "fName":"$fName","lName":""""+timeStamp+"""","languageId":"en_GB","subscription_id":"1","contractNumber":"1234567890","emailNotification":true,"orgName":"Performance Testing Organisation"}""")            
        .formParam("sendLoginCredential", "true"))



    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)

}

非常感谢您的帮助。

感谢, 普利文

1 个答案:

答案 0 :(得分:0)

当你使用$ fName的东西时,你需要把变量放在session中。 使用

  

EXEC(_组(" FNAME""用户名&#34))。EXEC(HTTP ...