為什么python+htmltestrunner生成的測試報告有問題?
問題描述
問題:一個百度首頁搜索的一個python+unittest測試,代碼執行成功,但是用HTMLTestRunner輸出的測試報告里面得內容有問題,具體問題是:測試條數,成功數,失敗數都為0代碼
?# -*- coding: utf-8 -*-from selenium import webdriverimport osimport timeimport unittestimport reimport HTMLTestRunnerfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.support import expected_conditionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.common.exceptions import NoAlertPresentExceptionclass LoginBaiDu(unittest.TestCase): def setUp(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(30)self.base_url = 'http://www.baidu.com'self.verificationErrors = []self.accept_next_alert = Trueprint(’Done-01’) def test_baidu(self):self.driver.get(self.base_url)self.driver.find_element_by_id('su').click()print(’Done-02’)time.sleep(2)jsClear='$('input[id=’kw’]').val('')'self.driver.execute_script(jsClear)print(’Done-03’)time.sleep(2)jsVal='$('input[id=’kw’]').val('selenium+python')'self.driver.execute_script(jsVal)time.sleep(1)self.driver.find_element_by_xpath('//input[@id=’su’]').click()print(’Done-04’)self.driver.close()print(’Done-05’) def tearDown(self):self.driver.quit()self.assertEqual([], self.verificationErrors)print('test down...') if __name__=='__main__':test=unittest.TestSuite()test.addTest(setUp)test.addTest(test_baidu)file_path='D:workspacePythonLearnsrcLoginBaiDuresult.html'file_result=open(file_path,’wb’)runner=HTMLTestRunner.HTMLTestRunner(stream=file_result,title=u'百度首頁測試',description=u'用例執行情況')runner.run(test)file_result.close()
生成的報告截圖:
問題解答
回答1:加測試用例的方式錯了要test=unittest.TestSuite() test.addTest(LoginBaiDu(’setUp’))test.addTest(LoginBaiDu(’test_baidu’))
或者直接加入類test= unittest.TestLoader().loadTestsFromTestCase(LoginBaiDu)
相關文章:
1. javascript - js 有什么優雅的辦法實現在同時打開的兩個標簽頁間相互通信?2. css3 - Typecho 后臺部分表單按鈕在 Chrome 下出現靈異動畫問題,求解決3. javascript - angular和jquery都用到了$符號,一起用會不會沖突?4. javascript - 怎樣限制同一個瀏覽器不能登錄兩個賬號5. 想找個php大神仿個網站。6. java - android代碼重構:如何把app設置里的頭像UI做成通用的?7. java - 新手做一個安卓視頻播放器,想實現一個進度條,按鈕那種在視頻下方懸浮的功能,不知道思路!8. javascript - jquery怎么給select option一個點擊時觸發的事件,如圖 如果選擇自定義觸發一個時間?9. nginx配置server模塊的問題10. mysql優化 - 關于mysql分區
