The vault allows you to store variables and code snippets that can be used across an entire project.
The link to access the Vault is at the top of the window, as shown below.
The first column shows all of the projects of a company and the Global Vault. Code snippets and variables saved in a specific project are only available in that project. They are not available across projects. If a variable and/or code snippet needs to be available in more projects within the company, they must be saved to the Global Vault. The Global Vault has been built to make variables and code snippets available across all of the projects in a company.
In the snippet section, you will find all of the snippets you have created using the composer (see here for more details). Once you have saved the snippet, from the composer, you can choose whether you want to save it and make it available only for the current project, or for all the projects within the company by saving it in the Global Vault. If you already have a snippet saved for the current project but you need to make it available across all projects, you can easily export them from the current project to the Global Vault by using the import/export feature.
A good use case for the snippets feature is an authentication flow; you don’t need or want to rewrite all of the steps in every test. You just need to call the snippet that contains the authentication snippet. Another good example is integration testing, 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. For identical variable names in the global vault and in the project vault, the latter will have higher priority.
Defining a variable in the Vault is helpful when you need to use the same variable across multiple tests. This way, you don’t need to rewrite it every time. For example, a password could be saved as a variable and reused in multiple places.
Just like code snippets, if you need a variable available across multiple projects you can save it in the Global Vault or import it directly from another project.
When you open the Vault tab in the Composer, global snippets and variables are highlighted for ease of identification.
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 request 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 use the login call in the new test, we just need to click the down arrow button next to the snippet, and it will be added into the test.
Now we can call the endpoint we want to test. Let’s use the search endpoint. We pass the ‘id’ variable as a query parameter. The authorization token that we parameterized after the login call is passed in as well:
Now consider the case where we want to use the same ‘id’ in multiple tests. We don’t set the id as a global param or an input set. We add it to 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.