Support both xml & json http message formats in same scenario


I have an API that supports both XML & JSON payloads.
If I want to load test with both these formats, is their any smart way to do that in Gatling?

What I can think of as of now is:
Create separate scenarios for xml & json and use .asXml() & .asJson() & execute them parallelly.

Is there any minimalistic approach to achieve this? like making the format parameterized so as to avoid the code duplication?

Maybe you can try this

val myApi = http("foo").post("/foo").body(StringBody("#{apiBody}"))

val scn = scenario("xml_json")
              50.0 -> feed(xmlBody).exec(myApi.asXML), // or use session to setup xml body
              50.0 -> feed(jsonBody).exec(myApi.asJSON) // or use session to setup json body

1 Like

Thanks Shoaib! This was really helpful