Is it possible to get the existing scenario builder object by the given scenario name

let me brief what i am looking to do it.

1.they are two scenario which list out below for your reference,

val matchProxyCompany: ScenarioBuilder = scenario{
xxxx
}

val matchProxyPerson: ScenarioBuilder = scenario{
xxxx
}
  1. here i am doing mapping the string name → with the given scenario
val scenarioByName: Map[String, ScenarioBuilder] = Map(
    "matchProxyPerson" -> matchProxyPerson,
    "matchProxyCompany" -> matchProxyCompany,
  )

### sample variable for your reference
 injectionNames=matchProxyPerson
ScenarioList=Map[matchProxyPerson,1]

val injections = for {
  name <- injectionNames
  scn = scenarioByName(name)
  defaultUsers <- ScenarioList.get(name)
} yield scn.inject(atOnceUsers(defaultUsers))
  setUp(injections).protocols(gatlingVariableConfig.httpConf)
}

looking to build the below one automatically as i have given the given the string name and scenario name are same

  1. using the injectionNames
val scenarioByName: Map[String, ScenarioBuilder] = Map(
    "matchProxyPerson" -> matchProxyPerson,
    "matchProxyCompany" -> matchProxyCompany,
  )

for example - sample code

// trying to get the existing scenario object by the it string name
for (int i=0,i>injectionNames.length,i++)
{
val scenarioByName: Map[String, ScenarioBuilder] = Map(
    injectionNames[i] -> scenarobuilder.getobject[injectionNames[i]],
  )
}

i would appreciate that if you pour some suggestion

Sorry, I don’t get it.

Thanks for your time and prompt reply,

i have two scenario,

  1. matchProxyPerson
  2. matchProxyCompany

our script is designed such a way, we can execute both scenario as individual scenario, scenario selections are given to injectionNames

example 1, want to run “matchProxyPerson” scenario for test, i will pass the below value

injectionNames=matchProxyPerson

example 2, want to run the both scenarios, i will pass the two values

injectionNames=matchProxyPerson,matchProxyCompany

Based on the number of items in “injectionNames”. - variable

below codes will generation the injections

val injections = for {
name ← injectionNames
scn = scenarioByName(name)
defaultUsers ← ScenarioList.get(name)
} yield scn.inject(atOnceUsers(defaultUsers))
setUp(injections).protocols(gatlingVariableConfig.httpConf)
}

let me come into the problem

below code help us to map ---------
scenarioName in string object —> scenarioName in scenario builder

val scenarioByName: Map[String, ScenarioBuilder] = Map(
“matchProxyPerson” → matchProxyPerson,
“matchProxyCompany” → matchProxyCompany,
)

let say, i want to add one scenario

  1. matchProxyScoops

Hi @selva4,

What you want is a way to parse your injectionNames variable into an Iterable?

So a question about string manipulation in scala?

What about split?

If so, this is not a question for our Gatling community.

Otherwise, magically find all available scenarii and their name, it’s either impossible or only by reflection and again, out of scope of Gatling community.

Cheers!

i would need to make one more entry here

val scenarioByName: Map[String, ScenarioBuilder] = Map(
“matchProxyPerson” → matchProxyPerson,
“matchProxyCompany” → matchProxyCompany,
“matchProxyScoops” → matchProxyCompany
)

what i am looking here and below code should be automated when we add a new scenario

val scenarioByName: Map[String, ScenarioBuilder] = Map(
“matchProxyPerson” → matchProxyPerson,
“matchProxyCompany” → matchProxyCompany,
“matchProxyScoops” → matchProxyCompany
)

@sbrevet thanks and will look into reflection topic

Hey there,

Can I ask whether or not it would be easier to develop in Java rather than Scala?

All the best,
Pete