Super detailed, automated testing allure test report practice (summary)


Preface

Allure can output very beautiful test reports, and can also be perfectly combined with pytest. It can not only render pages, but also control the execution of use cases. The following is a detailed introduction and summary of the use of allure.

Environment that needs to be prepared:
python;
pytest;
allure-pytest;
allure tool;

1. allure use case description

Instructions Parameter value Parameter Description
@allure.epic() epicdescription Concepts in agile, describing and classifying use cases or sets of use cases
@allure.feature() module name Similar to epic, but lower level than epic
@allure.story() user stories Similar to epic, but lower than feature level
@allure.title (title of the use case) Use case title Rename use case name of html report
@allure.testcase() Test case link address Similar to link
@allure.issue() defect Similar to link
@allure.description() Use case description Description of test cases
@allure.step() Steps Steps to conduct test cases
@allure.severity() use case level blocker,critical,normal,minor,trivial
@allure.link() Link Define a link to display in the test report (recommended)
@allure.attachment() appendix Add attachments to report

2. allure practical demo

# -*- coding:utf-8 -*-
import pytest
import allure
from base.log import Logger
logger = Logger(logger_name='allure', level='error').get_logger()


@pytest.fixture(scope="session")  # 用例前置操作
def login_fixture():
    # 比如登录获取token操作
    return "token:xx"


@allure.step("用例步骤1")
def step_1():
    logger.info("用例操作---------------步骤1")
    return True


@allure.step("用例步骤2")
def step_2():
    logger.info("用例操作---------------步骤2")
    return False


@allure.step("用例步骤3")
def step_3():
    logger.info("用例操作---------------步骤3")
    return True


@allure.epic("可以对用例或用例集进行描述分类(若出现多个时,内容一致则自动归为一类)")
@allure.feature("对用例集或用例进行描述分类---与epic类似,只是比epic级别低")
@allure.story("对用例集或用例进行描述分类---与epic类似,只是比feature级别低")
class TestAllureDemo:

    @allure.testcase("https://xxx/testcase/list",
                     name='用例链接testcase')  # 为了更好的链接到问题分类或者bug、测试用例地址中(url、name两个参数,可不填写name;可以用@allure.link)
    @allure.link("https://xxx/testcase/list", name='用例链接link')  # 与testcase没有多大区别,从可读性角度还是建议选择@allure.link
    @allure.issue("https://xxx/testcase/list", name='用例链接issue')  # 与testcase区别在于有小虫子图标
    @allure.title("用例的标题")  # 可参数化标题
    @allure.story("用例分类:1")  # 可参数化标题
    @allure.severity("critical")    # 用例等级(blocker critical normal minor trivial)
    def test_case_1(self, login_fixture):
        """
        1.用例描述
        2.用例步骤
        3.预期结果
        """
        logger.info(login_fixture)  # 获取用例前置的信息,比如登录token
        assert step_1()
        assert step_2()

    @allure.story("用例分类:2")
    def test_case_2(self, login_fixture):
        logger.info("测试用例2")
        assert step_1()
        assert step_3()


@allure.epic("冒烟自动化用例")
class TestDemo2:

    @allure.story("用例分类:3")
    def test_case_3(self, login_fixture):
        logger.info("测试用例3")
        step_1()

    @allure.story("用例分类:4")
    def test_case_4(self, login_fixture):
        logger.info("测试用例4")
        step_3()

3. Command line parameters of allure

When pytest executes use cases, you can add the mark parameter all to control which use cases are executed.

--allure-severities=SEVERITIES_SET
                        Comma-separated list of severity names. Tests only
                        with these severities will be run. Possible values
                        are: blocker, critical, normal, minor, trivial.
--allure-epics=EPICS_SET
                        Comma-separated list of epic names. Run tests that
                        have at least one of the specified feature labels.
--allure-features=FEATURES_SET
                        Comma-separated list of feature names. Run tests that
                        have at least one of the specified feature labels.
--allure-stories=STORIES_SET
                        Comma-separated list of story names. Run tests that
                        have at least one of the specified story labels.
--allure-link-pattern=LINK_TYPE:LINK_PATTERN
                        Url pattern for link type. Allows short links in test,
                        like 'issue-1'. Text will be formatted to full url
                        with python str.format().

Examples are as follows:

# 选择运行你要执行epic的用例
pytest --alluredir ./report/allure --allure-epics=epic对大Story的一个描述性标签

# 选择运行你要执行features的用例
pytest --alluredir ./report/allure --allure-features=模块2

# 选择运行你要执行features的用例
pytest --alluredir ./report/allure --allure-stories="用户故事:1"

4. Execute the script-allure to generate the report and start the report

Running mode one:
Run pytest in command line mode to produce test result files

pytest demo.py --alluredir ./report/allure

The allure program starts the file that has been produced

allure serve ./report/allure

Running method two:
write startup method and run pytest

pytest.main([allure_demo.py, "--alluredir", "report/result"])

Use the process to start the allure service

import subprocess

subprocess.call('allure generate report/result/ -o report/html --clean', shell=True)
subprocess.call('allure open -h 127.0.0.1 -p 9999 ./report/html', shell=True)

(Both methods require the allure tool to be installed)

5. Report renderings and annotations

E1

The following is the most comprehensive software testing engineer learning knowledge architecture system diagram in 2023 that I compiled.

1. Python programming from entry to proficiency

Please add image description

2. Practical implementation of interface automation projects

Please add image description

3. Web automation project actual combat

Please add image description

4. Practical implementation of App automation project

Please add image description

5. Resumes of first-tier manufacturers

Please add image description

6. Test and develop DevOps system

Please add image description

7. Commonly used automated testing tools

Please add image description

8. JMeter performance test

Please add image description

9. Summary (little surprise at the end)

On the stage where the sun shines, struggle is the brilliance of blooming; on the journey of wind and rain, hard work achieves glory without regrets. Persevere, move forward bravely, water the flowers of your ideals with your sweat, and let your hard work and perseverance create a dazzling masterpiece of life!

Victory belongs to those who are not afraid of hardships and dare to fight. Only by moving forward can we break through ourselves and chase our dreams. Persevere and never give up, and never stop struggling. Only in this way can you write your own glorious chapter and achieve unlimited possibilities!

Struggle is the passion of life, and hard work is the stage for realizing dreams. No matter how bumpy the road ahead is, persistent pursuit and unyielding perseverance will open up the road to success. Burn faith in your heart, sweat hard, achieve your own glory, and create an extraordinary life!

Guess you like

Origin blog.csdn.net/m0_60054525/article/details/131918923