脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python自动化报告的输出用例详解

python自动化报告的输出用例详解

2021-02-27 00:15舞涯 Python

本文通过用例给大家介绍了python自动化报告的输出,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

1、设计简单的用例

python自动化报告的输出用例详解

2、设计用例

   以testbaidulinks.py命名

python" id="highlighter_463749">
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding:utf-8
from selenium import webdriver
import unittest
class baidulinks(unittest.testcase):
 def setup(self):
  base_url = 'https://www.baidu.com'
  self.driver = webdriver.chrome()
  self.driver.implicitly_wait(10)
  self.driver.get(base_url)
 def teardown(self):
  self.driver.close()
  self.driver.quit()
 def test_baidu_news(self):
  u"""百度新闻"""
  driver = self.driver
  driver.find_element_by_link_text('新闻').click()
  self.assertin(driver.title, u'v百度新闻——全球最大的中文新闻平台')
 def test_baidu_hao123(self):
  u"""hao123"""
  driver = self.driver
  driver.find_element_by_link_text('hao123').click()
  self.assertequal(driver.title, u'hao123_上网从这里开始')
 def test_baidu_tieba(self):
  u"""百度贴吧"""
  driver = self.driver
  driver.find_element_by_link_text('贴吧').click()
  # 错误的断言
  self.asserttrue(driver.find_element_by_link_text('全吧搜索+1'))
if __name__ == '__main__':
 unittest.main()
 print('百度链接跳转成功')

3、写执行用例脚本

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# /usr/bin/env python3
# coding:utf-8
"""
created on 2018-05-30
project: learning
@author:wuya
"""
import os, time, unittest
import htmltestrunner
report_path = os.getcwd() # 设置保存报告的路径,这儿设置的是与执行文件在同一个目录下
now = time.strftime("%y-%m-%d %h:%m", time.localtime(time.time())) # 获取当前时间
title = u"百度头链接测试" # 标题
report_abspath = os.path.join(report_path, title + now + ".html") # 设置报告存放和命名
# 导入用例
def all_case():
 case_path = os.getcwd() # 用例路径,这儿的用例和执行文件在同一目录下
 discover = unittest.defaulttestloader.discover(case_path,             pattern="test*.py") # 添加用例,在case_path的路径下,所有以test开头的文件都当做用例文件执行
 print(discover)
 return discover
if __name__ == "__main__":
 fp = open(report_abspath, "wb") # 保存报告文件
 runner = htmltestrunner.htmltestrunner(stream=fp,           title=title + ':',)
 runner.run(all_case()) # 执行用例
 fp.close()

4、执行结果

  结果文档下载

python自动化报告的输出用例详解

  对于执行不通过的用例可以点击错误二字查看详情

python自动化报告的输出用例详解

总结

以上所述是小编给大家介绍的python自动化报告的输出用例详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:https://www.cnblogs.com/wuyazi/archive/2018/05/30/9109225.html

延伸 · 阅读

精彩推荐