標籤:pytho 報告 smart png epo erro webdriver emulator ddt
本文基於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()
產生測試報告:
Appium基於python unittest自動化測試並產生html測試報告