# Types of Hook
vREST NG provides two categories of hooks:
- Local Hooks:
Local hooks are executed only when they are linked with the test case explicitly. And the test case is only marked as passed when its own assertions are passed and also if there are any associated local hooks and assertions of those linked local hooks are also passed. These hooks are useful in doing microservices testing. Two types of hooks come under local hooks.
- Pre Test Case Local Hooks
- Post Test Case Local Hooks
- Non Local Hooks:
Hooks that cannot be linked to test cases explicitly are known as Non Local hooks. These hooks don't have any direct impact on the test case result. The following hooks come under non-local hooks.
- Pre Test Run Hooks
- Post Test Run Hooks
- Pre Test Suite Hooks
- Post Test Suite Hooks
- Pre Test Suite Iteration Hooks
- Post Test Suite Iteration Hooks
- Pre Test Case Hooks
- Post Test Case Hooks
- Pre Test Case Iteration Hooks
- Post Test Case Iteration Hooks
Now, let's discuss all types of hooks in detail. vREST NG provides the following types of hooks:
- Pre Test Run Hooks
- This type of hook will be executed just after the creation of the test run and before the execution of test cases.
- Example use cases:
- This can be useful in setting up resources in your ecosystem tools. e.g. Creating a test run in Test Rail.
- This can be useful in setting cookie-based authentication to third-party tools. (Note: Authorization can also be configured via Configuration Tab >> Authorizations, similar to test cases.).
- A special variable
{{$tr}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Id of the stored Test Run if vREST NG Dashboard service is enabled otherwise random id "name": "<String>", //Name of the test run (date and time information) "createdAt": "<String>",//Test Run Creation Date and Time "executionSource": "<String>", //Execution Source, values can be one of APP or CLI "environment": "<String>", //Test Environment name configured in vREST NG "executor": { //if user is logged in into vREST NG "name": "<String>", //Test Run Executor name "email": "<String>" //Test Run executor email } } }
- Post Test Run Hooks
- This type of hook will be executed after the test run execution completes.
- Example use cases:
- This can be useful in notifying the status of the test run to your team via slack, hipchat, etc.
- This can be useful in triggering jobs on the continuous integration server if there are no failed test cases.
- This is the most widely used hook.
- A special variable
{{$tr}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Id of the stored Test Run if vREST NG Dashboard service is enabled otherwise random id "name": "<String>", //Name of the test run (date and time information) "createdAt": "<String>",//Test Run Creation Date and Time "executionSource": "<String>", //Execution Source, values can be one of APP or CLI "environment": "<String>", //Test Environment name configured in vREST NG "executor": { //if user is logged in into vREST NG "name": "<String>", //Test Run Executor name "email": "<String>" //Test Run executor email } }, "result": { "totalCount": "<Number>", //Total number of test cases "failedCount": "<Number>", //Count of failed test cases "passedCount": "<Number>", //Count of passed test cases "notExecutedCount": "<Number>", //Count of not executed test cases "notRunnableCount": "<Number>", //Count of not runnable test cases "executionTime": "<Number>", //Total execution time of the test run "remarks": "<String>", //Remarks if any "resultLink": "<String>" //Link to view the results of test cases in the test run } }
- Pre Test Suite Hooks
- This type of hook will be executed just before the execution of the test suite.
- In case of parent entity iterations, the event will be emitted multiple times.
- A special variable
{{$ts}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Id of the test suite "name": "<String>", //Name of the test suite "description": "<String>", //Description of the test suite "tags": ["<String>"], //tags associated with test suite "isRunnable": "<Boolean>", //flag whether test suite was runnable or not "condition": "<Boolean>", //flag corresponding to test suite condition "loopSource": "<String>", //Loop source property of the test suite. "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "$data": { //Any custom data that you have provided to the test suite in the `testsuite.json` file }, "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Post Test Suite Hooks
- This type of hook will be executed after the test suite execution completes.
- In case of parent entity iterations, the event will be emitted multiple times.
- A special variable
{{$ts}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Name of the test suite "name": "<String>", //Name of the test suite "description": "<String>", //Description of the test suite "tags": ["<String>"], //tags associated with test suite "isRunnable": "<Boolean>", //flag whether test suite was runnable or not "condition": "<Boolean>", //flag corresponding to test suite condition "loopSource": "<String>", //Loop source property of the test suite. "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "$data": { //Any custom data that you have provided to the test suite in the `testsuite.json` file }, "result": { "isExecuted": "<Boolean>", //true if any of the associated test case is executed, false otherwise. "isPassed": "<Boolean>", //true if all of the associated test cases are passed, false otherwise. "executionTime": "<Number>" //Total execution time of the test suite in milliseconds }, "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Pre Test Suite Iteration Hooks
- This type of hook will be executed for each iteration of the test suite if the loop source is configured.
- Otherwise it will be executed only once before the test suite execution. In case of parent entity iterations, the event will be emitted multiple times.
- A special variable
{{$ts}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Id of the test suite "name": "<String>", //Name of the test suite "description": "<String>", //Description of the test suite "tags": ["<String>"], //tags associated with test suite "isRunnable": "<Boolean>", //flag whether test suite was runnable or not "condition": "<Boolean>", //flag corresponding to test suite condition "loopSource": "<String>", //Loop source property of the test suite. "loopIndex": "<Number>", //loop iteration number (starting from 0) which is being executed "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "$data": { //Any custom data that you have provided to the test suite in the `testsuite.json` file }, "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Post Test Suite Iteration Hooks
- This type of hook will be executed for each iteration of the test suite if the loop source is configured.
- Otherwise it will be executed only once after the test suite execution. In case of parent entity iterations, the event will be emitted multiple times.
- A special variable
{{$ts}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Name of the test suite "name": "<String>", //Name of the test suite "description": "<String>", //Description of the test suite "tags": ["<String>"], //tags associated with test suite "isRunnable": "<Boolean>", //flag whether test suite was runnable or not "condition": "<Boolean>", //flag corresponding to test suite condition "loopSource": "<String>", //Loop source property of the test suite. "loopIndex": "<Number>", //loop iteration number (starting from 0) which is being executed "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "$data": { //Any custom data that you have provided to the test suite in the `testsuite.json` file }, "result": { "isExecuted": "<Boolean>", //true if any of the associated test case is executed, false otherwise. "isPassed": "<Boolean>", //true if all of the associated test cases are passed, false otherwise. "executionTime": "<Number>" //Total execution time of the test suite in milliseconds }, "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Pre Test Case Hooks
- This type of hook will be executed just before the execution of the test case.
- If the loop source is configured in the test case then also this hook will be executed once before the first iteration.
- A special variable
{{$tc}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Test Case Id "summary": "<String>", //Test Case summary "externalId": "<String>",//External Id of the test case if defined "index": "<Number>", //Current test case position starting with 1 "loopSource": "<String>", //Loop source property of the test case. "tags": ["<String>"], //tags associated with test case "isRunnable": "<Boolean>", //flag whether test case was runnable or not "polling": "<Boolean>", //flag whether test case was marked as polling test case or not "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "request": { //Test Case request definition as specified by user "method": "<String>", //Test Case request method, value can be one of GET, POST, PUT, PATCH, DELETE, OPTIONS. "url": "<String>", //Test Case URL "queryParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": { "type": "<BODY_TYPE>", //body type can be one of "form-urlencoded", "json", "xml", "text", "others" "formParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "content": "<String>" } }, "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Post Test Case Hooks
- This type of hook will be executed after the test case execution completes.
- If the loop source is configured in the test case then this hook will be executed once all the iterations are executed.
- A special variable
{{$tc}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Test Case Id "summary": "<String>", //Test Case summary "externalId": "<String>",//External Id of the test case if defined "index": "<Number>", //Current test case position starting with 1 "loopSource": "<String>", //Loop source property of the test case. "tags": ["<String>"], //tags associated with test case "isRunnable": "<Boolean>", //flag whether test case was runnable or not "polling": "<Boolean>", //flag whether test case was marked as polling test case or not "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "request": { //Test Case request definition as specified by user "method": "<String>", //Test Case request method, value can be one of GET, POST, PUT, PATCH, DELETE, OPTIONS. "url": "<String>", //Test Case URL "queryParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": { "type": "<BODY_TYPE>", //body type can be one of "form-urlencoded", "json", "xml", "text", "others" "formParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "content": "<String>" } }, "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } }, "result": { "isExecuted": "<Boolean>", //true if a single iteration is executed for the test case, false otherwise. "isPassed": "<Boolean>" //true if all of the iterations are passed for this test case, false otherwise. } }
- Pre Test Case Iteration Hooks
- This type of hook will be executed for each iteration of the test case if the loop source is configured.
- Otherwise it will be executed only once before the test execution.
- A special variable
{{$tc}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Test Case Id "summary": "<String>", //Test Case summary "externalId": "<String>",//External Id of the test case if defined "index": "<Number>", //Current test case position starting with 1 "loopSource": "<String>", //Loop source property of the test case. "loopIndex": "<Number>", //loop iteration number (starting from 0) which is being executed "tags": ["<String>"], //tags associated with test case "isRunnable": "<Boolean>", //flag whether test case was runnable or not "polling": "<Boolean>", //flag whether test case was marked as polling test case or not "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "request": { //Test Case request definition as specified by user "method": "<String>", //Test Case request method, value can be one of GET, POST, PUT, PATCH, DELETE, OPTIONS. "url": "<String>", //Test Case URL "queryParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": { "type": "<BODY_TYPE>", //body type can be one of "form-urlencoded", "json", "xml", "text", "others" "formParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "content": "<String>" } }, "$data": "<OBJECT>", //Template Data "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Post Test Case Iteration Hooks
- This type of hook will be executed for each iteration of the test case if the loop source is configured.
- Otherwise it will be executed only once after the test execution.
- This hook is different from
post-test-case-hook
as it contains detailed information regarding test case execution details and assertions summary report. - This is the most used hook and can be useful in logging defects in your defect tracking tools with all the debug information. e.g. Log defects in JIRA whenever a test case or test case iteration fails.
- A special variable
{{$tc}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Test Case Id "summary": "<String>", //Test Case summary "externalId": "<String>",//External Id of the test case if defined "index": "<Number>", //Current test case position starting with 1 "loopSource": "<String>", //Loop source property of the test case. "loopIndex": "<Number>", //loop iteration number (starting from 0) which is being executed "tags": ["<String>"], //tags associated with test case "isRunnable": "<Boolean>", //flag whether test case was runnable or not "polling": "<Boolean>", //flag whether test case was marked as polling test case or not "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "request": { //Test Case request definition as specified by user "method": "<String>", //Test Case request method, value can be one of GET, POST, PUT, PATCH, DELETE, OPTIONS. "url": "<String>", //Test Case URL "queryParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": { "type": "<BODY_TYPE>", //body type can be one of "form-urlencoded", "json", "xml", "text", "others" "formParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "content": "<String>" } }, "$data": "<OBJECT>", //Template Data "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } }, "result": { "isExecuted": "<Boolean>", //true if a single iteration is executed for the test case, false otherwise. "isPassed": "<Boolean>", //true if all of the iterations are passed for this test case, false otherwise. "isRunnable": "<Boolean>", //true if the test case was runnable otherwise false. "assertionSummary": "<String>", //detailed assertion summary report "assertionSummaryWithColors": "<String>", //detailed assertion summary report with colors "assertionResults": [ { "source": "<String>", "property": "<String>", "operator": "<String>", "expectedValue": "<String>", "actualValue": "<any>", "isPassed": "<Boolean>" }, ... ], "resultLink": "<String>" //Link to view the result of this test case in the current test run. }, "execution": { "remarks": "<String>", "request": { //The request sent by vREST NG runner "method": "<String>", "url": "<String>", "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": "<String>" }, "response": { "statusCode": "<Number>", //status code of the API response "headers": { //response headers "[HEADER_NAME]": "[HEADER_VALUE]" }, "executionTime": "<Number>", //execution time in ms "type": "<String>", //response content type "content": "<String>" //response body received } } }
- Pre Test Case Local Hooks
- This is a local hook. In order to execute this hook, you need to set this hook in the "Local Hooks" field available in the Details tab of the test case.
- This hook is almost similar to Pre Test Case Iteration Hook.
- This type of hook will be executed for each iteration of the test case if the loop source is configured.
- Otherwise it will be executed only once before the test execution.
- A special variable
{{$tc}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Test Case Id "summary": "<String>", //Test Case summary "externalId": "<String>",//External Id of the test case if defined "index": "<Number>", //Current test case position starting with 1 "loopSource": "<String>", //Loop source property of the test case. "loopIndex": "<Number>", //loop iteration number (starting from 0) which is being executed "tags": ["<String>"], //tags associated with test case "isRunnable": "<Boolean>", //flag whether test case was runnable or not "polling": "<Boolean>", //flag whether test case was marked as polling test case or not "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "request": { //Test Case request definition as specified by user "method": "<String>", //Test Case request method, value can be one of GET, POST, PUT, PATCH, DELETE, OPTIONS. "url": "<String>", //Test Case URL "queryParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": { "type": "<BODY_TYPE>", //body type can be one of "form-urlencoded", "json", "xml", "text", "others" "formParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "content": "<String>" } }, "$data": "<OBJECT>", //Template Data "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } } }
- Post Test Case Local Hooks
- This is a local hook. In order to execute this hook, you need to set this hook in the "Local Hooks" field available in the Details tab of the test case.
- This hook is almost similar to Post Test Case Iteration Hook. The only difference is test case
result
data will not be available in this hook. - This type of hook will be executed for each iteration of the test case if the loop source is configured.
- Otherwise it will be executed only once after the test execution.
- This hook is different from
post-test-case-hook
as it contains detailed information regarding test case execution details.
- A special variable
{{$tc}}
will be available to the hook and the value of this variable will be as follows:
{ "details": { "id": "<String>", //Test Case Id "summary": "<String>", //Test Case summary "externalId": "<String>",//External Id of the test case if defined "index": "<Number>", //Current test case position starting with 1 "loopSource": "<String>", //Loop source property of the test case. "loopIndex": "<Number>", //loop iteration number (starting from 0) which is being executed "tags": ["<String>"], //tags associated with test case "isRunnable": "<Boolean>", //flag whether test case was runnable or not "polling": "<Boolean>", //flag whether test case was marked as polling test case or not "nestedLoopIndex": "<String>", //Comma separated indexes of the parent test suites "nestedLoops": [ //Loop indexes of parent test suites in detailed manner { "entityId": "<String>", //Entity Id "entityType": "<String>", //Entity Type (As of now, test suite) "loopIndex": "<Number>" //current loop index for the entity id }, ... ] }, "request": { //Test Case request definition as specified by user "method": "<String>", //Test Case request method, value can be one of GET, POST, PUT, PATCH, DELETE, OPTIONS. "url": "<String>", //Test Case URL "queryParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": { "type": "<BODY_TYPE>", //body type can be one of "form-urlencoded", "json", "xml", "text", "others" "formParams": [ { "name": "<String>", //Parameter name "value": "<String>" //Parameter value }, ... ], "content": "<String>" } }, "$data": "<OBJECT>", //Template Data "extensions": { "[EXTENSION_NAME]": { "[EXTENSION_FIELD_NAME]": "[EXTENSION_FIELD_VALUE]" } }, "execution": { "remarks": "<String>", "request": { //The request sent by vREST NG runner "method": "<String>", "url": "<String>", "headers": { "[HEADER_NAME]": "[HEADER_VALUE]" }, "body": "<String>" }, "response": { "statusCode": "<Number>", //status code of the API response "headers": { //response headers "[HEADER_NAME]": "[HEADER_VALUE]" }, "executionTime": "<Number>", //execution time in ms "type": "<String>", //response content type "content": "<String>" //response body received } } }
# Hook execution order
For a particular validation cycle, hooks are executed in the following order:
- Pre Test Run Hooks
For each Test Suite
- Pre Test Suite Hooks
For each Test Suite Iteration
(executed once in case of no loop source property set)- Pre Test Suite Iteration Hooks
For each Test Case
- Pre Test Case Hooks
For each Test Case Iteration
(executed once in case of no loop source property set)- Pre Test Case Iteration Hooks
- Pre Test Case Local Hooks
- Post Test Case Local Hooks
- Post Test Case Iteration Hooks
- Post Test Case Hooks
- Post Test Suite Iteration Hooks
- Post Test Suite Hooks
- Post Test Run Hooks