One of the most important requirement of any API test or any test in general is to have dependent data/objects available before we write the actual tests. In programming languages like JavaScript/Java this is usually done by writing a reusable data generator function for each module. The advantage Vibranium provides is that any test that you have written before acts as a reusable module for data generation.
Say you have a test object written for creating users and you need users to be available in the system as a dependency in another test, like for example test for assigning users into teams. In this case, all you need to do is mention the users test object in the teams test object as a dependency.
collection
[string]: The name of the collection in which the endpoint is availablescenario
[string]: The name of the scenario in which the endpoint is availableapi
[string]: The dependency endpoint namerepeat
[integer]: Number of times the endpoint is to be repeatedcache
[boolean]: Should the endpoint be cached or loaded from cache?variable
[string or object]: The variable name and path to be parsed from the endpoint responsepath
[string]: The path from which the variable is to be parsed from the dependency (to be used only if the value of 'variable' key is s string)variables
[object]: The variables to be passed to the dependencyThere are two ways to read data from the response of the dependency, If you need to read just one entry from the response, you can select either of the approaches, but if you need multiple values to be read, only the second approach works.
Using this approach, the variable
key will be a string and will have the variable name and the path
key will have the path to be parsed from response, using dot notation.
Example:
{
"variable": "userId",
"path": "response.id"
}
The limitation with this approach is that you can read only one value from the response.
Using this approach, the variable
key will be an object and will have the keys as variable names and the values as the paths that need to be parsed,
Example:
{
"variable": {
"userIds": "response.all.id",
"userNames": "response.all.name"
}
}
{
"name": "03.create_an_team",
"description": "Create a new team of a random type",
"url": "/api/v1/teams",
"method": "POST",
"variables": {
"visibility": "[PRIVATE|PUBLIC]"
},
"payload": {
"type": "{typeCode}",
"visibility": "{visibility}",
"admins": "{userIds}",
"description": {
"short": "[a-z ]{10, 255}",
"long": "{lorem_500}"
}
},
"dependencies": [
{
"api": "02.get_all_teams_types",
"variable": {
"typeCode": "response.any.code"
}
},
{
"collection": "collection_for_user_apis",
"scenario": "users_crud",
"api": "05.create_new_user",
"repeat": 5,
"cache": false,
"variable": {
"userIds": "all.id",
"userNames": "all.name"
}
}
]
}