栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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.查看读取的测试报告文件

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/689547.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号