慢慢探索&慢慢学习
1.安装allure
2.安装 pytest拓展包
pip install alllure-pytest
3.执行测试用例并收集结果
pytest xxx.py(你的case) --alluredir=/temp/my_allure_result
结果:
4.将结果发送报告
allure serve ./result/tmp
如果发现allure不是内部或外部命令,以管理员运行pycharm,再输入allure
结果:
再次执行命令
allure serve ./result/tmp
5.报告验收
6.扩展-生成测试报告并且随时打开
生成报告
allure generate ./result/map -o ./result/tmp/ --clean
打开报告,启动一个tomcat服务,在服务下打开HTML页面
allure open -h xx.xx.xx.xx -p 8888 ./repore/tmp
结果:
7.allure特性
@allure.feature(‘功能名称’)
@allure.stiry(‘子功能名称’)
@allure.step(‘步骤细节’)
@allure.feature("登录模块")
class TestLogin:
@allure.story("登陆成功")
def test_login_success(self):
print("这是登录: 测试用例 ,登录成功 ")
pass
@allure.story("登陆成功-a")
def test_login_success_a(self):
print("这是登录: 测试用例 ,登录成功 ")
pass
@allure.story("用户名缺失")
def test_login_success_b(self):
print("用户名缺失 ")
pass
@allure.story("密码缺失")
def test_login_failure(self):
# 标记用例步骤
with allure.step("点击用户名"):
print("输入用户名 ")
# 标记用例步骤
with allure.step("点击密码"):
print("输入密码 ")
print("点击登录")
while allure.step("点击之后登录失败"):
assert '1' == 1
print("登录失败")
pass
@allure.story("登录失败")
def test_login_failure_a(self):
print("这是登录: 测试用例 ,登录失败 ")
pass
报告结果:
feature 对应模块
story 对应子模块
step对应用例步骤 代码中使用 with allure.step
@allure.link(“链接地址”,name=“描述”)
pytest pytest_allure_link.py --alluredir=./result/link
@allure.testcase(“用例地址”,“描述”)
pytest pytest_allure_link.py --alluredir=./result/link
@allure.issue(“bug id”,“描述”)
pytest pytest_allure_link.py --allure-link-pattern=issue:http://192.168.50.2:8081/bug-view-9663.html --alluredir=./result/link
# 链接地址
@allure.link("http://www.baidu.com", name="这是一个链接")
def test_with_link():
print("这是一条加了链接的用例")
# 用例地址
TEST_CASE_LINK = "http://www.baidu.com"
@allure.testcase(TEST_CASE_LINK, "登录用例")
def test_with_link_2():
print("这是一条加了链接的登录用例")
# bug链接 bug id
@allure.issue("9663", "这是一个issue")
def test_with_link_3():
print("这是一条加了链接的登录用例")
生成报告结果:
attack
def test_attach_text():
allure.attach.file(text,
attachment_type=allure.attachment_type.TEXT)
def test_attach_html():
allure.attach("<body>这是一段htmlbody</body>", "这是一个html测试块", attachment_type=allure.attachment_type.HTML)
def test_attach_picture():
allure.attach.file("D:\JetBrains\PycharmProjects\wangmin\测试框架\ource\picture.jpg",
name="这是一个图片",
attachment_type=allure.attachment_type.JPG)
@allure.attach(‘具体文本信息’),需要附加的信息,可以提供数据、文本、图片、视频、网页
pytest 文件名 --allure-features’购物车功能’ --allure-storise ‘加入购物车’(注意这里–allure_features中间是下划线)