appium实例代码

来源:互联网 发布:linux创造普通用户 编辑:程序博客网 时间:2024/05/27 14:14

https://github.com/appium/sample-code/blob/master/sample-code/examples/python/android_simple.py



5428114on 10 Aug 2014
@bootstraponlinebootstraponline Add sample code from appium/appium
59 lines (41 sloc) 1.75 KB
import osfrom timeimport sleep import unittest from appiumimport webdriver # Returns abs path relative to this file and not cwdPATH= lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)) classSimpleAndroidTests(unittest.TestCase):defsetUp(self):desired_caps = {}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) deftearDown(self):# end the sessionself.driver.quit() deftest_find_elements(self):el = self.driver.find_element_by_accessibility_id('Graphics')el.click()el = self.driver.find_element_by_accessibility_id('Arcs')self.assertIsNotNone(el) self.driver.back() el = self.driver.find_element_by_accessibility_id("App")self.assertIsNotNone(el) 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")')  deftest_simple_actions(self):el = self.driver.find_element_by_accessibility_id('Graphics')el.click() el = self.driver.find_element_by_accessibility_id('Arcs')el.click() 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)