Reputation: 47
I create tests using Selenium WebDriver and Cucumber-jvm, built on Maven. I want to achieve next:
I want to have profiles with properties and use this properties in my steps depended on enviroments.
I've created a folder in src/test/resources
and added 2 subfolder in it: Staging
and Dev
.
In each folder I have a file config.properties
where I have saved username
.
My POM looks like :
<profiles>
<profile>
<id>staging</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
</properties>
</profile>
</profiles>
Now I want to change properties of profiles to something like this:
<properties> test/resources/dev/config.properties</properties>
<properties> test/resources/staging/config.properties</properties>
And I want when I run my test with an active staging profile in my step defs when I call:
system.getProperty("username")
I want this to return username
which is provided in staging's properties.
When I run this when dev
profile is active, I want to get dev
's property.
Upvotes: 3
Views: 2313
Reputation: 1463
My solution is like this:
Use Spring Boot external configuration. We could set up either application-{profile}.properties
or application-{profile}.yaml
according to your preference. Put the environment variables (e.g. hostname, uri, credentials etc) over there. And if we need variables for all the environments, just put them in application.properties
or application.yaml
.
Use the maven argument spring.profiles.active
to activate the profile accordingly. The following command is one use case in CI/CD:
mvn clean verify -Dspring.profiles.active={profile} ..........
Upvotes: 0
Reputation: 14782
Add properties to your profiles, e.g:
<propertiesFile>staging.properties</propertiesFile>
<propertiesFile>dev.properties</propertiesFile>
src/test/resources
directly.config.properties
with one of the options described in Best practices for copying files with Maven by using ${propertiesFile}
. I prefer the Wagon Maven Plugin.UPDATE
That means: Forget about the two extra directories containing the two properties files. Put them both in src/test/resources/
and copy them according to:
staging
src/test/resources/staging.properties
copied to:
src/test/resources/config.properties
target/config.properties
depending on the phase you bind the copy process to.
dev
src/test/resources/dev.properties
copied to:
src/test/resources/config.properties
target/config.properties
depending on the phase you bind the copy process to.
Upvotes: 2