I have a need to use different data for different environments like staging, integration and prod. The simulation code is the same but just that I have to change the data based on the environment I use. how can I achieve this using gatling?
Pass a system property and resolve it it your simulation to pick one file or the other.
Thanks for the lead, Stephen
I am having issues with setting the feeder file values based on my if condition.New to gatling so any help is appreciated.
I am trying to use a if statement to set the feeder file based on my environment url but I am not able to use the set value in my scenario
class X extends Simulation with TestConfiguration {
val httpProtocol = http.baseUrl("$BASE_URL") //BASE_URL is set in TestConfiguration
if(BASE_URL == “http://staging.com”)
{
val dataFile: String = getClass.getResource("/1.txt").getFile
}
else
{
val dataFile: String = getClass.getResource("/2.txt").getFile
}
def loadTestScenarioBuilder: ScenarioBuilder =
scenario(“POST API Tests”)
.repeat(1) {
exec(feed(csv(dataFile).random)) //this line gives an error
.exec(
http(“Verify POST endpoint “)
.post(s”/data”)
.header(“Content-Type”, “application/json”)
.header(“Accept-Encoding”,"*")
.body(StringBody("""{“dataType”: “testId”, “id”: “${Id}”}""")).asJson
.check(status.in(200)))
}
Doing this, I get dataFile not found error at the line where I load the feeder, exec(feed(csv(dataFile).random)). how can I make the dataFile value visible inside the loadTestScenarioBuilder?
-
Stephen=> Stéphane - As you’re trying to use an if statement, you should have a look at any beginner tutorial, such as https://docs.scala-lang.org/overviews/scala-book/if-then-else-construct.html#if-expressions-always-return-a-result
- Why are you trying to resolve a File? You should just resolve the classpath location String and let our feeder locate it.
Thanks Stephane, if statement returning a result worked