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.
- A Sauce Labs account (Log in or sign up for a free trial license)
- Your Sauce Labs Username and Access Key
- In Terminal mode, enter
vi ~/.bash_profile, and then press Return.
- Press i to insert text into your profile file.
- Enter these lines:
export SAUCE_USERNAME="your Sauce username"export SAUCE_ACCESS_KEY="your Sauce access key"
- Press Esc.
- Hold Shift and press Z twice (shift+Z+Z) to save your file and quit vi.
- In the terminal, enter
- Click Start on the task bar.
- In the Search programs and fields box, enter Environment Variables.
- Click Edit the environment variables. This will open the System Properties dialog.
- Click Environment Variables. This will open the Environment Variables dialog.
- In the User variables section, click New. This will open the New System Variable dialog.
- For Variable name, enter SAUCE_USERNAME.
- For Variable value, enter your Sauce username.
- Click OK.
- Repeat 4 - 8 to set up the SAUCE_ACCESS_KEY.
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: