Accessing Request names in scenarios using feeder

Hi,

I have requests written in following format. BaseClass extends Simulation class and contains headers.

object NewAPIs extends BaseClass {

val request1: ChainBuilder = exec(http("POST - api/v1/analysis”)

.post(“api/v1/analysis”)

.headers(headers_1)

.body(StringBody(string = “”"{“startDate”:"${startDate}" ,“endDate”:"${endDate}"}"""))

.check(status.is(200)))

val request2: ChainBuilder = exec(http("POST - api/v1/analysis2”)

.post("api/v1/analysis2”)

.headers(headers_1)

.body(StringBody(string = “”"{“startDate”:"${startDate}" ,“endDate”:"${endDate}"}"""))

.check(status.is(200)))

}

I want to access these requests in scenario using a csv feeder. It gives error: “ Can’t cast value NewAPIs.request1 of type class java.lang.String into class io.gatling.core.session.Session”

CSV file format :

API,Start,End

NewAPIs.request1,2020/12/01,2020/12/05

NewAPIs.request2,2020/12/02,2020/12/09

NewAPIs.request1,2020/12/03,2020/12/10

Format of scenarios:

val records: Seq[Map[String, Any]] = csv(records.csv).readRecords

val scenario1 = scenario(“scenario1”)

.foreach(records, “record”) {

exec(flattenMapIntoAttributes("${record}"))

.exec(AuthenticateApis.authenticateApi2)

.exec("${API}")

}

Is there a way to execute requests in this manner?

No that’s not possible.

What you could do is route on request1 or request2 with a doSwitch.

Thanks Stéphane. Actually, I have a lot of distinct requests in the CSV, and not just two. That was just for example.

That doesn’t change anything. If you want to keep your current way of coding each request, you need a switch to pick the desired one.
Otherwise, use a generic request and make the url a feeder field.