美文网首页python+selenium
selenium——测试报告优化

selenium——测试报告优化

作者: 小二哥很二 | 来源:发表于2019-07-25 17:48 被阅读0次

1.简单的测试报告

1.png 2.png

-----------------------------------------------------------------------

2.HTMLTestRunner测试报告

3.png

-----------------------------------------------------------------------

3.可读性测试报告(优化)

1)因为我们在测试的时候,不知道报告里所测的是哪条用例,所以可以在类或者方法下加上注释,python的注释分为两种,一种是comment,一种就是可读的doc string,用三引号注释“”“ ”“”或‘’‘ ’‘’
2)多次执行用例的时候,每次都要修改报告名称,如果不修改,就会覆盖之前的报告,所以最好的方法就是加上当前时间~!

import time

if __name__=='__main__':
    suit=unittest.TestSuite()
    suit.addTest(Baidu('test_baidu'))
    now=time.strftime('%Y-%m-%d %H_%M_%S)
    filename='./' + now + 'result.html'
    fp=open(filename,'wb')
    runner== HTMLTestRunner(stream=fp,
                            title= '接口自动化测试报告' ,
                            description= '用例执行情况:' ,
    )
runner.run(suit)
fp.close()

-----------------------------------------------------------------------

4.项目集成测试报告
想执行testcase目录下的所有文件,一个个写进suit.add()里太麻烦:

import unittest,time
from HTMLTestRunner import  HTMLTestRunner

#指定测试用例为当前文件夹下的testcase目录
test_dir='./test_case'
#指定执行该目录下的所有包含test_*.py的文件
discover=unittest.defaultTetLoader.discover(test_dir,pattern='test_*.py')

if __name__=='__main__':
   pt = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
   reportname=os.path.dirname(os.path.abspath('.'))+'\\Report\\'+pt+'.html'
   file_result =open(reportname, 'wb')
   runner=HTMLTestRunner.HTMLTestRunner(stream=file_result,title=u'WebTour测试报告',description=u'用例执行情况')
    runner.run(add_case())
注意:测试用例文件必须继承unittest.Testcase,单纯的def方法是无法添加到测试集中

PS:觉得这篇文章有用的朋友,多多点赞打赏哦~!

相关文章

网友评论

    本文标题:selenium——测试报告优化

    本文链接:https://www.haomeiwen.com/subject/wzqkrctx.html