十一.web自动化【生成企业级allure测试报告】

 1.下载allure安装包

下载allure安装包:Releases · allure-framework/allure2 · GitHubAllure Report is a flexible, lightweight multi-language test reporting tool. It provides clear graphical reports and allows everyone involved in the development process to extract the maximum of information from the everyday testing process - Releases · allure-framework/allure2icon-default.png?t=N7T8https://github.com/allure-framework/allure2/releases

 2.下载后解压,配置环境变量

把bin路径添加到path路径中。E:\allure-2.25.0\bin;

3.在cmd命令框输入allure --version验证环境

4.pip install allure-pytest

5.生成allure报告

第一步:配置pytest.ini文件,生成临时json报告

addopts = -vs --alluredir ./temp --clean-alluredir

[pytest]
addopts = -vs --alluredir ./temp --clean-alluredir
python_files = test_*.py
python_class = Test*
python_function = test_*

第二步:配置run.py文件,生成html报告

import os
import time
import pytest
if __name__ == '__main__':
    pytest.main()
    time.sleep(3)
    os.system("allure generate ./temp -o ./report --clean")

定制allure报告,将错误截图放入allure报告的html中:

import time
import allure
from selenium import webdriver
from ms.pageobject.login_page import LoginPage

#测试用例层

class TestLogin:
    def setup_class(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)
    def teardown(self) -> None:
        print("执行完毕")
        time.sleep(3)
        self.driver.quit()


# 用户名密码登录
    def test_01_login(self):
        try:
           lp = LoginPage(self.driver)
           lp.login_ecshop()
           assert 1==2
        except Exception as e:
            #保存错误截图
            file_path = r"C:\Users\ASUS\Desktop\qf99\ms\error_image\login.png"
            self.driver.save_screenshot(file_path)
            #将错误截图放入allure报告
            with open(file_path,mode="rb") as f:
                allure.attach(f.read(),"degnlu.png",allure.attachment_type.PNG)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值