forked from bitbar/test-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitBarSampleAppTest.py
More file actions
66 lines (53 loc) · 2.46 KB
/
Copy pathBitBarSampleAppTest.py
File metadata and controls
66 lines (53 loc) · 2.46 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
#
# Example script for parallel Appium tests
#
import unittest
from time import sleep
import xmlrunner
from appium.webdriver.common.appiumby import AppiumBy
from selenium.common.exceptions import WebDriverException
from BitBarAppiumTest import BitBarAppiumTest, log
class BitBarSampleAppTest(BitBarAppiumTest):
def setUp(self):
# BitBarAppiumTest takes settings (local or cloud) from environment variables
super(BitBarSampleAppTest, self).setUp()
# Test start.
def test_the_app(self):
driver = self.get_driver() # Initialize Appium connection to device
sleep(10) # Wait that the app loads
log("Start!")
# Use this to get detected screen hierarchy
# print self.driver.page_source
if self.isAndroid():
try:
log("Taking screenshot 0_appLaunch.png")
driver.save_screenshot(self.screenshot_dir + "/0_appLaunch.png")
log("Clicking element 'Use Testdroid Cloud'")
elem = self.driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,
'new UiSelector().text("Use Testdroid Cloud")')
self.assertTrue(elem)
elem.click()
sleep(2) # always sleep before taking screenshot to let transition animations finish
log("Taking screenshot: 1_radiobuttonPressed.png")
driver.save_screenshot(self.screenshot_dir + "/1_radiobuttonPressed.png")
log("Sleeping 3 before quitting WebDriver")
sleep(3)
except WebDriverException:
log("Android testrun failed..")
else: # iOS
try:
log("Taking screenshot 0_appLaunch.png")
driver.save_screenshot(self.screenshot_dir + "/0_appLaunch.png")
log("Finding buttons")
buttons = driver.find_elements(AppiumBy.CLASS_NAME, 'UIAButton')
log("Clicking button [2] - Radiobutton 2")
buttons[2].click()
log("Taking screenshot 1_radiobuttonPressed.png")
driver.save_screenshot(self.screenshot_dir + "/1_radiobuttonPressed.png")
log("Sleeping 3 before quitting WebDriver")
sleep(3)
except WebDriverException:
log("iOS testrun failed..")
# Test end.
if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))