What You'll Need
- The SAUCE_USERNAME and SAUCE_ACCESS_KEY specific to your Sauce Labs account. You can find them by logging into saucelabs.com and going to Account > User Settings.
Setting Up Environment Variables on macOS and Linux Systems
- In Terminal mode, enter
.bash_profile, and then press Enter.
Enter these lines:
- Press Escape.
Hold Shift and press Z twice (z z) to save your file and quit
In the terminal, enter
Setting Up Environment Variables on Windows Systems
- Click Start on the task bar.
- For Search programs and fields, enter E
- 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
- For Variable value, enter your Sauce username.
- Click OK.
- Repeat 4 - 8 to set up the
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: