NOTE: This repository is now deprecated. Please see the Demo Python project for up-to-date code samples.
This code is meant for actual py.test users with aspirations beyond running unittest style tests using py.test. It demonstrates the use of py.test fixtures in conjunction with Selenium and SauceLabs.
This code is provided on an "AS-IS” basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. Your tests and testing environments may require you to modify this framework. Issues regarding this framework should be submitted through GitHub. For questions regarding Sauce Labs integration, please see the Sauce Labs documentation at https://wiki.saucelabs.com/. This framework is not maintained by Sauce Labs Support.
-
Global Dependencies
- Install Python
- Or Install Python with Homebrew
$ brew install python
- Install pip for package installation
-
Sauce Credentials
- In the terminal export your Sauce Labs Credentials as environmental variables:
$ export SAUCE_USERNAME=<your Sauce Labs username> $ export SAUCE_ACCESS_KEY=<your Sauce Labs access key>
-
Project
- The recommended way to run your tests would be in virtualenv. It will isolate the build from other setups you may have running and ensure that the tests run with the specified versions of the modules specified in the requirements.txt file.
$ pip install virtualenv
- Create a virtual environment in your project folder the environment name is arbitrary.
$ virtualenv venv
- Activate the environment:
$ source venv/bin/activate
- Install the required packages:
$ pip install -r requirements.txt
- The recommended way to run your tests would be in virtualenv. It will isolate the build from other setups you may have running and ensure that the tests run with the specified versions of the modules specified in the requirements.txt file.
-
Tests in Parallel:
$ py.test -s -n 2 tests
-
Dump session ids for the SauceLabs CI plugins:
$ cat $(find . -name "*.testlog")
There may be additional latency when using a remote webdriver to run tests on Sauce Labs. Timeouts or Waits may need to be increased. * Selenium tips regarding explicit waits
- A great resource to search for issues not explicitly covered by documentation.
- Test output will be captured in .testlog files as the pytest-xdist plugin has issues with not capturing stdout and stderr. You can use the following commands to output session id's for CI integration and clean up.
$ cat *.testlog
$ rm -rf *.testlog