Skip to content

Commit f2796d5

Browse files
committed
Merge pull request #68 from appium/isaac-sauce
Add base class for Sauce tests
2 parents fcc8308 + 5fcd80e commit f2796d5

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

appium/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
"""
1616
Appium Python Client
1717
"""
18+
from .saucetestcase import SauceTestCase
19+
from .saucetestcase import on_platforms

appium/saucetestcase.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
import os
17+
import sys
18+
import new
19+
from appium import webdriver
20+
from sauceclient import SauceClient
21+
22+
SAUCE_USERNAME = os.environ.get('SAUCE_USERNAME')
23+
SAUCE_ACCESS_KEY = os.environ.get('SAUCE_ACCESS_KEY')
24+
sauce = SauceClient(SAUCE_USERNAME, SAUCE_ACCESS_KEY)
25+
26+
27+
def on_platforms(platforms):
28+
def decorator(base_class):
29+
module = sys.modules[base_class.__module__].__dict__
30+
for i, platform in enumerate(platforms):
31+
d = dict(base_class.__dict__)
32+
d['desired_capabilities'] = platform
33+
name = "%s_%s" % (base_class.__name__, i + 1)
34+
module[name] = new.classobj(name, (base_class,), d)
35+
return decorator
36+
37+
38+
class SauceTestCase(unittest.TestCase):
39+
def setUp(self):
40+
self.desired_capabilities['name'] = self.id()
41+
sauce_url = "http://%s:%[email protected]:80/wd/hub"
42+
self.driver = webdriver.Remote(
43+
desired_capabilities=self.desired_capabilities,
44+
command_executor=sauce_url % (SAUCE_USERNAME, SAUCE_ACCESS_KEY)
45+
)
46+
self.driver.implicitly_wait(30)
47+
48+
def tearDown(self):
49+
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
50+
try:
51+
if sys.exc_info() == (None, None, None):
52+
sauce.jobs.update_job(self.driver.session_id, passed=True)
53+
else:
54+
sauce.jobs.update_job(self.driver.session_id, passed=False)
55+
finally:
56+
self.driver.quit()

0 commit comments

Comments
 (0)