1

我遇到了测试脚本的问题。在我到达 for 循环之前,一切似乎都运行良好。我正在尝试对登录响应中保存到 ${items} 的每个值执行 itemChain 中的所有操作。

我收到以下错误:

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",
        }

    ]
}
4

1 回答 1

3

当您编写用于获取项目的 JsonPath 表达式时,您使用了默认基数,即 find (= find(0))。

如果你想提取所有这些,并得到一个序列,而不是单个元素,你必须使用 findAll:https ://gatling.io/docs/current/http/http_check/#http-check-extracting

于 2014-01-20T19:08:12.157 回答