【问题标题】:Gatling: How do you pass userdefined variables (values) in scala script?Gatling:如何在 scala 脚本中传递用户定义的变量(值)?
【发布时间】:2017-01-11 07:14:30
【问题描述】:

我正在创建 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)

}

非常感谢您的帮助。

谢谢, 普拉文

【问题讨论】:

  • 问题:什么是 Scala 脚本?
  • @SarveshKumarSingh 回答:Gatling 是一种性能测试工具,用于使用 Scala 编程进行脚本开发。

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


【解决方案1】:

当您使用 $fName 时,您需要将变量放入会话中。 使用

exec(_.set("fName","username")).exec(http...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 2022-10-17
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    相关资源
    最近更新 更多