This script provides an example of how you might configure your own automated tests to run in the Sauce Labs browser cloud. The sample test uses environment variables for authentication, assigns a tag and build number for test result management, and reports Pass/Fail status to the Sauce Labs dashboard.
Example Only
The code in this topic is presented as an example only, since your tests and testing environments may require specialized scripting. This information should be taken only as an illustration of how you could set up your tests with Sauce Labs, and is not directly supported by Sauce.
Prerequisites
- You should have a Sauce Labs account
- You should have a Selenium environment with the bindings for Python set up on the local machine where you'll launch your tests. If you need help with this, check out the ReadMe in the Python example scripts repository on GitHub.
- You should read the Best Practices for Running Tests
You will need to install the Selenium WebDriver client driver to your local Python environment
You can either download the driver from the link, or usepip
to install it.You can also optionally install the Sauce Python client, which provides features for reporting job information to the Sauce Labs dashboard.
Setup Example Script
The sample test opens the browser, navigates to the saucelabs.demo web app, and then closes the browser.
To run this script against your own app using your Sauce Labs credentials:
- Set your authentication credentials as environment variables to connect the test to your Sauce Labs account.
- Enter the URL for the web app you want to test in the place of
saucedemo.com
.
Once you've been able to run the test against your web app, check out the Platform Configurator to see more of the desired capabilities you can use when testing with Sauce.
You can clone this script from the saucelabs-training
repository on GitHub: https://github.com/saucelabs-training/demo-python
There are examples using both pytest
and unittest
frameworks, change directories to the relevant module before running your tests:
Testing with a Proxy
If you're trying to run this script from behind a VPN or a corporate proxy, you must use either IPSec or Sauce Connect Proxy. Once you've downloaded and installed the relevant software, add the following capability to the test script:
'tunnelIdentifier': '<tunnel_id>',
Running the Test
Navigate to the root project directory and use
pip
to install the latest Selenium library for use in the script:$ pip install -r requirements.txt
- Set your Sauce Labs Credentials as envrionment variables, indicated by the following lines in the script:
sauce_username = os.environ["SAUCE_USERNAME"] sauce_access_key = os.environ["SAUCE_ACCESS_KEY"]
Depending on which framework you're using, your commands may be different to run the tests. Use any of the following command based on the chosen framework:
pytest:
pytest on-boarding-modules/pytest-examples/test_module4_pytest.py
unittest:
python -m unittest on-boarding-modules/unittest-examples/test_module4_unittest.py