Selenium自我实战之总运行模块(第三模块)

# -*- coding: UTF-8 -*-
import unittest
import HTMLTestRunner
import login_order ,category
import time

#创建测试集合    
def create_suite():
    print("测试开始")
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(login_order.LoginOrderTestCase))
    suite.addTest(unittest.makeSuite(category.CategoryTestCase))
    return suite
     

if __name__ == '__main__':
    suite = create_suite()

    #文件名中加了当前时间,为了每次生成不同的测试报告
    file_prefix = time.strftime("%Y-%m-%d %H_%M_%S", time.localtime())

    #创建测试报告,此时这个文件还是空文件 wb 以二进制格式打开一个文件,只用于写入,如果文件存在则覆盖,不存在则创建
    fp = open("D:\\nd\\自动化selenium\\综合\\"+file_prefix+"_result.html","wb")
   
    # stream定义一个测试报告写入的文件,title就是标题,description就是描述
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=" 测试报告",description="测试用例执行情况",verbosity=2)
    runner.run(suite)
    fp.close()

结果
pycharm运行结果
生成html测试报告
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容