我遇到测试脚本问题。在我到达for循环之前,一切似乎都能正常工作。我正尝试在itemChain中为登录响应中保存到$ {items}的每个值执行所有操作。
我收到以下错误:
12:08:30.460 [ERROR] i.g.c.a.InnerWhile - Could not evaluate condition: Can't cast value item1 of type class java.lang.String into interface scala.collection.Seq, exiting loop
LoginScenario.scala
package stressTesting
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import Headers._
import scala.concurrent.duration._
import bootstrap._
import io.gatling.core.session.Expression
object LoginScenario {
val itemChain =
exec(
http("Test Connection")
.post("/inbrowser/connectionCheck.html?1390234478703")
.headers(post_header)
.check(status.is(200))
)
.pause(500 milliseconds, 2 seconds)
.exec(
http("Save Response")
.post("/api/tde/testresponse/save/${item}")
.body(ELFileBody("saveResponseTemplate.json")).asJSON
.headers(post_header)
.check(status.is(200))
)
.pause(500 milliseconds, 2 seconds)
.exec(
http("Save Event")
.post("/api/tde/log/testevent/${testPartToken}")
.body(ELFileBody("saveEventTemplate.json")).asJSON
.headers(post_header)
.check(status.is(200))
)
.pause(500 milliseconds, 2 seconds)
.exec(
http("Heartbeat")
.post("/api/tde/heartbeat/${testPartToken}")
.body(ELFileBody("heartbeatTemplate.json")).asJSON
.headers(post_header)
.check(status.is(200))
)
.pause(500 milliseconds, 2 seconds)
val scn = scenario("Login")
.feed(csv("user_credentials.csv"))
.exec(
http("Login")
.post("/api/tde/login/test")
.body(ELFileBody("loginTemplate.json")).asJSON
.headers(post_header)
.check(status.is(200))
.check(jsonPath("$.testToken").saveAs("testToken"))
.check(jsonPath("$.testPartToken").saveAs("testPartToken"))
.check(jsonPath("$.items[*].identifier").saveAs("items"))
.check(jsonPath("$.items[*].assets[*].name").saveAs("assets"))
)
.exec(
http("Get Test")
.post("/api/tde/test/${testToken}")
.headers(post_header)
.check(status.is(200))
)
.exec(
http("Get Test Part")
.post("/api/tde/testpart/${testPartToken}")
.headers(post_header)
.check(status.is(200))
)
.exec(
http("Get Items")
.post("/api/tde/item/${testPartToken}/${items}")
.headers(post_header)
.check(status.is(200))
)
.foreach("${items}", "item"){itemChain }
.exec(
http("Close Test")
.post("/api/tde/closetestpart/TIMEOUT/${testPartToken}")
.body(ELFileBody("closeTestPartTemplate.json")).asJSON
.headers(post_header)
.check(status.is(200))
)
}
示例登录响应
{
"firstName": "User1",
"lastName": "Test1",
"testToken": "12345",
"testPartToken": "4567",
"test": {
"identifier": "abc",
"testName": "",
"title": "",
"level": "",
"program": "asdf",
"contentArea": "",
"sessionStatus": "IN_PROGRESS",
"items": [
{
"identifier": "item1",
},
{
"identifier": "item2",
},
{
"identifier": "item3",
}
]
}
答案 0 :(得分:2)
当您编写用于获取项目的JsonPath表达式时,您使用了默认基数,即find(= find(0))。
如果你想要提取所有这些,并获得一个序列,而不是一个元素,你必须使用findAll:https://github.com/excilys/gatling/wiki/Checks#wiki-extracting