一个标准的单元UI自动化测试代码案例
Posted paulwang2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个标准的单元UI自动化测试代码案例相关的知识,希望对你有一定的参考价值。
import unittest import htmlTestRunner import time from ios_login import driver # from appium.webdriver.common.mobileby import MobileBy ReferenceNumber="2072109" #require unique customerName="paul.wang" mobile="13138153397" Phone="029-88888888" emailadd="[email protected]" class addCustomers(unittest.TestCase): u"创建一个客户的测试用例" def setUp(self): pass def addCustomers(self): u"创建客户信息函数" driver.find_element_by_name("Bindo Payment").click() driver.implicitly_wait(60) driver.find_element_by_accessibility_id("nav side bar btn 20x20").click() driver.implicitly_wait(2) driver.find_element_by_accessibility_id("sidebar_customers").click() driver.implicitly_wait(1) driver.find_element_by_accessibility_id("blue plus 20x20").click() driver.implicitly_wait(1) driver.find_element_by_ios_predicate("value==‘Full Name‘").send_keys(customerName) #只有value值的时候可以用iOS谓词(谓词表达式为value的表达式)定位 # driver.find_element_by_ios_predicate("value==‘Mobile‘").send_keys(mobile) driver.find_element_by_ios_predicate("value==‘Reference Number‘").send_keys(ReferenceNumber) # driver.find_element_by_ios_predicate("value==‘Phone‘").send_keys(Phone) driver.find_element_by_ios_predicate("value==‘Gender‘").click() driver.find_element_by_accessibility_id("Male").click() driver.find_element_by_ios_predicate("value==‘Email‘").send_keys(emailadd) driver.find_element_by_ios_predicate("value==‘Special Discount‘").click() driver.find_element_by_accessibility_id("% Discount").click() # driver.find_element_by_accessibility_id("New Discount").click() driver.find_element_by_accessibility_id("Adsdsfa").click() driver.find_element_by_accessibility_id("Save").click() driver.implicitly_wait(60) driver.find_element_by_class_name("XCUIElementTypeSearchField").send_keys(customerName) driver.implicitly_wait(80) if(driver.find_element_by_name(customerName)==True): print("addCustomers succuss!!!" ) else: print("addCustomers fail!!") def tearDown(self): driver.quit() pass if __name__=="__main__": testsuite=unittest.TestSuite() testsuite.addTest(addCustomers(‘addCustomers‘)) #获取当前时间 now=time.strftime(‘%Y-%m-%d %H_%M_%S‘) #定义一个报告存放路径 filename=r‘report‘+now+‘result.html‘ fp=open(filename,‘wb‘) runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title=u‘创建客户测试报告‘,description=u‘用例执行情况:‘) runner.run(testsuite) fp.close()
以上是关于一个标准的单元UI自动化测试代码案例的主要内容,如果未能解决你的问题,请参考以下文章