Selenium HTMLTestRunner 无法生成测试报告的总结

时间:2022-10-04 18:22:42

使用Python ,HTMLTestRunner 生成测试报告时,遇到很奇怪的问题,明明运行的结果,没有任何报错,就是不生成测试报告,纠结好久。google+baidu搜索结果也不满意,最后终于解决,先总结下。

代码示例 

#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re,os
import HTMLTestRunner
class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(r'C:\Users\user\AppData\Local\Google\Chrome\Application\chromedriver')
self.driver.implicitly_wait(30)
self.base_url = "http://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True

def test_baidu_search(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("kw").send_keys("selenium webdriver")
driver.find_element_by_id("su").click()
time.sleep(2)
driver.close()

def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
testunit = unittest.TestSuite()
# 将测试用例加入到测试容器中
testunit.addTest(Baidu("test_baidu_search"))
# 定义个报告存放路径,支持相对路径
filename = 'E:\\sresult.html'
fp = open(filename, 'wb')
# 定义测试报告
runner=HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='baidu',
description='baidu:'
)
# 运行测试用例
runner.run(testunit)

Selenium HTMLTestRunner 无法生成测试报告的总结

Selenium HTMLTestRunner 无法生成测试报告的总结

Selenium HTMLTestRunner 无法生成测试报告的总结