Appium基於python unittest自動化測試並產生html測試報告

來源:互聯網
上載者:User

標籤: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測試報告

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.