Special Variables

vREST NG supports the following special variables:

  1. {{$projectDir}} for current project directory path
  2. {{*}} for JSON responses
  3. __STAR_VAR__ for XML responses

{{$projectDir}} for current project directory path

This variable returns the current project direcory path. This can be used in several use cases:

  1. If you are doing data driven testing and you want to read the CSV file relative to the project. So, that the same tests work in other team member's machine seamlessly.
  2. If you want to restore dump files that resides inside your project.

{{$data}} for template data

This variable returns the JSON object specified in the Template Data tab of the testcase. Template Data tab is used to perform template driven testing.

{{*}} for JSON responses

This star variable is used in the expected body tab to ignore some part of the JSON API response. This variables makes the validation of dynamic API responses much easier. Lets understand the concept of this variable by taking an example: Suppose we have an API which creates resource on server and returns the following JSON response:

{
  "id": "54a79b704cba8d5328d087f5",
  "resource_name": "testcase",
  "resource_url": "http://vrest.io/i/demo/m/RVD/create_resource",
  "resource_description": "This API creates a resource on the server",
  "meta": {
    "created_at": "2015-01-03T07:41:21.000Z"
  }
}

Here "id" and "created_at" are dynamic fields, which we do not know the values in advance. Now question comes, how we can test these type of responses.

With Star variable, we can write our expected body like this:

{
  "id": "{{*}}",
  "resource_name": "testcase",
  "resource_url": "http://vrest.io/i/demo/m/RVD/create_resource",
  "resource_description": "This API creates a resource on the server",
  "meta": {
    "created_at": "{{*}}"
  }
}

vREST will simply replace this special variable with the actual values received before response validation. You can simply use the built-in response validator "Default Validator" for the test case.

For more validation scenarios on this special variable, please read through JSON Response Validation.

__STAR_VAR__ for XML responses

Similar to {{*}} variable, STAR_VAR is used to ignore the dynamic parts of XML API response.

For more validation scenarios on this special variable, please read through XML Response Validation.