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
- A Sauce Labs account (Log in or sign up for a free trial license)
- Your Sauce Labs Username and Access Key
Setting Up Environment Variables
- Mac/Linux
- Windows
Sauce Connect Proxy enviroment variables may be added to one of the user environment configuration files, such as ~/.bash_profile
.
- Open
~/.bash_profile
in your prefered text editor. - Add the variables
export SAUCE_USERNAME="your Sauce username"
export SAUCE_ACCESS_KEY="your Sauce access key"
- Start a new shell or a new terminal.
- Confirm that your environment variables have been set by typing
echo $SAUCE_USERNAME
in your terminal. The response should be your username value.
- Open the Control Panel and click the System icon to open the System Properties dialog.
- Click Environment Variables to open the Environment Variables dialog.
- In the User variables section, click New to open the New System Variable dialog.
- For Variable name, enter SAUCE_USERNAME and for Variable value, enter your Sauce username and then click OK.
- Repeat 3-4 to set up the SAUCE_ACCESS_KEY or any other environment variable.
- Confirm that your environment variables have been set by typing
echo %SAUCE_USERNAME%
in your terminal. The response should be your username value. Then do the same for your access key.
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:
- Java
- NodeJS
- Python
- Ruby
- C#
loading...
loading...
loading...
loading...
loading...