Gatling 2 - issue with foreach

657 views
Skip to first unread message

Ryan Luckie

unread,
Jan 20, 2014, 1:39:09 PM1/20/14
to gat...@googlegroups.com


I am having issues with a test script. Everything seems to work fine until I reach the for loop. I am trying to perform all the actions in itemChain for each value saved to ${items} from the login response.

I receive the following error:

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

Sample Login Response

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

    ]
}


Stéphane Landelle

unread,
Jan 20, 2014, 2:08:34 PM1/20/14
to gat...@googlegroups.com
Hi,

I've just answered on SOF.

Cheers,

Stéphane


2014/1/20 Ryan Luckie <rtlu...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ryan Luckie

unread,
Jan 20, 2014, 2:22:25 PM1/20/14
to gat...@googlegroups.com
Thanks again!

Stéphane Landelle

unread,
Jan 20, 2014, 2:33:51 PM1/20/14
to gat...@googlegroups.com
My pleasure :)


2014/1/20 Ryan Luckie <rtlu...@gmail.com>
Reply all
Reply to author
Forward
0 new messages