sauceclient¶
Python client library for Sauce Labs API.
Info¶
- Author: Corey Goldberg (2013-2017)
- Docs: https://sauceclient.readthedocs.io
- Releases: https://pypi.python.org/pypi/sauceclient
- Dev: https://github.com/cgoldberg/sauceclient
- License: Apache v2.0
About sauceclient¶
sauceclient is a Python client library for Sauce Labs API. You can manage a Selenium test environment and retrieve test assets from Sauce.
The API gives remote access to:
- Test Jobs & Assets (Results, Logs, Videos, Screenshots)
- Account
- Platform Information
- JavaScript Unit Tests
- Temporary Storage
- Tunnels
Note: sauceclient is not used for running tests on Sauce Labs’ services. Test execution is handled by Selenium WebDriver.
About Sauce Labs¶
Sauce Labs is a service for running remote Selenium WebDriver tests. It ghas VM’s with 800+ browser/OS combinations, allowing comprehensive cross-browser cross-platform test coverage.
Install¶
with pip:
pip install sauceclient
Example Usage¶
public access:
import sauceclient sc = sauceclient.SauceClient() status = sc.information.get_status()with authorization:
import sauceclient sc = sauceclient.SauceClient( 'sauce-username', 'sauce-access-key', ) jobs = sc.jobs.get_jobs(full=True, limit=5)
Compatibility Note¶
Due to changes in the SauceLabs REST API, some of sauceclient’s classes and methods have been changed or renamed since the pre-1.0 releases.
Python Module Reference¶
sauceclient Module¶
Sauce Labs REST API client
Copyright (c) 2013-2017 Corey Goldberg
This file is part of: sauceclient https://github.com/cgoldberg/sauceclient
License: Apache Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
Sauce Labs REST API documentation: http://saucelabs.com/docs/rest
-
class
sauceclient.
Account
(client)[source]¶ Account Methods
These methods provide user account information and management. - https://wiki.saucelabs.com/display/DOCS/Account+Methods
-
class
sauceclient.
Analytics
(client)[source]¶ Analytics Methods
These methods provide user account information and management. - https://wiki.saucelabs.com/display/DOCS/Analytics+Methods
-
get_build_trends
(start=None, end=None, time_range=None, scope=None, owner=None, status=None, pretty=False, os=None, browser=None)[source]¶
-
get_concurrency
(start=None, end=None, interval=None, time_range=None, scope=None, owner=None, status=None, pretty=False)[source]¶
-
get_error_trends
(start=None, end=None, time_range=None, scope=None, owner=None, status=None, pretty=False, os=None, browser=None)[source]¶
-
-
class
sauceclient.
Information
(client)[source]¶ Information Methods
Information resources are publicly available data about Sauce Lab’s service. - https://wiki.saucelabs.com/display/DOCS/Information+Methods
-
get_appium_eol_dates
()[source]¶ Get a list of Appium end-of-life dates. Dates are displayed in Unix time.
-
-
class
sauceclient.
JavaScriptTests
(client)[source]¶ JavaScript Unit Testing Methods
-
class
sauceclient.
Jobs
(client)[source]¶ Job Methods
-
get_auth_token
(job_id, date_range=None)[source]¶ Get an auth token to access protected job resources.
https://wiki.saucelabs.com/display/DOCS/Building+Links+to+Test+Results
-
get_job_asset_url
(job_id, filename)[source]¶ Get details about the static assets collected for a specific job.
-
-
class
sauceclient.
SauceClient
(sauce_username=None, sauce_access_key=None, apibase=None)[source]¶ SauceClient class.
Running Selenium WebDriver¶
Selenium WebDriver in Python (local and remote)¶
Requirements¶
- Python 2.7 or 3.x
- Selenium 2.x bindings (
pip install selenium
)
Selenium - Local WebDriver example¶
Let’s start with a very simple Selenium WebDriver example…
consider the following Python code:
#!/usr/bin/env python
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://saucelabs.com/test/guinea-pig')
driver.quit()
This code uses webdriver.Firefox()
, to invoke the local FireFox driver.
Selenium - Remote WebDriver example¶
Instead of running locally via webdriver.Firefox()
, we can use
webdriver.Remote()
, and have it execute from a remote machine
running Selenium Server. In this case, the Sauce Labs cloud:
#!/usr/bin/env python
from selenium import webdriver
SAUCE_USERNAME = 'your-username-string'
SAUCE_ACCESS_KEY = 'your-access-key-string'
driver = webdriver.Remote(
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX,
command_executor='http://%s:%s@ondemand.saucelabs.com:80/wd/hub' %
(SAUCE_USERNAME, SAUCE_ACCESS_KEY)
)
driver.get('http://saucelabs.com/test/guinea-pig')
id = self.driver.session_id
print 'Link to your job: https://saucelabs.com/jobs/%s' % id
driver.quit()
Running a Test From Local WebDriver¶
The following Python script executes a simple test against a remote web server. It drives the local FireFox browser:
#!/usr/bin/env python
import unittest
from selenium import webdriver
class Selenium2OnLocal(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_from_local(self):
self.driver.get('http://saucelabs.com/test/guinea-pig')
self.assertEqual('I am a page title - Sauce Labs', self.driver.title)
body = self.driver.find_element_by_css_selector('body')
self.assertIn('This page is a Selenium sandbox', body.text)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
Running a Test From Sauce Labs¶
Similar Python script as above, but now executing from Sauce Labs cloud. Notice
the use of webdriver.Remote()
as a replacement driver:
#!/usr/bin/env python
import unittest
from selenium import webdriver
SAUCE_USERNAME = 'your-username-string'
SAUCE_ACCESS_KEY = 'your-access-key-string'
class Selenium2OnSauce(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX,
command_executor='http://%s:%s@ondemand.saucelabs.com:80/wd/hub' %
(SAUCE_USERNAME, SAUCE_ACCESS_KEY)
)
def test_from_sauce(self):
self.driver.get('http://saucelabs.com/test/guinea-pig')
self.assertEqual('I am a page title - Sauce Labs', self.driver.title)
body = self.driver.find_element_by_css_selector('body')
self.assertIn('This page is a Selenium sandbox', body.text)
def tearDown(self):
id = self.driver.session_id
print 'Link to your job: https://saucelabs.com/jobs/%s' % id
self.driver.quit()
if __name__ == '__main__':
unittest.main()
\ Sort by:\ best rated\ newest\ oldest\
\\
Add a comment\ (markup):
\``code``
, \ code blocks:::
and an indented block after blank line