https://github.com/appium/sample-code/blob/master/sample-code/examples/python/android_simple.py
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) |
|
class SimpleAndroidTests(unittest.TestCase): |
|
desired_caps['platformName'] = 'Android' |
|
desired_caps['platformVersion'] = '4.2' |
|
desired_caps['deviceName'] = 'Android Emulator' |
|
desired_caps['app'] = PATH( |
|
'../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk' |
|
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) |
|
def test_find_elements(self): |
|
el = self.driver.find_element_by_accessibility_id('Graphics') |
|
el = self.driver.find_element_by_accessibility_id('Arcs') |
|
el = self.driver.find_element_by_accessibility_id("App") |
|
els = self.driver.find_elements_by_android_uiautomator("new UiSelector().clickable(true)") |
|
self.assertGreaterEqual(12, len(els)) |
|
self.driver.find_element_by_android_uiautomator('text("API Demos")') |
|
def test_simple_actions(self): |
|
el = self.driver.find_element_by_accessibility_id('Graphics') |
|
el = self.driver.find_element_by_accessibility_id('Arcs') |
|
self.driver.find_element_by_android_uiautomator('new UiSelector().text("Graphics/Arcs")') |
|
if __name__ == '__main__': |
|
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleAndroidTests) |
|
unittest.TextTestRunner(
verbosity
=
2).run(suite)