Pytest教程系列(5)Pytest+Allure生成完美的HTML测试报告

Pytest+Allure生成完美的HTML测试报告

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
# 导入excel类便于读取excel中的数据
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初始化类
# epic 系统名称描述
@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.查看读取的测试报告文件
报告文件

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值