Creating an Authentication Snippet
A good use case for the snippets feature is building an authentication flow; you don't need 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 Add Child Component below the request component.
- Select Basic Authentication from the list.
- Enter the details for
username
andpassword
, then select Confirm. - Once the Authentication Header appears, click Save Changes.
- Hold down the Ctrl key, highlight the code in the UI and Save Snippet.
- Give the snippet a name and Save Snippet.
Consider a scenario where this authentication call will be required for all the endpoints you have to test. It makes sense for this call to be stored in the Vault so you don't have to write it every time.
Now you can choose to Call Snippet or Paste Snippet in your tests that require that authentication.