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 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
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like