mirror of
https://github.com/appium/appium.git
synced 2026-01-14 14:19:56 -06:00
Added sauce pass/fail reporting to the python example.
This commit is contained in:
@@ -5,12 +5,18 @@ set to your Sauce Labs username and access key."""
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import httplib
|
||||
import base64
|
||||
from random import randint
|
||||
from selenium import webdriver
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
SAUCE_USERNAME=os.environ.get('SAUCE_USERNAME')
|
||||
SAUCE_ACCESS_KEY=os.environ.get('SAUCE_ACCESS_KEY')
|
||||
|
||||
base64string = base64.encodestring('%s:%s' % (SAUCE_USERNAME, SAUCE_ACCESS_KEY))[:-1]
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
@@ -34,6 +40,16 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
rndNum = randint(0, 10)
|
||||
elem.send_keys(rndNum)
|
||||
self._values.append(rndNum)
|
||||
|
||||
def _set_test_status(self, jobid, passed=True):
|
||||
# Report the status of your test to Sauce
|
||||
body_content = json.dumps({"passed": passed})
|
||||
connection = httplib.HTTPConnection("saucelabs.com")
|
||||
connection.request('PUT', '/rest/v1/%s/jobs/%s' % (SAUCE_USERNAME, jobid),
|
||||
body_content,
|
||||
headers={"Authorization": "Basic %s" % base64string})
|
||||
result = connection.getresponse()
|
||||
return result.status == 200
|
||||
|
||||
def test_ui_computation(self):
|
||||
# populate text fields with values
|
||||
@@ -43,7 +59,11 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
buttons[0].click()
|
||||
# is sum equal ?
|
||||
texts = self.driver.find_elements_by_tag_name("staticText")
|
||||
self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])
|
||||
try:
|
||||
self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])
|
||||
self._set_test_status(self.driver.session_id, True)
|
||||
except:
|
||||
self._set_test_status(self.driver.session_id, False)
|
||||
|
||||
def tearDown(self):
|
||||
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
|
||||
|
||||
Reference in New Issue
Block a user