I am trying to configure different environment specific data in serenity.conf and trying to read them using EnvironmentVariables in my serenity bdd tests.I have below configuration in serenity.conf
environments {
dev {
restapi.baseurl = "https://dev.api.3stripes.io/"
}
stg {
restapi.baseurl = "https://stg.api.3stripes.io/"
}
default {
restapi.baseurl = "https://prod.api.3stripes.io/"
}
}
I am trying to read this in my bdd steps like this
EnvironmentVariables objEnvVar = SystemEnvironmentVariables.createEnvironmentVariables();
String baseURI = objEnvVar.getProperty("restapi.baseurl");
I am running the tests using maven command :
mvn clean verify -Denvironment=dev
But am getting null value for baseURI string.Please let me know what needs to be changed here to read the value properly.
The serenity.conf file has to be located in either src/main/resources or src/test/resources for it to be loaded.
You have to use the EnvironmentSpecificConfiguration class to read the values.
private EnvironmentVariables env;
@Test
void testMethod() {
String baseurl = EnvironmentSpecificConfiguration.from(env).getProperty("restapi.baseurl");
String basepath = EnvironmentSpecificConfiguration.from(env).getProperty("restapi.basepath");
}
My serenity.conf file looks like:
environments {
localhost {
restapi.baseurl = "https://localhost:9001"
}
uat {
restapi.baseurl = "https://uat.myco.com"
}
default {
restapi.baseurl = "https://some.host.com"
}
all {
restapi.basepath = "/path/to/api"
}
}
And I can activate the configs by running:
./gradlew -Denvironment=localhost clean test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With