allure 报告[通俗易懂]

allure 报告[通俗易懂]一、简介二、下载安装三、报告生成四、环境配置五、Python使用allure方法一、简介官方文档:https://docs.qameta.io/allure/二、下载安装1、linux下载安装先检查是否安装npm:whichnpm 未安装npm的话:curl–silent–locationhttps://rpm.nodesource.com/setup_10.x|bash- 安装:yuminstall-ynodejs …

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

一、简介

二、下载安装

三、报告生成

四、环境配置

五、Python 使用 allure 方法


一、简介

官方文档:https://docs.qameta.io/allure/

二、下载安装

1、linux 下载安装

  1. 先检查是否安装npm:     which npm
  2. 未安装npm的话:curl –silent –location https://rpm.nodesource.com/setup_10.x | bash –
  3. 安装:yum install -y nodejs
  4. # npm install -g cnpm –registry=https://registry.npm.taobao.org
  5. 查看当前npm的镜像源:npm config get registry
  6. 修改npm镜像源:npm config set registry https://registry.npm.taobao.org
  7. 安装: npm install
  8. npm run build
  9. 查看版本:npm -v
  10. 下载安装allure : https://github.com/allure-framework/allure2/releases/tag/2.7.0
  11. 上一步无法下载的话 使用:wget https://registry.npmjs.org/allure-commandline/-/allure-commandline-2.13.0.tgz
  12. 解压后 配置环境变量
  13. 查看安装版本:allure –version

2、windows 下载安装

下载地址

下载后解压到安装目录,配置环境变量

查看安装版本:allure –version

三、报告生成

1、结合pytest框架生成 xml格式的报告数据   

python -m pytest –alluredir=[allure的xml目录]

2、将xml报告数据转换成html格式

allure generate –clean [allure的xml目录] -o [allure的html目录]

3、打开报告-默认浏览器

allure open <directory-with-report>

4、清理报告

使用 allure report clean 命令。

四、环境配置

———方式一————-

1、在报告生成前创建 environment.properties 环境配置文件

2、environment.properties 文件内配置环境属性

Browser=Chrome
Browser.Version=63.0
Stand=Production

3、将 环境配置文件 environment.properties 移动到报告目录下以后 生成报告即可

——-方式二——–

1、在报告生成前创建 environment.xml 环境配置文件

2、environment.xml 文件内配置环境属性

<environment>
    <parameter>
        <key>Browser</key>
        <value>Chrome</value>
    </parameter>
    <parameter>
        <key>Browser.Version</key>
        <value>63.0</value>
    </parameter>
    <parameter>
        <key>Stand</key>
        <value>Production</value>
    </parameter>
</environment>

3、将环境配置文件environment.xml 移动到报告目录下以后 生成报告即可

五、Python 使用 allure 方法

1、安装 allure-pytest 库

pip install allure-pytest

2、在测试完成后查看报告  此命令将在默认浏览器中显示您生成的报告。

allure serve /tmp/my_allure_results

3、用例描述 在用例方法内使用”””用例描述””” 

import pytest

def test_success():
    """this test succeeds"""
    assert True

4、标记预期失败的方法   @pytest.mark.xfail(condition=lambda: True, reason=’this test is expecting failure’)

@pytest.mark.xfail(condition=lambda: True, reason='this test is expecting failure')
def test_xfail_expected_failure():
    """this test is an xfail that will be marked as expected failure"""
    assert False

5、条件标记

@pytest.mark.skipif('2 + 2 != 5', reason='This test is skipped by a triggered condition in @pytest.mark.skipif')
def test_skip_by_triggered_condition():
    pass

6、参数化

import allure
import pytest


@allure.step
def simple_step(step_param1, step_param2 = None):
    pass


@pytest.mark.parametrize('param1', [True, False], ids=['id explaining value 1', 'id explaining value 2'])
def test_parameterize_with_id(param1):
    simple_step(param1)


@pytest.mark.parametrize('param1', [True, False])
@pytest.mark.parametrize('param2', ['value 1', 'value 2'])
def test_parametrize_with_two_parameters(param1, param2):
    simple_step(param1, param2)


@pytest.mark.parametrize('param1', [True], ids=['boolean parameter id'])
@pytest.mark.parametrize('param2', ['value 1', 'value 2'])
@pytest.mark.parametrize('param3', [1])
def test_parameterize_with_uneven_value_sets(param1, param2, param3):
    simple_step(param1, param3)
    simple_step(param2)

7、步骤描述

import allure

@allure.step('Step with placeholders in the title, positional: "{0}", keyword: "{key}"')
def step_with_title_placeholders(arg1, key=None):
    pass


def test_steps_with_placeholders():
    step_with_title_placeholders(1, key='something')
    step_with_title_placeholders(2)
    step_with_title_placeholders(3, 'anything')

8、夹具步骤描述  使用conftest.py模块中定义的夹具进行测试的示例(即使未直接导入,Pytest也会解析此类夹具)

# conftest.py
import allure
import pytest


@allure.step('step in conftest.py')
def conftest_step():
    pass


@pytest.fixture
def fixture_with_conftest_step():
    conftest_step()
# test case file
import allure

from .steps import imported_step


@allure.step
def passing_step():
    pass


def test_with_step_in_fixture_from_conftest(fixture_with_conftest_step):
    passing_step()

allure 报告[通俗易懂]

9、添加附件

allure.attach(body, name, attachment_type, extension)

  1. body -要写入文件的原始内容。

  2. name -带有文件名的字符串

  3. attachment_typeallure.attachment_type值之一

  4. extension -提供的-将用作创建文件的扩展名。

10、添加附件方法二

allure.attach.file(source, name, attachment_type, extension)

  1. source -包含文件路径的字符串。

  2. name -带有文件名的字符串

  3. attachment_typeallure.attachment_type值之一

  4. extension -提供的-将用作创建文件的扩展名。

import allure
import pytest


@pytest.fixture
def attach_file_in_module_scope_fixture_with_finalizer(request):
    allure.attach('A text attacment in module scope fixture', 'blah blah blah', allure.attachment_type.TEXT)
    def finalizer_module_scope_fixture():
        allure.attach('A text attacment in module scope finalizer', 'blah blah blah blah',
                      allure.attachment_type.TEXT)
    request.addfinalizer(finalizer_module_scope_fixture)


def test_with_attacments_in_fixture_and_finalizer(attach_file_in_module_scope_finalizer):
    pass


def test_multiple_attachments():
    allure.attach.file('./data/totally_open_source_kitten.png', attachment_type=allure.attachment_type.PNG)
    allure.attach('<head></head><body> a page </body>', 'Attach with HTML type', allure.attachment_type.HTML)

11、用例描述

@allure.description提供描述字符串的装饰器,也可以用于@allure.description_html提供一些HTML,以在测试用例的“描述”部分中呈现

12、标题

import allure
import pytest


@allure.title("This test has a custom title")
def test_with_a_title():
    assert 2 + 2 == 4

13、链接

import allure

TEST_CASE_LINK = 'https://github.com/qameta/allure-integrations/issues/8#issuecomment-268313637'


@allure.link('https://www.youtube.com/watch?v=4YYzUTYZRMU')
def test_with_link():
    pass


@allure.link('https://www.youtube.com/watch?v=Su5p2TqZxKU', name='Click me')
def test_with_named_link():
    pass


@allure.issue('140', 'Pytest-flaky test retries shows like test steps')
def test_with_issue_link():
    pass


@allure.testcase(TEST_CASE_LINK, 'Test case title')
def test_with_testcase_link():
    pass

14、失败重试

使用插件 pip install pytest-rerunfailures

pytest --reruns 5 --reruns-delay 1  # 使用pytest 命令行 指定失败重试次数 可选重试延迟时间 秒

15、BDD标记 

 @allure.feature (修饰类)@allure.story(修饰方法) 用于根据特定于项目的功能/故事细分来标记测试   

要标记某些功能或故事属于史诗,请使用以epic_前缀开头的名称

import allure


def test_without_any_annotations_that_wont_be_executed():
    pass


@allure.story('epic_1')
def test_with_epic_1():
    pass


@allure.story('story_1')
def test_with_story_1():
    pass

@allure.story('story_2')
def test_with_story_2():
    pass


@allure.feature('feature_2')
@allure.story('story_2')
def test_with_story_2_and_feature_2():
    pass

可以使用以下命令行选项来指定不同的测试集,以执行传递逗号分隔值列表的操作:

  1. --allure-epics

  2. --allure-features

  3. --allure-stories

17、严重性标记

使用@allure.severity装饰器。它以allure.severity_level枚举值作为参数

通过将--allure-severities命令行选项与逗号分隔的严重性级别结合使用,将仅运行具有相应严重性的测试

pytest tests.py --allure-severities normal,critical
import allure


def test_with_no_severity_label():
    pass


@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
    pass


@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
    pass


@allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object):

    def test_inside_the_normal_severity_test_class(self):
        pass

    @allure.severity(allure.severity_level.CRITICAL)
    def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
        pass

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/164423.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • java executeupdate_执行完executeUpdate()方法…-体系课

    java executeupdate_执行完executeUpdate()方法…-体系课如题:Servlet代码如下:packagejdbcHomeWork;importjava.io.IOException;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.SQLException;importjavax.servlet.ServletException;importja…

    2022年10月20日
  • 向量的内积与夹角_两个向量的内积怎么算

    向量的内积与夹角_两个向量的内积怎么算最近在做文本聚类,用到了奇异值分解,可是我不明白原理,于是复习线性代数。遇到了向量内积和夹角的关系,不太明白。向量内积,也叫做向量的点积,是两个向量对应分量乘积之和。如果两个向量是垂直的,那么点积为0。如果点积为0,那么两个向量是垂直的。如果两个向量内积大于0,那么两个向量夹角小于90’,如果两个向量内积小于0,那么两个向量夹角大于90’。    $$x=

  • mongodb笔记_mongodb objectid

    mongodb笔记_mongodb objectid注册表中查找B1159E65-821C3-21C5-CE21-34A484D54444中的子项4FF78130,删除其下的三个子项即可。这样剩余时间又会回到15天前。[img]http://dl.iteye.com/upload/attachment/0077/4713/021bf1d3-48db-3aef-a948-e8ae5b5b9ec3.png[/img]…

  • MPP架构概念_体系架构是什么意思

    MPP架构概念_体系架构是什么意思MPP架构概念1.什么是MPPMPP(MassivelyParallelProcessing),即大规模并行处理。什么是并行处理?在数据库集群中,首先每个节点都有独立的磁盘存储系统和内存系统,其次业务数据根据数据库模型和应用特点划分到各个节点上,MPP是将任务并行的分散到多个服务器和节点上,在每个节点上计算完成后,将各自部分的结果汇总在一起得到最终的结果。什么是大规模?每台数据节点通过专用网络或者商业通用网络互相连接,彼此协同计算,作为整体提供数据库服务。整个集群称为非共享数据库集群,非

    2022年10月27日
  • 计算机 修改 虚拟ip,怎么样在电脑中设置虚拟IP地址?

    计算机 修改 虚拟ip,怎么样在电脑中设置虚拟IP地址?满意答案wtc69812020.03.01采纳率:56%等级:9已帮助:114人更改IP地址广域IP:1、如果是PPOE上网只需断开连接再重新连上就好了,服务器会从IP地址池中随机分配一个IP地址给你。2、固定IP上网那你要找运营商更改了,这样改是快不了的。局域IP:网络邻居右键属性,我的连接右键属性,打开tcp/ip更改。改网卡物理地址:1、直接改:可以在桌面上的“网上邻居”图标上单击右…

    2022年10月20日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号