Appium基于python unittest自动化测试并生成html测试报告

本文基于python单元测试框架unittest完成appium自动化测试,生成基于html可视化测试报告

代码示例:

 1 #利用unittest并生成测试报告 2 class Appium_test(unittest.TestCase): 3 """appium测试类""" 4  def setUp(self): 5 desired_caps = { 6 platformName: Android, 7 deviceName: Android Emulator,#可有可无,这里是指我的模拟器 8 platformVersion: 5.0, 9  # apk包名10 appPackage: com.smartisan.notes,11  # apk的launcherActivity12 appActivity: com.smartisan.notes.NewNotesActivity,13  #如果存在activity之间的切换可以用这个14 # appWaitActivity:.MainActivity,15 unicodeKeyboard: True,16  #隐藏手机中的软键盘17 resetKeyboard: True18  }19 self.driver = webdriver.Remote(http://127.0.0.1:4723/wd/hub,desired_caps)20 time.sleep(5)21 self.verificationErrors = "今天天气不错在家学习!" #设置的断言22 23  def tearDown(self):24 time.sleep(10)25 assertt = self.driver.find_element_by_id("com.smartisan.notes:id/list_rtf_view").text26  # print(assertt) #调试用27 self.assertEqual(assertt,self.verificationErrors,msg="验证失败!")28  #断言:实际结果,预期结果,错误信息29  self.driver.quit()30 31  def test_creat(self):32 """记事本中新增一条记录"""33 self.driver.find_element_by_id("com.smartisan.notes:id/add_button").click()34 time.sleep(3)35 self.driver.find_element_by_class_name("android.widget.EditText").send_keys("今天天气不错在家学习!")36 self.driver.find_element_by_id("com.smartisan.notes:id/send_finish_button").click()37 38 suite = unittest.TestSuite()39 suite.addTest(Appium_test(test_creat))40 41 report_file = ".\\appium_report.html"42 fp = open(report_file,wb)43 runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="appium测试报告",description=新增一条笔记并保存)44 runner.run(suite)45 fp.close()

生成测试报告:

技术分享

 

相关文章