forked from appium-boneyard/sample-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselendroid_simple.py
More file actions
60 lines (45 loc) · 1.86 KB
/
selendroid_simple.py
File metadata and controls
60 lines (45 loc) · 1.86 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
import os
from time import sleep
import unittest
from appium import webdriver
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
# think times can be useful e.g. when testing with an emulator
THINK_TIME = 5.
class SimpleSalendroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.1'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['automationName'] = "selendroid"
desired_caps['app'] = PATH(
'../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk'
)
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
# end the session
self.driver.quit()
def test_selendroid(self):
el = self.driver.find_element_by_name("Animation")
# assert el.text == "Animation"
self.assertEqual('Animation', el.text)
el = self.driver.find_element_by_class_name("android.widget.TextView")
# assert el.text == "Accessibility"
self.assertEqual('Accessibility', el.text)
el = self.driver.find_element_by_name("App")
el.click()
sleep(THINK_TIME)
els = self.driver.find_elements_by_class_name("android.widget.TextView")
# Selendroid gets all the elements, not just the visible ones
self.assertLessEqual(30, len(els))
self.driver.find_element_by_name('Action Bar')
self.driver.back()
sleep(THINK_TIME)
el = self.driver.find_element_by_name("Animation")
self.assertEqual('Animation', el.text)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleSalendroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)