#! /usr/bin/env python #! -*-cording:utf-8 -*- import unittest from appium import webdriver import time #脚本初始化获取操作实例 class MyTestCase(unittest.TestCase): def setUp(self): desired_caps={} desired_caps['platformName']='Android' desired_caps['platformVersion']='7.1.1' desired_caps['deviceName']='Galaxy Note8' desired_caps['appPackage']='com.sec.android.app.popupcalculator' desired_caps['appActivity']='.Calculator ' desired_caps['unicodeKeyboard']='True' desired_caps['resetKeyboard']='False' self.driver=webdriver.Remote("http://localhost:4723/wd/hub",desired_caps) def tearDown(self): self.driver.quit() #测试的脚本 LOVE原则 @unittest.skip('Notest') def testAdd(self): number8=self.driver.find_element_by_id("bt_08") number8.click() numberadd=self.driver.find_element_by_id("bt_add") numberadd.click() number5=self.driver.find_element_by_id("bt_05") number5.click() equal=self.driver.find_element_by_id("bt_equal") equal.click() try: result=self.driver.find_element_by_id('txtCalc') value=result.text self.assertEqual(u"13",value) except Exception: print ("程序出现异常了") self.fail("程序出现异常") #Exception 处理异常 #Locate 定位一元素 # els=self.driver.find_element_by_class_name("") # self.driver.find_element_by_id("") # self.driver.scroll(els[0],els[1]) #把所有classname和els一样的元素从0-1 #operate操作一个元素 #verif验证操作的结果 #Exception处理异常的情况 # def testOtherAPI(self): # elements=self.driver.find_element_by_id("bt_08") # elements[0].click() # time.sleep(5) # print(len(elements)) # def testmoreAPI(self): self.driver.flick(100,750,100,100) #滑动屏幕 # print self.driver.current_activity #输出当前activity名字 print(self.driver.wait_activity('.Calculator',3,1)) #等待指定activity显示 time.sleep(5) def get_suite(self): suite = unittest.TestSuite() suite.addTests(MyTestCase, 'testmoreAPI') return suite if __name__ == '__main__': s = get_suite() runner=unittest.TextTestRunner(verbosity=2) runner.run(s)