The vault allows you to store variables and fragments of tests (code snippets) that can be used across an entire project.
The link to access the Vault is in the top menu.
The first column shows all the projects of company. Code snippets and variables are available on a per project basis. Note: They are not available across projects. We did this for a specific reason based on customer feedback.
In the snippet section, you will find all the snippets you have created using the composer (see here for more details).
A good example for the snippets feature is an authentication flow: you don’t need to write all the steps in every test, you just need to call the snippet that contains the authentication fragment. Another good example is integration tests, where you can reuse various tests to create one larger flow.
In the variable section, you can define variables which will be part of the scope of the tests.
If a variable with the same name is defined within the test, it will override the one defined in the Vault.
Defining a variable in the vault is helpful when you need to use the same variable in different tests, in this way you don’t need to write it every time. You can also save a password as variable.
Here is a quick example on how the Vault can be used in a test.
The Authentication Snippet
First, create a new test. Go to the test list, click +New Test, enter the test name and click Compose. Once the composer appears, we need to enter the call. For this example, we will add a GET that logs in using a Basic authentication:
Consider a scenario where this login will be required for all the endpoints we have to test. It makes sense for this call to be stored in the Vault.
Select the GET, open the Vault panel and click the + button. Enter a name and description.
Now you can proceed creating the test. Once done we need to create the other tests for our API. Once again, click +New Test. Once you are in the composer, you can open the Vault panel and select the snippet we saved in the previous step.
To invoke the login call into the new test, we just need to click the down arrow button near the snippet, and it will be added into the test.
Now we can call the endpoint we want to test. Let us use the search endpoint, where we pass the ‘id’ variable as a parameter, and the token is retrieved from the login call:
Now consider the case where we want to use the same ‘id’ in multiple tests, so we do not set the id as either a global param nor as an input set. We add it in the vault instead. Save the test and exit from the composer. Click on Vault in the header and add the variable ‘id’ here:
Once done, go back to the test and check that the variable is available in the Vault panel:
Now if you launch the test you can see that the ‘id’ will be replaced with the value you have set in the Vault.