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 …


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_type–allure.attachment_type值之一

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

10、添加附件方法二

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

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

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

  3. attachment_type–allure.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

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

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

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • 推荐系统常用算法介绍_基于内容推荐算法

    推荐系统常用算法介绍_基于内容推荐算法原文链接:https://www.cnblogs.com/zhangyang520/p/10969951.html参考回答:推荐算法:基于人口学的推荐、基于内容的推荐、基于用户的协同过滤推荐、基

    2022年8月3日
  • ES集群搭建「建议收藏」

    ES集群搭建「建议收藏」1.设置内核参数:/etc/sysctl.confvm.max_map_count=6553602.设置文件描述符限制:/etc/security/limits.conf*softnofile65536*hardnofile131072*softnproc2048*hardnproc4096&&1和2的配置,可以等到启动时候报错,再修改(可以清晰地知道1、2在处理什么问题)3.es不允许root用户启动,修改用户和分组chownuser1.

    2022年10月13日
  • webgame开发之Flex调用FLash自定义界面

    webgame开发之Flex调用FLash自定义界面心得教程类型:原创本帖最后由junxiang于2011-7-307:20编辑今天做游戏主界面,在群里看见有人讨论如何在Flex中调用Flash里面的组建或者自己搭建的界面,所以抽了点时间写了一个游戏开发中常用的聊天组建提供有用之人学习

    2022年6月1日
  • 百度网盘网页版加速播放(有可用的网站吗)

    源码名称:百度网盘解析加速工具网页版源码环境:PHP7+MySQL源码功能:通过curl获取网盘文件信息,处理后显示在网页中。通过api接口以及SVIP账号的Cookie(BDUSS)获取高速下载链接。本质就是用会员账号获取下载地址并发送给访客。首先下载项目文件。然后访问install.php文件并填写相关信息进行安装。如果使用数据库,则需要先点击检查数据库连接连接数据库,保证账号密码正确。最后点击提交即可。安装完成后可直接使用,站长可进入sett

    2022年4月16日
  • 积分中值定理_三个中值定理的公式

    积分中值定理_三个中值定理的公式设$f:[a,b]\to\mathbf{R}$是区间$[a,b]$上的连续函数,其中$a,b\in\mathbf{R}$且$a<b$.则存在$a<\varepsilon<b$,使得

    2022年8月4日
  • Windows 7下安装MongoDB

    Windows 7下安装MongoDB

    2022年2月7日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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