在 Gatling 中使用 formParams 的方法
Using a method for formParams in Gatling
我有一个包含 50 条记录的页面,当您保存一个值时,它会为 50 条记录中的每条记录触发 31 个表单参数。所以这意味着很多代码由于 JVM 的限制而无法编译。它也是非常可重复的代码。
所以我想创建一个这样的方法:
def formParams(recordNumber : String) = {
.formParam("DMX.DUMMY_OCCURRENCES.MENSYS." + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.1-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.2-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.3-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.4-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.5-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.6-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.7-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.13-" + recordNumber, "CDL_RECM")
.formParam("VALUE.DUMMY_FIELDS.MENSYS.13-" + recordNumber, "1")
.formParam("VALUE.DUMMY_FIELDS.MENSYS.15-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.15-" + recordNumber, "CDL_SCOR")
.formParam("VALUE.DUMMY_FIELDS.MENSYS.16-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.16-" + recordNumber, "CDL_NOTE")
.formParam("%.DUMMY_FIELDS.MENSYS.1-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.2-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.3-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.4-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.5-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.6-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.7-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.8-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.9-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.10-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.11-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.12-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.13-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.14-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.15-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.16-" + recordNumber, "")
}
然后在我的 exec 中这样调用它:
.exec(http("store OD")
.post("/urd/sits.urd/run/SIW_DMX_LITE")
.headers(headers_36)
.formParam("NKEY.DUMMY.MENSYS.1", "${SEARCHNKEY}")
.formParam("RUN_MODE.DUMMY.MENSYS.1", "ACT")
.formParam("SORT_FILTER.DUMMY_PAGER.MENSYS.1", "")
//CALL METHOD HERE......
.formParam("FIRST_VALUE.DUMMY_PAGER.MENSYS.1", "1")
.formParam("PREVIOUS_VALUE.DUMMY_PAGER.MENSYS.1", "-49")
....
}
目前无法解析第一个 .formparam
的符号
我还使用我看到的另一个示例进行了尝试:
def formParams(recordNumber : String, form : HttpRequestBuilder) = {
form
.formParam("DMX.DUMMY_OCCURRENCES.MENSYS." + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.1-" + recordNumber, "")
....
}
该方法本身没有错误,但是当我调用该方法时,它在执行代码中抛出无法解析符号错误。
有没有人有任何我可以尝试的想法?
如果您的问题是编译器堆栈深度,您可以使用 formParamMap
并传递一个 Map:
def formParams(recordNumber : String): Map[String, String] =
Map(
"DMX.DUMMY_OCCURRENCES.MENSYS." + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.1-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.2-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.3-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.4-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.5-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.6-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.7-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.13-" + recordNumber -> "CDL_RECM",
"VALUE.DUMMY_FIELDS.MENSYS.13-" + recordNumber -> "1",
"VALUE.DUMMY_FIELDS.MENSYS.15-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.15-" + recordNumber -> "CDL_SCOR",
"VALUE.DUMMY_FIELDS.MENSYS.16-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.16-" + recordNumber -> "CDL_NOTE",
"%.DUMMY_FIELDS.MENSYS.1-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.2-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.3-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.4-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.5-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.6-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.7-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.8-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.9-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.10-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.11-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.12-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.13-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.14-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.15-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.16-" + recordNumber -> ""
)
???
.exec(http("store OD")
.post("/urd/sits.urd/run/SIW_DMX_LITE")
.headers(headers_36)
.formParam("NKEY.DUMMY.MENSYS.1", "${SEARCHNKEY}")
.formParam("RUN_MODE.DUMMY.MENSYS.1", "ACT")
.formParam("SORT_FILTER.DUMMY_PAGER.MENSYS.1", "")
//CALL METHOD HERE......
.formParamMap(formParams(0))
.formParam("FIRST_VALUE.DUMMY_PAGER.MENSYS.1", "1")
.formParam("PREVIOUS_VALUE.DUMMY_PAGER.MENSYS.1", "-49")
....
}
我有一个包含 50 条记录的页面,当您保存一个值时,它会为 50 条记录中的每条记录触发 31 个表单参数。所以这意味着很多代码由于 JVM 的限制而无法编译。它也是非常可重复的代码。
所以我想创建一个这样的方法:
def formParams(recordNumber : String) = {
.formParam("DMX.DUMMY_OCCURRENCES.MENSYS." + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.1-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.2-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.3-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.4-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.5-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.6-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.7-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.13-" + recordNumber, "CDL_RECM")
.formParam("VALUE.DUMMY_FIELDS.MENSYS.13-" + recordNumber, "1")
.formParam("VALUE.DUMMY_FIELDS.MENSYS.15-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.15-" + recordNumber, "CDL_SCOR")
.formParam("VALUE.DUMMY_FIELDS.MENSYS.16-" + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.16-" + recordNumber, "CDL_NOTE")
.formParam("%.DUMMY_FIELDS.MENSYS.1-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.2-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.3-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.4-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.5-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.6-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.7-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.8-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.9-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.10-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.11-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.12-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.13-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.14-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.15-" + recordNumber, "")
.formParam("%.DUMMY_FIELDS.MENSYS.16-" + recordNumber, "")
}
然后在我的 exec 中这样调用它:
.exec(http("store OD")
.post("/urd/sits.urd/run/SIW_DMX_LITE")
.headers(headers_36)
.formParam("NKEY.DUMMY.MENSYS.1", "${SEARCHNKEY}")
.formParam("RUN_MODE.DUMMY.MENSYS.1", "ACT")
.formParam("SORT_FILTER.DUMMY_PAGER.MENSYS.1", "")
//CALL METHOD HERE......
.formParam("FIRST_VALUE.DUMMY_PAGER.MENSYS.1", "1")
.formParam("PREVIOUS_VALUE.DUMMY_PAGER.MENSYS.1", "-49")
....
}
目前无法解析第一个 .formparam
我还使用我看到的另一个示例进行了尝试:
def formParams(recordNumber : String, form : HttpRequestBuilder) = {
form
.formParam("DMX.DUMMY_OCCURRENCES.MENSYS." + recordNumber, "")
.formParam("CODE.DUMMY_FIELDS.MENSYS.1-" + recordNumber, "")
....
}
该方法本身没有错误,但是当我调用该方法时,它在执行代码中抛出无法解析符号错误。
有没有人有任何我可以尝试的想法?
如果您的问题是编译器堆栈深度,您可以使用 formParamMap
并传递一个 Map:
def formParams(recordNumber : String): Map[String, String] =
Map(
"DMX.DUMMY_OCCURRENCES.MENSYS." + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.1-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.2-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.3-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.4-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.5-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.6-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.7-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.13-" + recordNumber -> "CDL_RECM",
"VALUE.DUMMY_FIELDS.MENSYS.13-" + recordNumber -> "1",
"VALUE.DUMMY_FIELDS.MENSYS.15-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.15-" + recordNumber -> "CDL_SCOR",
"VALUE.DUMMY_FIELDS.MENSYS.16-" + recordNumber -> "",
"CODE.DUMMY_FIELDS.MENSYS.16-" + recordNumber -> "CDL_NOTE",
"%.DUMMY_FIELDS.MENSYS.1-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.2-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.3-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.4-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.5-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.6-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.7-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.8-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.9-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.10-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.11-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.12-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.13-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.14-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.15-" + recordNumber -> "",
"%.DUMMY_FIELDS.MENSYS.16-" + recordNumber -> ""
)
???
.exec(http("store OD")
.post("/urd/sits.urd/run/SIW_DMX_LITE")
.headers(headers_36)
.formParam("NKEY.DUMMY.MENSYS.1", "${SEARCHNKEY}")
.formParam("RUN_MODE.DUMMY.MENSYS.1", "ACT")
.formParam("SORT_FILTER.DUMMY_PAGER.MENSYS.1", "")
//CALL METHOD HERE......
.formParamMap(formParams(0))
.formParam("FIRST_VALUE.DUMMY_PAGER.MENSYS.1", "1")
.formParam("PREVIOUS_VALUE.DUMMY_PAGER.MENSYS.1", "-49")
....
}