Getting Null Value When Trying to Read Environment Specific Data from Serenity. Conf
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...
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 = ""
}
stg {
restapi.baseurl = ""
}
default {
restapi.baseurl = ""
}
}
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.
1 Answer
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 = ""
}
uat {
restapi.baseurl = ""
}
default {
restapi.baseurl = ""
}
all {
restapi.basepath = "/path/to/api"
}
}
And I can activate the configs by running:
./gradlew -Denvironment=localhost clean test