forked from bitbar/test-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_test.py
More file actions
90 lines (77 loc) · 3.44 KB
/
Copy pathbase_test.py
File metadata and controls
90 lines (77 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
##
# For help on setting up your machine and configuring this TestScript go to
# http://docs.bitbar.com/testing/appium/
##
import os
import unittest
import subprocess
from appium import webdriver
from appium.options.common import AppiumOptions
from bitbar_utils import BitbarUtils
from device_finder import DeviceFinder
class BaseTest(unittest.TestCase):
def setUp(self):
self.appium_url = (
os.environ.get("BITBAR_APPIUM_URL") or "https://appium.bitbar.com/wd/hub"
)
bitbar_url = os.environ.get("BITBAR_URL") or "https://cloud.bitbar.com"
bitbar_apiKey = os.environ.get("BITBAR_APIKEY") or ""
bitbar_testrun_name = os.environ.get("BITBAR_TESTRUN") or "My testrun"
bitbar_app = os.environ.get("BITBAR_APP") or ""
new_command_timeout = os.environ.get("BITBAR_CMD_TIMEOUT") or "60"
bitbar_test_timeout = os.environ.get("BITBAR_TEST_TIMEOUT") or "600"
bitbar_find_device = os.environ.get("BITBAR_FINDDEVICE") or True
self.screenshot_dir = (
os.environ.get("BITBAR_SCREENSHOTS") or os.getcwd() + "/screenshots"
)
self.screenshot_count = 1
# Options to select device
# 1) Set environment variable BITBAR_DEVICE
# 2) Set device name to this python script
# 3) Do not set #1 and #2 and let DeviceFinder to find free device for
# you
self.bitbar_device = os.environ.get("BITBAR_DEVICE") or ""
self.device_finder = DeviceFinder(url=bitbar_url)
self.utils = BitbarUtils(self.screenshot_dir)
self.utils.log("Will save screenshots at: " + self.screenshot_dir)
self.capabilities = {
"appium:newCommandTimeout": new_command_timeout,
"appium:fullReset": False,
"appium:noReset": True,
"bitbar:options": {
"apiKey": bitbar_apiKey,
"testrun": bitbar_testrun_name,
"testTimeout": bitbar_test_timeout,
"findDevice": bitbar_find_device,
**({"app": bitbar_app} if bitbar_app != "" else {})
}
}
def test_sample(self):
pass
def tearDown(self):
self.utils.log("Quitting")
self.driver.quit()
def _start_webdriver(self):
self.utils.log(
"WebDriver request initiated. Waiting for response, this typically takes 2-3 mins"
)
options = AppiumOptions().load_capabilities(self.capabilities)
self.driver = webdriver.Remote(self.appium_url, options=options)
self.utils.log("WebDriver response received")
self.utils.update_driver(self.driver)
self.utils.log("Driver session id: " + self.driver.session_id)
def _find_device(self, os: str):
if os == "Android":
while self.bitbar_device == "":
self.bitbar_device = self.device_finder.available_android_device()
if "localhost" in self.appium_url:
self.api_level = subprocess.check_output(
["adb", "shell", "getprop ro.build.version.sdk"]
)
else:
self.api_level = self.device_finder.device_API_level(self.bitbar_device)
self.utils.log("Device API level is %s" % self.api_level)
else:
while self.bitbar_device == "":
self.bitbar_device = self.device_finder.available_ios_device()
self.utils.log("Starting Appium test using device '%s'" % self.bitbar_device)