Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = "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.

like image 873
Sheetal Satish Babu Avatar asked Oct 22 '25 14:10

Sheetal Satish Babu


1 Answers

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
like image 152
pards Avatar answered Oct 26 '25 19:10

pards