Include Page |
---|
| _sauce description | _sauce description |
---|
|
This tutorial will show you how to get started with testing with Python on Sauce. setup_example_intro | | _setup_example_intro |
---|
|
Include Page |
---|
| _example_only |
---|
| _example_only |
---|
|
Prerequisites
Include Page |
---|
| _python_requirements |
---|
| _python_requirements |
---|
|
Code Example
Include Page |
---|
| _pythonsetup_codeexample_examplescript |
---|
| _pythonsetup_codeexample_example |
---|
|
Tip |
---|
|
The explicit wait method tells the browser to wait a set amount of time (in seconds) for elements to appear on the page before giving up. Using explicit waits is one of our recommended best practices. |
Analyzing the Code
If you look at the code closely, you'll see that basics for setting up a test to run on sauce are very straightforward, and really only require two elements.
...
Running the Test
- Copy the example code and save it into a file called
first_test.py
.
Make sure your username and access key are included in the URL passed through to the command_executor. - Open terminal and navigate to the directory where the file is located.
Execute the test:
Code Block |
---|
python first_test.py |
Check your dashboard and you will see that your test has just run on Sauce!
Running Local Tests
...
Running Tests in Parallel
...
See the topics under Running Tests in Parallel with Python for more information and examples of setting up popular Python testing frameworks to run tests in parallel on Sauce
Reporting on Test Results
Include Page |
---|
_python_reporting | _python_reportingYou can clone this script from the saucelabs-training
repository on GitHub: https://github.com/saucelabs-training/demo-python
Info |
---|
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:
Code Block |
---|
'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:
Code Block |
---|
$ pip install -r requirements.txt |
- Set your Sauce Labs Credentials as envrionment variables, indicated by the following lines in the script:
View Git file |
---|
path | on-boarding-modules/pytest-examples/test_module4_pytest.py |
---|
lastline | 9 |
---|
repository-id | 36 |
---|
firstline | 8 |
---|
branch | refs/remotes/origin/master |
---|
|
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:
Code Block |
---|
pytest on-boarding-modules/pytest-examples/test_module4_pytest.py |
unittest:
Code Block |
---|
python -m unittest on-boarding-modules/unittest-examples/test_module4_unittest.py |