為什么python+htmltestrunner生成的測(cè)試報(bào)告有問(wèn)題?
問(wèn)題描述
問(wèn)題:一個(gè)百度首頁(yè)搜索的一個(gè)python+unittest測(cè)試,代碼執(zhí)行成功,但是用HTMLTestRunner輸出的測(cè)試報(bào)告里面得內(nèi)容有問(wèn)題,具體問(wèn)題是:測(cè)試條數(shù),成功數(shù),失敗數(shù)都為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'百度首頁(yè)測(cè)試',description=u'用例執(zhí)行情況')runner.run(test)file_result.close()
生成的報(bào)告截圖:
問(wèn)題解答
回答1:加測(cè)試用例的方式錯(cuò)了要test=unittest.TestSuite() test.addTest(LoginBaiDu(’setUp’))test.addTest(LoginBaiDu(’test_baidu’))
或者直接加入類test= unittest.TestLoader().loadTestsFromTestCase(LoginBaiDu)
相關(guān)文章:
1. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)2. 關(guān)于mysql聯(lián)合查詢一對(duì)多的顯示結(jié)果問(wèn)題3. python中如何計(jì)算t分布的值?4. mysql在限制條件下篩選某列數(shù)據(jù)相同的值5. 數(shù)據(jù)庫(kù) - Mysql的存儲(chǔ)過(guò)程真的是個(gè)坑!求助下面的存儲(chǔ)過(guò)程哪里錯(cuò)啦,實(shí)在是找不到哪里的問(wèn)題了。6. python執(zhí)行cmd命令,怎么讓他執(zhí)行類似Ctrl+C效果將其結(jié)束命令?7. python - scrapy url去重8. 實(shí)現(xiàn)bing搜索工具urlAPI提交9. python - Django有哪些成功項(xiàng)目?10. Python從URL中提取域名
