3

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.

1 Answers1

3

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
pards
  • 1,098
  • 15
  • 20
  • have you figured out a way to extract more than URL from this file? something like `my.webservice.endpoint = "https://local.host/" my.companyID = "local" my.userId = "local02" my.password = "Local@1234"` – 3xt May 13 '21 at 16:42