# Templates functionality

WARNING

This feature is available as part of vREST NG Pro/Enterprise version.

Templates allow you to configure re-usable test cases. This will help you to reduce your test maintenance effort drastically. Maintenance is a major problem while doing automation testing. A large amount of effort is spent in maintaining automated tests. vREST NG helps you to solve the maintenance problem by structuring your tests in a meaningful way so that your tests don't have any duplicated test logic. There are various features in the vREST NG Application that makes your test maintenance easier. Templates are one among them which further helps you to remove duplicate information in your test data. A template is identical to a test case having variables.

Let us try to understand various use cases of templates with the help of examples.

# Use Case 1:

Suppose we have the following structure of Test Suites and Test Cases.

├─ Test Suite 1
│  ├─ Login API
│  ├─ Test Case 1
│  ├─ Test Case 2
│  ├─ Test Case 3
│  ├─ ...
|
├─ Test Suite 2
│  ├─ Login API
│  ├─ Test Case 4
│  ├─ Test Case 5
│  ├─ Test Case 6
│  ├─ ...
|
├─ ...

In the above structure, in order to execute our scenarios, we have to log in to our application first through Login API. And this Login API test case is duplicated in all our test suites. And if there are some changes in the Login API then we have to change them in all the duplicated tests.

With templates, you may just create a single template for Login API and all the tests for Login API will just refer to that template. And your test case file will look like this on the file system.

{
  "$ref": "login_api"
}

This file is generated by vREST NG Application. Here login_api is the template id for the Login API template.

# Use Case 2:

You can define a template for each API spec available for your test application. And this template will contain necessary variables which you would like to manipulate. e.g. For Login API, you may configure the email and password fields as variables for input and errorMessage fields for the validation error. And your test cases will just define the variable's value to validate various positive and negative scenarios.

e.g. Your test case to validate the condition when email field is blank will look like this on the file system:

{
  "$ref": "login_api",
  "details": {
    "summary": "Validate Login API when email field is blank"
  },
  "$data": {
    "email": "",
    "password": "secret0@A",
    "errorMessage": "Email field is required."
  }
}

This file is generated by vREST NG Application.

And your test case to validate the condition when password field is invalid will look like this on the file system:

{
  "$ref": "login_api",
  "details": {
    "summary": "Validate Login API when password field contains invalid data"
  },
  "$data": {
    "email": "john.doe@example.com",
    "password": "invalid_password",
    "errorMessage": "Either email/password is invalid."
  }
}

This file is generated by vREST NG Application.

As you can see that your test case now contains only the required information which is necessary for API input and validation logic. All the test logic is now contained in the template. And that template can be re-used to validate various test conditions. It makes your test automation much more easier and maintainable.

To learn more, read the following sections:

  1. Create Templates
  2. Generate Template from test case
  3. Create test cases from Template