最近一直在忙,终于有时间来整理一下,传一个简单的用例,运行之后可以看到用例的报告,希望对大家有帮助。
HTMLTestRunner这个包网上有很多,大家可以自己下载。
1 import unittest
2 from appium import webdriver
3 from time import sleep
4 import os
5 import tempfile
6 from PIL import Image
7 import HTMLTestRunner
8 import time
9
10 class LitterTestscase(unittest.TestCase):
11 def setUp(self):
12 desired_cups={}
13 desired_cups['platformName']='Android'
14 desired_cups['platformVersion']='4.4.2'
15 desired_cups['deviceName']='DU2SSE15A9032675'
16 desired_cups['appPackage']='com.cleanmaster.mguard_cn'
17 desired_cups['appActivity']='com.keniu.security.main.MainActivity'
18 self.dr=webdriver.Remote('http://localhost:4725/wd/hub',desired_cups)
19 sleep(20)
20 # self.dr.find_element_by_id('com.cleanmaster.mguard_cn:id/im').click()
21 # sleep(5)
22 def tearDown(self):
23 self.dr.quit()
24 #垃圾清理
25 def clean_litter(self):
26 cl=self.dr.find_element_by_id('com.cleanmaster.mguard_cn:id/biw')
27 self.assertIsNotNone(cl)
28 cl.click()
29 sleep(15)
30 #如果需要清理直接清理,不需要则点击返回---垃圾清理
31 try:
32 self.dr.find_element_by_id('com.cleanmaster.mguard_cn:id/af6').click()
33 except Exception as e:
34 print(Exception, ":", e, '垃圾清理按钮')
35 self.dr.find_element_name('大师锦囊').click()
36 else:
37 sleep(15)
38 self.dr.find_element_by_name('大师锦囊').click()
39 if __name__=='__main__':
40 suite = unittest.TestSuite()
41 suite.addTest(LitterTestscase('clean_litter'))
42 #unittest.TextTestRunner(verbosity=2).run(suite)44
filename='C:\Test-ZQ\report\report.html'
45 fp=open(filename,'wb')
46 runner=HTMLTestRunner.HTMLTestRunner(
47 stream=fp,
48 title=u'result',
49 description=u'report'
50 )
51 runner.run(suite)
52 fp.close()