/

Variables

Use of variables and pre-define variable sets


In most case we do not want to hard code values in our test and we want to control the value based on certain environment to run it. You can specify pre-defined variable set using a JSON file.

Pre-defined Staging Environment Variables

features/data/uat.variables.json

{
  "host": "www.uat.autokinjs.com",
  "username": "autokin"
}

For example above is our variable set, and we have 2 key-value that we can use within our test. Using the above anticipated variables, the following can be our test:

Feature: My Feature
	As Autokin tester
	I want to verify that all API are working as they should

    Scenario: Login to the system
        Given that a secure endpoint is up at {host}
        Given I set Content-Type header to application/json
        Given I set the JSON body to 
        """
        {
            "username": "{username}",
            "password": "p3dr0"
        }
        """
        When I POST /login
        Then response status code should be 200
        Then I keep the value of body path "$.sessionId" as "userSessionToken"

In the above example, we can use the variable by using curly braces to enclose our variable name, such as {host}. In the example above, we used the variable as our source for the host, and we also used another variable in the username as part of the body.

Specifying pre-define variable in runtime

./node_modules/.bin/autokin -e -v ./features/data/uat.variables.json