我们先下载对应的模块到我们的目录下
(venv是python的虚拟环境,这个可有可无)
使用HTMLTestRunner
我们在项目里新建一个用来放测试用例的文件夹testCase,把我们之前的登录测试移动到该文件夹里并重命名为test_login.py。
在项目目录里新建runner.py文件:
#coding=utf-8
from HTMLTestReportCN import HTMLTestReportCN
import unittest
import time
casefile = "./testCase/"
#遍历testCase里的所有test_*.py文件,添加所有测试用例。
def createsuite():
testunit = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(casefile,pattern='test_*.py',top_level_dir=None)
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
return testunit
now = time.strftime("%Y-%m-%d_%H%M",time.localtime())
#测试报告存放的位置
filepath = './result/report/' + now +'.html'
fp = open(filepath,'wb')
runner = HTMLTestReportCN.HTMLTestRunner(
stream=fp,
title='自动化报告',
tester='lin'
)
runner.run(createsuite())
fp.close()
并手动新建./result/report/文件夹
项目目录
在终端cd到项目目录,输入python runner.py
(venv) yauloladeMacBook-Air:appium yaulola$ python runner.py
.