為什么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. mac里的docker如何命令行開啟呢?2. 如何解決docker宿主機(jī)無(wú)法訪問(wèn)容器中的服務(wù)?3. 韋小寶老師的TP基礎(chǔ)實(shí)戰(zhàn)教學(xué)4. node.js - 在vuejs-templates/webpack中dev-server.js里為什么要exports readyPromise?5. javascript - 手賤把桌面git init了,請(qǐng)問(wèn)如何撤回6. angular.js - 百度爬蟲如何處理“#”符號(hào)?8. css3動(dòng)畫 - css3 animation初始動(dòng)畫卡頓是怎么回事?9. Java在半透明框架/面板/組件上重新繪畫。10. html - css3中多列高度 統(tǒng)一
