Created
January 20, 2012 01:37
-
-
Save santiycr/1644439 to your computer and use it in GitHub Desktop.
Sauce REST API via Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
import base64 | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
config = {"username": "your-sauce-username", | |
"access-key": "your-sauce-api-key"} | |
base64string = base64.encodestring('%s:%s' % (config['username'], config['access-key']))[:-1] | |
def set_test_status(jobid, passed=True): | |
body_content = json.dumps({"passed": passed}) | |
connection = httplib.HTTPConnection("saucelabs.com") | |
connection.request('PUT', '/rest/v1/%s/jobs/%s' % (config['username'], jobid), | |
body_content, | |
headers={"Authorization": "Basic %s" % base64string}) | |
result = connection.getresponse() | |
return result.status == 200 | |
set_test_status("your-job-id", passed=True) |
@dlai0001, using webdriver:
driver.session_id
hi, could u please tell how to send this session ID to test attribute (because i use ReportPortal and for connections SauceLabs and ReportPortal -> becuase i see that test run in ReportPortal happens earlier then driver is started and we receive this session ID
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For python 3 just replace line 11 with:
base64string = str(base64.b64encode(bytes('%s:%s' % (config['username'], config['access-key']),'utf-8')))[1:]
I also recommend you close the socket after line 19:
connection.close()