1 #coding:utf-8 2 #Import the common package 3 import os 4 import unittest 5 from appium import webdriver 6 from time import sleep 7 8 #设置路径信息 9 PATH = lambda p: os.path.abspath( 10 os.path.join(os.path.dirname(__file__), p) 11 ) 12 13 class LoginAndroidTests(unittest.TestCase): 14 def setUp(self): 15 #初始化测试平台 16 desired_caps = {} 17 desired_caps['platformName'] = 'Android' 18 desired_caps['platformVersion'] = '4.4.2' 19 desired_caps['deviceName'] = '127.0.0.1:62001' 20 #desired_caps['app'] = 'D:\apk\xx.apk' 21 desired_caps['appPackage'] = 'com.lovebizhi.wallpaper' 22 desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity' 23 self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) 24 25 26 27 def tearDown(self): 28 29 self.driver.quit() 30 31 def test_1(self): 32 #测试导航页 33 print("start test1...") 34 35 #判断是否安装爱壁纸APP 36 wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper") 37 if wallpaper: 38 #self.driver.remove_app("com.lovebizhi.wallpaper") 39 sleep(8) 40 # 点击某一壁纸图片 41 self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[4].click() 42 sleep(4) 43 # 点击设置壁纸 44 self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click() 45 sleep(5) 46 else: 47 self.driver.install_app("D:\apk\xx.apk") 48 sleep(30) 49 50 def test_2(self): 51 #测试导航页 52 print("start test2") 53 54 #判断是否安装爱壁纸APP 55 wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper") 56 #是 57 if wallpaper: 58 sleep(8) 59 # 点击某一壁纸图片 60 self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[5].click() 61 sleep(4) 62 # 点击设置壁纸 63 self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click() 64 sleep(5) 65 #否,安装 66 else: 67 self.driver.install_app("D:\apk\xx.apk") 68 sleep(30) 69 70 71 72 if __name__ == '__main__': 73 suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests) 74 unittest.TextTestRunner(verbosity=2).run(suite)