LEFT | RIGHT |
(no file at all) | |
| 1 import base64 |
| 2 import httplib |
| 3 import json |
| 4 import os |
| 5 import selenium |
| 6 import selenium.webdriver |
| 7 import unittest |
| 8 |
| 9 ie = dict(selenium.webdriver.DesiredCapabilities.INTERNETEXPLORER) |
| 10 ie['platform'] = 'Windows 2012' |
| 11 ie['version'] = '10' |
| 12 |
| 13 chrome = dict(selenium.webdriver.DesiredCapabilities.CHROME) |
| 14 chrome['platform'] = 'Linux' |
| 15 # The saucelabs.com folks recommend using the latest version of Chrome because |
| 16 # new versions come out so quickly, therefore there is no version specified |
| 17 # here. |
| 18 |
| 19 firefox = dict(selenium.webdriver.DesiredCapabilities.FIREFOX) |
| 20 firefox['platform'] = 'Linux' |
| 21 firefox['version'] = '18' |
| 22 |
| 23 browser_capabilities = dict(ie=ie, chrome=chrome, firefox=firefox) |
| 24 |
| 25 # Given the limited capabilities that the credentials impart (primarily the |
| 26 # ability to run a web browser via Sauce Labs) and that anyone can sign up for |
| 27 # their own credentials at no cost, it seems like an appropriate handling of |
| 28 # the credentials to just include them here. |
| 29 config = { |
| 30 'username': 'juju-gui', |
| 31 'access-key': '0a3b7821-93ed-4a2d-abdb-f34854eeaba3', |
| 32 } |
| 33 |
| 34 credentials = ':'.join([config['username'], config['access-key']]) |
| 35 encoded_credentials = base64.encodestring(credentials)[:-1] |
| 36 # This is saucelabs.com credentials and API endpoint rolled into a URL. |
| 37 command_executor = 'http://%s@ondemand.saucelabs.com:80/wd/hub' % credentials |
| 38 |
| 39 |
| 40 def set_test_result(jobid, passed): |
| 41 headers = {'Authorization': 'Basic ' + encoded_credentials} |
| 42 url = '/rest/v1/%s/jobs/%s' % (config['username'], jobid) |
| 43 body = json.dumps({'passed': passed}) |
| 44 connection = httplib.HTTPConnection('saucelabs.com') |
| 45 connection.request('PUT', url, body, headers=headers) |
| 46 if connection.getresponse().status != 200: |
| 47 raise RuntimeError('Unable to send test result to saucelabs.com') |
| 48 |
| 49 |
| 50 class TestCase(unittest.TestCase): |
| 51 |
| 52 def setUp(self): |
| 53 # We sometimes run the tests under different browsers, if none is |
| 54 # specified, use Chrome. |
| 55 browser_name = os.environ.get('JUJU_GUI_TEST_BROWSER', 'chrome') |
| 56 self.capabilities = browser_capabilities[browser_name].copy() |
| 57 self.capabilities['name'] = 'Juju GUI' |
| 58 self.driver = selenium.webdriver.Remote( |
| 59 desired_capabilities=self.capabilities, |
| 60 command_executor=command_executor) |
| 61 |
| 62 def run(self, result=None): |
| 63 self.last_result = result |
| 64 super(TestCase, self).run(result) |
| 65 |
| 66 def tearDown(self): |
| 67 set_test_result(self.driver.session_id, |
| 68 self.last_result.wasSuccessful()) |
| 69 self.driver.quit() |
| 70 |
LEFT | RIGHT |