# 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 directory 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 members' machines seamlessly.
  2. If you want to restore dump files that reside inside your project.

# {{$data}} for template data

This variable returns the JSON object specified in the Template Data tab of the test case. 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 parts of the JSON API response. This variable makes the validation of dynamic API responses much easier. Let's understand the concept of this variable by taking an example: Suppose we have an API that creates resources on the 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 the question comes, how we can test these types of responses.

With the 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.

TIP

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

# __STAR_VAR__ for XML responses

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

TIP

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