Our Vault feature allows you to store variables and code snippets to use in your tests in one project, or across all projects.
- An existing API Testing Project. For details on how to create one, see the Quickstart guide.
There are two types of API Testing vaults, the Company Vault and Project-specific Vault. While their UI is the same, they serve two different purposes:
The Company Vault is where you can store variables and test code snippets to use across all of your Projects. You can access this tab from your API Testing home page, where all of your Projects are listed.
The Project Vault, which you can access from within a Project, is where you can store Project-specific variables and test code snippets.
In the Variables section, you can define environment variables to use in your tests, so that you don't need to rewrite them every time.
The screenshot below shows the Company Vault; these variables are available across all projects.
You should define a variable at the Project-specific Vault when you need to use the same one across multiple tests. As an example, you could save a password here as a variable and reuse it in multiple tests.
Import Postman Collections into The Vault
Additionally, you can import variables from Postman. See here for more details.
If the same variable with the same name definition exists in both the Project Vault and Company Vault, then the value in the Project Vault will override the one in the Company Vault.
- Go into a Project.
- Click on the Vault tab.
- Select New Entry.
- Add a Key (e.g.,
- Add a Value (e.g.,
- Select Confirm.
Then in your tests, you'd reference the variable by the
Key using the following syntax:
Consider a scenario where an
/product endpoint requires a specific
id query parameter.
While this is a perfectly valid request parameter, it can be hard to manage and update if you scale out your tests. Therefore rather than continuously hard-coding this value into the Query Params field, a safer and more efficient approach is to export this value into to a variable.
Here is an example of how it could look like in the Project-specific Vault:
Now you can switch the Query Params field from String value to Variable and enter the variable name:
product_id (see the screenshot below). This way if you have multiple tests in your project using the same password.
code view example
You can also reference this parameter in Code view with the following syntax:
In the Snippets section of the Vault, you can create or import test component/code examples exist. A snippet is a test code fragment that you can create, import and store in your Vault and reuse in multiple tests. Snippet length can range from one line of code to an entire test.
Much like with variable scope, snippets saved in the [Project] Vault are only available in that Project and snippets saved in the Company Vault are available across all projects.
When you save a snippet from the Composer, it will be saved in the [Project] Vault. While you cannot save a snippet from the Composer to the Company Vault, you can export there using the import/export feature (see screenshot below).
- Log in to Sauce Labs, then click API Testing > Get Started.
- Click on a Project.
- Click on a Test.
- Click on the first component you want to include in your snippet.
- Hold down the
[SHIFT]key and click on the last component you want to include. This will highlight your snippet selection.
- Select the desired test component.
- Select the Export snippet from selection icon.
- Give the snippet a name.
- Select Save Snippet.
That's it! Now that your snippet has been created, you can use it in every test within the Project.
- Open the snippet from your Project Vault.
- Click on any of the fields and begin typing to edit the details.
- Changes are saved automagically.
For each snippet, two actions are available:
- Paste Snippet: allows you to paste the entire component inside the test, allowing you to edit as needed. The pasted components will lose any reference to the original snippet.
- Invoke Snippet: creates a Call component that will invoke the snippet. If the snippet changes, all the tests containing the Call component to that snippet will inherit the changes.
A good use case for the snippets feature is building an authentication flow; you don't need nor want to rewrite all authentication steps for every single test. Instead, call the snippet that contains these authentication details. Another good example is integration testing, where you can reuse various tests to create one larger flow.
Below is an example of how to create an Authentication Snippet.
- First, create a new test with a request component that requires basic authentication. For examples, check the Sauce Labs REST API endpoints for ideas.
- Select to the + Add Request Headers section below the request component.
- Select Basic Authentication from the list.
- Enter the details for
password, then select Save.
- Once the Authorization Header appears, highlight it in the UI, then select the Export snippet from selection icon in the toolbar.
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.
Now you can choose to insert or invoke this snippet in future tests that require a Basic Authentication header.