1.安装Allure
pip install allure-pytest
2.设置公共的pytest.ini文件
具体内容含义请参考
Pytest教程系列(4)Pytest.ini文件配置系列教程
[pytest]
addopts =-v -s -k smoke --alluredir ./AllurePeportJson
testpaths = ./TestCase
python_files = test_* *_test test*pytes
python_functions = test_* test*
python_classes = test_* Test*
xfail_strict = true
markers =
smoke: smoke
module: module
3.设置执行的测试用例的Run文件
coding=utf-8#设置公共类
import pytest
import subprocess
if __name__ == '__main__':
pytest.main()
#读取指定的报告生成的json文件 并将json文件转换成可读的html文件
subprocess.call('allure generate ./AllurePeportJson/ -o ./Report/AllureReport/ --clean',shell=True)
#设置本地的地址及端口用来启动读取测试报告文件的服务
subprocess.call('allure open -h 127.0.0.1 -p 917 ./Report/AllureReport/',shell=True)
4.设置测试报告中的描述
* coding: utf-8 * 导入time sleep单位为秒 便于设置等待时间import os
from time import sleep
from TestCase.test_public_base import Test_Public
from DataExcel.readExcel import ExcelUtil
导入日志类便于设置日志信息from Logs.Log import Logger
导入页面封装好的页公共类from PageWeb.PageObjects import Page_Object
导入配置文件类读取公共数据from Readini.Read import Readini
import pytest
import allure
#设置读取登录中用户名和密码的参数
excel = ExcelUtil(Readini().get_ini_value(‘Excel’,‘exccelini’),‘login’).dict_data()
#设置日志类型参数
log = Logger(‘登录模块结果校验’).getlog()
#继承unittest初始化类
@allure.feature('登录功能验证') # 用feature说明产品需求
class Test_Login_Case(Test_Public):
#模块名称描述
@allure.story('用户登录模块') # 用story说明用户场景
#设置冒烟标识
@pytest.mark.smoke
def test_1_chandao_success(self):
'''输入正确的用户名和正确的密码 '''
try:
#调用页面公共类
PO=Page_Object(self.driver)
#调用页面类。操作用户名和密码文本框
#设置操作步骤描述
with allure.step('步骤一:输入用户名admin'):
PO.input_textbox('id', 'account',excel[0]['username'],)
with allure.step('步骤二:输入密码123456'):
PO.input_textbox('name', 'password',excel[0]['password'],)
#设置等待时间为1秒
sleep(1)
#进行登录点击操作
with allure.step('步骤三:点击登录按钮'):
PO.click_in('id', 'submit')
sleep(1)
with allure.step('步骤四:登录成功 进行截图操作'):
#登录成功进行截图操作
PO.get_windows_img('登录成功')
#设置等待时间为1秒
sleep(1)
#设置日志信息
log.info('输入正确的用户名和密码,登录成功 验证通过')
#点击退出按钮
PO.click_in('linkText', '退出')
#设置等待时间为1秒
sleep(1)
except Exception as e:
with allure.step('步骤五:登录失败 进行截图操作'):
PO.get_windows_img('登录失败')
log.info('输入正确的用户名,正确的密码, 验证失败'+e)
5.查看读取的测试报告文件



