3.desired_caps获取
- 环境变量设置(根据个人实际目录配置)
- 查看设备名称
- package和activity的查看
launchable-activity在中间位置
4.实例 importos importunittest fromappium importwebdriver fromtime importsleep
# Returns abs path relative to this file and not cwd PATH =lambdap: os.path.abspath( os.path.join(os.path.dirname(__file__), p) )
classContactsAndroidTests(unittest.TestCase): defsetUp(self): desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '6.0' desired_caps['deviceName'] = 'HISSC6FA9LXXXXXXX' desired_caps['app'] = PATH('D:/workspace/testUI_new/app/test.apk') desired_caps['appPackage'] = 'com.xxx.xx' desired_caps['appActivity'] = 'com.xxx.xx.xxx'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
deftearDown(self): self.driver.quit()
deftest_add_contacts(self):
sleep(2) self.driver.find_element_by_id("com.xxx.xx:id/dot_001").click() self.driver.find_element_by_id("com.xxx.xx:id/newguide_01_002").click()
if__name__ =='__main__': suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests) unittest.TextTestRunner(verbosity=2).run(suite)
5.元素定位 android sdk tool所在目录 双击uiautomatorviewer.bat
id 、content-desc、class都可以使用