Linda
Linda

Reputation: 1

Alway get an error "No attribute named 'name' is defined" if try to process multiple lines from csv data feed

In my test script I try to process 100 lines data from csv data feed via following statement:

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

But I always get an error:

[ERROR] HttpRequestAction - 'httpRequest-1' failed to execute: No attribute named 'name' is defined

Could you please help me to find out the root cause? thank you.

Here is the script:

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))

And the data in test_data.csv is:

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

By the way, if I process only 1 line, it works well.

Upvotes: 0

Views: 2629

Answers (1)

Linda
Linda

Reputation: 1

Read the document again, and fixed the issue. If feed multiple records all at once, the attribute names will be suffixed from 1.

https://docs.gatling.io/reference/script/core/session/feeders/#csv-feeders

Upvotes: 0

Related Questions