一、升级Powershell(windows7及以上版本默认自带、其实普通的CMD命令行工具够用了)
我是Win7默认带的pw1.0,太古老了升级一下,地址如下,选择与自己windows版本匹配的连接下载:
https://docs.microsoft.com/zh-cn/powershell/scripting/install/installing-windows-powershell?view=powershell-6
安装时报错如下:
解决办法:
1.修改xxx.msu文件名后缀为xxx.cab,并解压在当前目录D:\test\xxx\
2.win+r打开运行:并输入dism /online /add-package /packagepath:”D:\test\xxx”
等待安装完成重启电脑,查看版本号 运行PowerShell并输入:$psversiontable或$host
二、allure环境配置
以下均在PowerShell中执行
1.修改脚本执行授权,会有风险提示的一堆英文,输入A 回车同意即可
执行命令:set-executionpolicy remotesigned -scope currentuser
2.下载并安装scoop包管理工具(为后续安装各种软件包提供便捷)
执行命令:iex (new-object net.webclient).downloadstring(‘https://get.scoop.sh’)
3.安装allure
执行命令:scoop install allure
三、allure生成报告常用指令
进入test_*.py测试脚本目录下
1.执行用例并生成xml文件:pytest -s -q –alluredir=xml_report #xml_report为执行结果目录
2.按需生成定离线告页面:allure generate xml_report -o my_html #xml_report为上边执行的结果目录,my_html为指定的美化后的结果页面目录(未指定 -o 目录时,默认生成allure-report目录)
访问这个报告页面,需要使用 firefox浏览器……其它不支持。或者直接在PycharmIDE 的工程目录下 右键点击结果报告里的 index.html文件,选择:open in brower 打开。
3.如果有安装web服务器,可以执行命令生成在线报告:allure serve xml_report,会创建web临时目录(存在C:\Users\Administrator\AppData\Local\Temp),基本支持所有的浏览器访问(360、chrome、ie什么的)
四、allure定制报告(以下参考 小喜的博客)
1、关键字:feature 主要功能模块-一级模块
2、关键字:story: Features下的子功能-二级模块
3、关键字:severity: 标注测试用例的重要级别
4、关键字:step: 标注测试用例的重要步骤
Issue和TestCase: 标注Issue、Case,可加入URL
Allure中对严重级别的定义(若关键字拼写错误,则默认显示normal级别):
1、 关键字-S级:blocker
2、 关键字-A级:critical
3、 关键字-B级:normal
4、 关键字-C级:minor
5、 关键字-D级:trivial
我 一般使用到1~4级便够用了……分级太多反而麻烦。
# -*- coding: utf-8 -*-
import allure
import pytest
from PIL import *@allure.step('检查UI名:{0}打开了')
def ui_check(tips):
return tipsf=open('./sc.png','rb').read()
# with open('./sc.png','rb') as f:
# f.read()
@allure.feature('feature:功能名1')
@allure.story('story:1-子功能UI测试')
@allure.severity('normal')
@allure.issue('http://bug.report')#缺陷链接地址
@allure.testcase('http://testcase.com')#用例链接地址
#@allure.attach('sname',f,allure.attachment_type.PNG)
#这是用例标题-功能1-子功能UI测试
def test_call_check_ui(): """
用例描述:UI检查测试
"""
print('UI检查测试')
assert ui_check('Main')=='Main'@allure.feature('feature:功能名1')
@allure.story('story:1-子功能数据测试')
@allure.severity('critical')
def test_app_data():
'''
用例描述:数据测试
'''
print('数据测试')@allure.feature('feature:功能名1')
@allure.story('story:1-子功能逻辑测试')
@allure.severity('critical')
def test_app_logic():
'''
用例描述:逻辑测试
'''
print('逻辑测试')@allure.feature('feature:功能名2')
@allure.severity('trivial')
#这是用例标题-功能2
def test_app_install():
"""
用例描述:test_app_install 应用安装结果统计
"""
print('安装应用')@allure.feature('feature:功能名3')
@allure.severity('blocker')
def test_app_start():
"""
用例描述:test_app_start 应用启动结果统计
"""
print('启动应用并统计启动时间')
assert 1 == 0@allure.feature('feature:功能名4')
@allure.severity('normal')
def test_app_uninstall():
'''
用例描述:这是描述这个用例的作用
'''
print('卸载应用结果统计')if __name__ == '__main__':
pytest.main(['-s','-q','--alluredir','./report'])
[Mac环境]
1.Allure下载路径:https://github.com/allure-framework/allure2/releases
下载解压包,添加路径
export PATH=${PATH}:/Users/XXX/Downloads/Compressed/allure-2.12.1/bin
到文件: ~/.bash_profile
最后执行:source ~/.bash_profile 即可生效,输入allure –version 查看当前版本
2.安装依赖插件,使用pip命令即可
pip install pytest allure-pytest pytest-html pytest-ordering