Skip to main content

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:

  1. First, create a new test with a request component that requires Basic Authentication. For examples, check the Sauce Labs REST API endpoints for ideas.
    Example Snippet Request
  2. Select Add Child Component below the request component.
    Add Request Header
  3. Select Basic Authentication from the list.
    Basic Auth Component
  4. Enter the details for username and password, then select Confirm.
    Basic Auth Details
  5. Once the Authentication Header appears, click Save Changes.
  6. Hold down the Ctrl key, highlight the code in the UI and Save Snippet.
    Save snippet
  7. Give the snippet a name and Save Snippet.
    Snippet name

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.

Snippet options