配置:
/*
@param:
@env: windows64bit
@version python 3.7 amdx86-64bit
@author:Chenquan
@Date: 2019.01.19
安装jdk1.8,这个由于allure-commandline基于java,jdk环境变量配置就不说了;
pip install pytest
pip install pytest-html
pip install allure-pytest 由于官方放弃维护pytest-allure-adaptor 看见安装这个的也不要奇怪,建议用前面的官方维护的
pip install pytest-rerunfailures
最后面一个很重要转换数据为报告的allure-commandline工具,pytest生成测试数据的xml,json文件转化为报告就靠它的bin目录的allure.bat文件了,下载zip包这个要去官方下载解压缩,官方目前更新到2.7
windows环境变量配置:进入allure-commandline解压文件bin目录,复制文件bin目录的路径粘贴到环境变量Path下面点击保存,记得如果在最后面前面加;分号中间不管jdk配过的就不用提醒了我的是D:/allure-commandline/bin
解压后,运行bin目录下allure.bat ,然后cmd验证 输入allure 看到帮助文档就说明安装allure-commandline ok了
*/
2.脚本编写
# -*- coding: utf-8 -*-
# @Time : 2019/01/19
# @Author : Chen
# @File : test_allure.py
import allure
import pytest
"""
/* @param:标注测试用例的重要级别
Blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)
Critical级别:临界缺陷( 功能点缺失)
Normal级别:普通缺陷(数值计算错误)
Minor级别:次要缺陷(界面错误与UI需求不符)
Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)
*/
"""
@allure.feature('测试模块:权限')
class TestAuthor(object):
@allure.story('有修改权限能修改权限场场景用例测试')
@allure.severity("critical")
@allure.issue("http://www.pypi.com")
@allure.testcase("http://www.baidu.com")
def test_case_01(self):
"""
用例描述:Test case 01
"""
with allure.step("第一步:开始登录"):
print("这个位置是你写登录函数的代码区")
allure.attach('第一步登录成功', '登录人admin')
with allure.step("第二步,修改权限"):
print("这是修改权限代码区")
allure.attach('第二步权限修改成功', '修改人admin')
with allure.step("第三步,跳转首页验证权限"):
print("这是跳转验证代码区")
allure.attach('验证权限修改')
with allure.step("第四步:断言"):
allure.attach("期望无查看权限")
assert 'success' == 'failed'
allure.attach("执行用例结束")
@allure.story('字符处理场景的:字符拼接')
@pytest.mark.parametrize("param1, param2", # 用例参数
[("hello world", "hello world"), # 用例参数的参数化数据
(4, 4),
("中文", "中文")],
ids=["test ASCII string", # 对应用例参数化数据的用例名
"test digital string",
"test unicode string"])
def test_case_02(self,param1,param2):
"""
用例描述:Test case 02
"""
allure.attach("str_add返回结果:{}+{}".format(param1,param2))
# if __name__ == '__main__':
# pytest.main(['-s', '-q', '--alluredir', './report/xml'])
3.cmd cd到用例所在目录输入命令
py.test -s -q --alluredir ./report/xml
运行脚本产生报告junit.xml html,log.txt,失败retry次数为2,重跑间隔延时时间为3秒,产生json,xml数据保存在report/xml目录下
4.很关键,将report/xml下数据生成报告转换为allure类型html报告展示保存在report/test_report 目录下
cmd:输入allure generate report/xml -o report/test_report --clean
5.第一次去看很能都是loading...不要担心,取pycharm找到用例文件目录下report/test_report 下的index.html点击右键runindex.html或者open in browser 选项选取chrome打开即可