从0开始一步步搭建selenium+python+pymysql+HTMLTestRunner 自动化测试框架(七)
最后一步:用HTMLTestRunner 跑起来
# coding=utf-8
# 1.先设置编码,utf-8可支持中英文,一般放在第一行
#测试gitee
import time
import os
import unittest
from HTMLTestRunner import HTMLTestRunner
class TestRunner(object):
''' Run test '''
def __init__(self, cases="../", title=u'自动化测试报告', description=u'环境:windows 10'):
self.cases = cases
self.title = title
self.des = description
def run(self):
for filename in os.listdir(self.cases):
if os.path.exists(self.cases+'report'):
break
else:
os.mkdir(self.cases+'report')
now = time.strftime("%Y-%m-%d_%H_%M_%S")
fp = open("../report/" + now + "result.html", 'wb')
tests = unittest.defaultTestLoader.discover("../testsuits", pattern='*.py', top_level_dir=None)
runner = HTMLTestRunner(stream=fp, title=self.title, description=self.des)
runner.run(tests)
fp.close()
if __name__ == '__main__':
test = TestRunner()
test.run()
好了,以上是我的自动化框架,跟大家分享完了,还有很多不足,希望得到大家的指正。