Gatling:随机进纸器POST请求:未找到:值电子邮件(Gatling 3.0.0)



**带门控的随机负载测试**我想测试我构建的API以获得更高的负载,因此,我必须生成大量的随机电子邮件(我知道目前服务器上没有电子邮件复选框,所以我只创建随机字符串(。我使用的工具是gatling-charts-highcharts-bundle-3.0.0,我查看了其他关于如何解决这个问题的问题和网页,我得到了使用feeder的信息。我尝试了以下代码,但我不明白为什么总是会出现值非错误。基本上:我正试图创建一个随机字符串馈送器,并在gatling 3.0.0中使用它,但当我以以下方式执行时,我总是收到一个"未找到:值电子邮件"错误:

package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Random
class testsimu extends Simulation {

val httpProtocol = http
.baseUrl("http://testurl.com/api") // Here is the root for all    relative URLs
.acceptHeader("application/json") // Here are the common headers
.acceptLanguageHeader("en;q=1.0,de-AT;q=0.9")
.acceptEncodingHeader("gzip;q=1.0,compress;q=0.5")
.userAgentHeader("TestApp/1.3.0(com.test.test;build:1;iOS12.1.0)Alamofire/4.7.0")
val headers_10 = Map("Content-Type" -> "application/json") // Note the  headers specific to a given request
val feeder = Iterator.continually(Map("email" -> (Random.alphanumeric.take(20).mkString)))
val scn = scenario("Login") // A scenario is a chain of requests and pauses
// Note that Gatling has recorded real time pauses
.feed(feeder)
.exec(http("LoginRequest") // Here's an example of a POST request
.post("/login")
.headers(headers_10)
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
setUp(scn.inject(constantUsersPerSec(10) during(5 seconds) randomized).protocols(httpConf))
}

这里的错误信息:

GATLING_HOME is set to  /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-3.0.0
15:06:12.819 [ERROR] i.g.c.ZincCompiler$ - /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-  3.0.0/user-files/simulations/test/test.scala:45:46: not found: value email
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
^
15:06:12.821 [ERROR] i.g.c.ZincCompiler$ - /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-3.0.0/user-files/simulations/higgs/higgs-sim.scala:45:103: not found: value email
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
                               ^
15:06:12.856 [ERROR] i.g.c.ZincCompiler$ - two errors found
15:06:12.858 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.internal.inc.CompileFailed: null
...

为什么会出现"找不到值"的错误?

我找到了解决方案:代替:

StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson

用途:

StringBody("""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson

相关内容

最新更新