Gherkin variables (legacy) - veepee-oss/gingerspec GitHub Wiki

Read this first

Starting from version 2.2.0-RC3, GingerSpec will favor the use of only one variable placeholder, and that is the ${}. You can see the main reasons for this change in the following discussion here, but, as a recap:

  • Using 4 different variables placeholders (!{}, ${}, @{} and #{}) can bring confusion on when to use one or the other.
  • StringSubstitutor is a much powerfull library, allows performing the same functions with much less code
  • Supports default values for variables
  • Support nested variables

!{}, @{} and #{} variable placeholders will continue to work normally, but they are now deprecated and will be removed in future releases, so, you have been warned!


The following information is deprecated. The !{}, @{} and #{} variable placeholders won't be supported after 2.2.0-RC3 and will be removed in future releases

Gingerspec library adds the possibility of using variables directly in the gherkin steps. These variables are most commonly used to store the result of a previous step to use it afterward or pass variables in the maven command to allow a more parametrized execution of the tests.

There are 4 types of libraries, all of them are enclosed in '{}' symbols:

  • ${} -> run-on time variables (passed via maven command)
  • !{} -> Local variable (local in the scope of the gherkin scenario)
  • #{} -> Property file variable
  • @{} -> Attribute value replacement
Variable Description Example
${VALUE} Run-on time the environment variable taking it from maven. AspectJ will proceed with value replacement. mvn verify -DCOUNTRY=es
!{VALUE} Local environment variable (defined in some previous gherkin step). This way we don't need to do more code to create to preserve some data, some response from the previous step, for instance, JSON response or some value. Then I run '!{MY_COMMAND}' locally
@{VALUE} Replaces every placeholder element, enclosed in @{} with the corresponding attribute value in local Common class (JSON
#{VALUE} Replaces the variable with the property defined in a .*properties file. example of common.properties file

wait.time=1

Example of UAT properties file

# SPAIN SACARINO CONFIGURATION
sacarino.es.bo.url=boes-uat31.privalia-test.com:80
sacarino.es.database.host=sudc1dbmysql240-21.privalia.pin
sacarino.es.database.port=3306
sacarino.es.database.name=sacarino_es
sacarino.es.database.user=root
sacarino.es.database.password=

The file that contains all common configuration for the project (environment independent configuration) must be located in /resources/configuration/common.properties.

Environment-specific configuration can be located in a separated file. This configuration can override the configuration from the common file. All environment specific configuration files can be included at runtime via maven variable, setting the 'env' to the name of the file.

For example, to use properties from the file uat.properties located in /resources/configuration/uat.properties, just pass -Denv=uat when running your tests
Given My app is running in '#{sacarino.es.bo.url}
And I wait '#{wait.time}' seconds

You can check the usage of the environment variable in the following examples:

⚠️ **GitHub.com Fallback** ⚠️