Skip to main content

Using Environment Variables for Authentication Credentials

As a best practice, we recommend setting your Sauce Labs authentication credentials as environment variables on your local system, that can then be referenced from within your tests. This provides an extra layer of security for your tests, and also enables other members of your development and testing team to write tests that will authenticate against a single account.

For a list of Sauce Connect Proxy environment variables, see Environment Variables.

What You’ll Need

Setting Up Environment Variables

Sauce Connect Proxy enviroment variables may be added to one of the user environment configuration files, such as ~/.bash_profile.

  1. Open ~/.bash_profile in your prefered text editor.
  2. Add the variables
export SAUCE_USERNAME="your Sauce username"
export SAUCE_ACCESS_KEY="your Sauce access key"
  1. Start a new shell or a new terminal.
  2. Confirm that your environment variables have been set by typing echo $SAUCE_USERNAME in your terminal. The response should be your username value.

Referencing Environment Variables in Test Scripts

Once you've set up the environment variables for your credentials, you need to reference them within the test scripts that you want to run on Sauce. You can find examples of test scripts that use environment variables for authentication in the demo directory for each language in the Sauce Labs Training repo on GitHub.

Below are examples of how to set environment variables in a given language/framework:

Authenticating with Environment Variables
loading...