生成HTML测试报告表格
#生成HTML测试报告 #-*- 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 import HTMLTestRunner class Baidu(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.implicitly_wait(30) # 隐式等待 self.base_url = "http://www.baidu.com" self.verificationError = [] self.accept_next_alert = True def test_baidu_search(self):#测试用例1 pass def test_baidu_set(self):#测试用例2 pass def test_baidu_xxx(self):#测试用例3 pass def tearDown(self): self.driver.quit() self.assertEqual([],self.verificationErrors) #if __name__ == "__main__": if __name__ == "__main__": testunit = unittest.TestSuite() #定义一个单元测试容器 testunit.addTest(Baidu("test_baidu_search")) #将测试用例加入到测试容器中 #testunit.addTest(Baidu("test_baidu_set")) #testunit.addTest(Baidu("test_baidu_xxx")) filename = "D:\\result.html" #定义个报告存放路径,支持相对路径 fp = file(filename,'wb') runner = HTMLTestRunner.HTMLTestRunner( stream= fp, title= 'Report_title', description = 'Report_description') runner.run(testunit) #自动进行测试
报错信息1:
def test_baidu_set(self):#测试用例2
pass
一直显示为缩进问题,但是从表面上看完全没有缩进的问题;后来进行反复重写,使用TAB键进行缩进,在test_baidu_xxx用例下加入pass,不会再报错
报错2:
if __name__ = "__main__":
很明显,应该是 “==”
报错3:self.assertEqual([],self.verificationErrors) if __name__ == "__main__":
原来代码中有后面置灰部分,注释掉就不会报错
代码运行结果: