gatling - 如果尝试处理来自 csv 数据馈送的多行,总是得到错误“未定义名为‘name’的属性”
问题描述
在我的测试脚本中,我尝试通过以下语句 处理100
来自数据馈送的行数据: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 开始。
推荐阅读
- flutter - (Flutter, dart) 如何在 Listview 中选择特定的 Card 并将图标颜色从白色切换到绿色
- java - 如何在 ActiveMQ 中 X 天后丢弃消息?
- c# - 为什么 WebDrivermanager 在设置时会出错?
- .net - 在将对象添加到 csv 之前获取对象的值
- reactjs - 等待一个元素不出现
- c++ - boost numeric_cast 可以抛出的所有异常是什么?
- api - 参数 json_data 的 Zoho Sheet API 问题
- python - 将 (Lambda) 订阅放在 CW Logs 组上
- reactjs - 我无法在 React 中更改表单中的文本
- c# - 大写对象列表c#