为什么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 - 请问一下npm 如何卸载之前的版本安装新的版本呢?2. javascript - 方法要用到一个外部的数据 那么是优先选择当成参数传过去 还是把数据存成相对当前作用域来说全局的变量~3. javascript - 请问一下fullpage只能初始化一次的问题怎么解决?4. html5 - html2canvas生成的图片,checkbox和radio的选中项无法截图。5. javascript - tab切换点击不同的按钮显示不同的内容6. javascript - 如何使用loadash对[object,object,object]形式的数组进行比较7. html5 - input type=’file’ 上传获取的fileList对象怎么存储于浏览器?8. javascript - 请教移动端从详情页返回到列表页原来位置的问题?9. javascript - vueclick事件点击时报错10. nginx英文文档的WebSocket proxying部分没看太明白,麻烦推荐一点中文文章

网公网安备