UI自动化代码

from appium import webdriver
import unittest
import warnings
import HTMLTestRunner


class MyTest(unittest.TestCase):
#初始化参数
def setUp(self):
warnings.simplefilter("ignore", ResourceWarning) #规避报错信息
desired_caps = {}
desired_caps['platformName'] = 'Android'#测试机型
desired_caps['platformVersion'] = '4.4.2' #机型版本
desired_caps['deviceName'] = '172.0.0.1:62001' #测试机or模拟器连接端口
desired_caps['appPackage'] = 'com.dheaven.mscapp.SIGFFCNFN' #包名
desired_caps['appActivity'] = 'com.dheaven.mscapp.SIGFFCNFN.activity.SplashActivity' #Activity
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

#登陆功能


#点击查违章进行跳转
def test_Chaweizhang(self):
self.driver.find_element_by_id("com.dheaven.mscapp.SIGFFCNFN:id/ll_chaweizhang").click()

#点击清洗服务
def test_Cleaning(self):
self.driver.find_element_by_id("com.dheaven.mscapp.SIGFFCNFN:id/ll_vehicle_cleaning").click()

def tearDown(self):
print("end")
def suite():
testSuite = unittest.TestSuite() # 构造测试集
testSuite.addTest(MyTest("test_Chaweizhang")) # 加入测试用例
testSuite.addTest(MyTest("test_Cleaning"))
return testSuite

if __name__ == '__main__':

filepath= "D:\\result.html"
fp = open(filepath, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"测试报告", description=u"用例执行情况")
runner.run(suite())
fp.close()

posted @ 2018-09-19 09:29  Test_Tencury  阅读(45)  评论(0编辑  收藏  举报