如果尝试从csv数据源处理多行,Alway会收到错误“没有定义名为'name'的属性”

时间:2018-06-18 05:49:20

标签: gatling scala-gatling

在我的测试脚本中,我尝试通过以下语句处理来自100数据Feed的csv行数据:

private val scn = scenario("test_scn").feed(insertFeeder, 100).exec(httpReq)

但我总是收到错误:

[ERROR] HttpRequestAction - 'httpRequest-1' failed to execute: No attribute named 'name' is defined
你可以帮我找出根本原因吗?谢谢。

这是脚本:

private val insertFeeder = csv("test_data.csv").queue

private val csvHeader = GeneralUtil.readFirstLine(""test_data.csv"")

private val httpConf = http .baseURL("http://serviceURL") .disableFollowRedirect .disableWarmUp .shareConnections

private var httpReq = http("insert_request") .post("/insert")

for (i <- 0 to 99) {

val paramsInArray = csvHeader.split(",")
for (param <- paramsInArray) {

  if (param.equalsIgnoreCase("name")) {
    httpReq = httpReq.formParam(("name" + "[" + i +"]").el[String] , "${name}")
  }

  if (param.equalsIgnoreCase("url")) {
    httpReq = httpReq.formParam(("url" + "[" + i +"]").el[String] , "${url}")
  }

  if (!param.equalsIgnoreCase("name") && !param.equalsIgnoreCase("url")) {
    val firstArg = param + "[" + i + "]"
    val secondArg = "${" + param + "}"
    httpReq = httpReq.formParam(firstArg, secondArg)
  }
}
}

private val scn = scenario("test_scn") .feed(insertFeeder, 100) .exec(httpReq)

setUp( scn.inject( constantUsersPerSec(1) during (1200 seconds) ).protocols(httpConf) ).assertions(global.failedRequests.count.lte(5))

test_data.csv中的数据是:

name,url,price,size,gender

image_1,http://image_1_url,100,xl,male

image_2,http://image_2_url,90,m,female

image_3,http://image_3_url,10,s,female

...

image_2000,http://image_2000_url,200,xl,male

顺便说一句,如果我只处理1行,那么效果会很好。

1 个答案:

答案 0 :(得分:0)

再次阅读文档,并解决了问题。如果同时提供多个记录,则属性名称将以1为后缀。

https://gatling.io/docs/current/session/feeder/#csv-feeders