I’m new to Gatling and initially used Scala for the load test but now want to go ahead with Java as the compiler is much faster. And therefore I want to convert the below Scala code that I had written earlier to Java.
Scenarios in Loop
import io.gatling.http.Predef.*
import io.gatling.core.Predef.*
import io.gatling.core.structure.PopulationBuilder
import scala.collection.immutable.ArraySeq
import scala.collection.mutable
import scala.concurrent.duration.*
import scala.language.postfixOps
class personalDetails extends Simulation {
// Protocol
val httpProtocol = http.baseUrl("https://morpheus.uat.creditsaison.xyz")
.contentTypeHeader("application/json")
.header("requestingSub", "5317f163-448d-48f2-8f30-900cdd669288")
.authorizationHeader("Basic QGRNMU46UEAkJFcwckQ=")
var users = 100
var i = 0
// Scenario
def scnList() = {
var scnList = List.empty[PopulationBuilder]
for (_ <- 0 to 2) yield {
val injectionProfile = users match {
case 100 => rampUsers(5).during(1)
case 200 => rampUsers(10).during(1)
case 300 => rampUsers(15).during(1)
}
val scn = scenario(s"Personal Details ${users} Users")
.exec(
http("Personal Details API")
.post("/api/v1/appForm")
.check(status.is(424))
.body(RawFileBody("./src/test/resources/requestBody/personaldetails.json")).asJson
)
.inject(injectionProfile)
scnList :+= scn
users += 100
}
scnList
}
// Setup
setUp(
scnList(): _*
).protocols(httpProtocol)
}
I have already tried it but the code that it is generating is not working
What did you try and what is “not working”?
Is it specifically with gatling, or is it common code from scala and java (and a better question for one or the other forum)?
Sorry, but it doesn’t make sense in the topic.
Your working scala code doesn’t contain any nothingFor.
So, it isn’t the issue you mentioned.
If your issue is with chaining OpenInjectionSteps, this is definitely an another issue.
Do you know that injectOpen method can take either several OpenInjectionSteps (variadic) or a List<OpenInjectionStep>? Perhaps do you need the later as your injectionProfile variable.
Usually, we advise people to split the scenario definition (what a single user should do) from the injection profile.
@sbrevet Thanks for the guidance !!
I’ll try using the List of OpenInjectionStep
And we need scenarios to be executed separately and same should be listed in the report for analysis that’s why we are using loop for generating scenarios.