## How to use System Properties and Maven profiles to change Cucumber-jvm’s behaviour

In a previous post, I had shown how to use Maven profiles to execute integration tests with cucumber-jvm.

I have now updated the example to use WebDriver rather than selenium RC, and to show how to use the cucumber.options system properties to change the cucumber-jvm runtime behaviour.

To use cucumber.options and its default value, you create a variable:

that you can then use as a system variable for failsafe:

It is then straightforward to override these options using a profile to run different tags or produce different reports depending on the development cycle you are in:

It is also possible to override these options using the command line by executing:

mvn install -Dcucumber.options="--tags @foo --format pretty --monochrome"


If you need to define your own properties and want to pass them either from the command line with -D=, or from the <properties> tag, and want to be able to retrieve these system properties from your step definitions, you must add an entry in the systemPropertyVariables tag when configuring failsafe. For example, say you want to have a ui.language property, add that property to the properties tag:

<properties>
<ui.language>FR</ui.language>
. . .
<cucumber.options>--format html:target/cucumber --tags @wip,@foo</cucumber.options>
</properties>


This will give you the “default” value for your property; then add it to systemPropertyVariables:

           <plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<cucumber.options>${cucumber.options}</cucumber.options> <ui.language>${ui.language}</ui.language>
</systemPropertyVariables>
</configuration>
</plugin>


This will cause failsafe to pass on this property to the forked JVM running the tests. You can then override the “default” property either in a profile, or on the command line:

mvn install -Dui.language=EN


Note that this will work properly when cucumber-jvm 1.0.15 is released; until then you need to re-define the glue and path to features if you override cucumber.options, as setting that system properties clears all options set by the Cucumber.Options annotation.