Allure isn’t technically a testing framework, but it’s an open source tool for generating nice test reports that works well with the Pytest testing framework.
In other words, Allure is a process that uses the data generated by Pytest to generate a consistent, aesthetically pleasing test report.
A: I’ve had a Allure for a while
1. What isAllure
Allure is an open source test report framework developed by Qameta Software to make it easier for anyone to generate and read. It supports most test frameworks, such as Pytest, TestNG, etc., easy to use and easy to integrate.
2. Allure
The Allure framework is based on other testing frameworks, such as Pytest.
# windows env
source env/Scripts/activate
# Install pyTest and pytest-allure-adaptor
pip3 install pytest
# Allure Pytest Adaptor is a plugin for Pytest.
# allure- Pytest is a bit newer and recommended
pip3 install pytest-allure-adaptor
pip3 instal allure-pytest
The Allure tool is used to convert pyTest data into HTML
# Install the Linux environment
Add allure to Linux feeds now
sudo apt-add-repository ppa:qameta/allure
Update the local source
sudo apt-get update
# installation allure, [allure cannot use solution] (https://askubuntu.com/questions/1168821/allure-report-installed-but-not-findable)
sudo apt-get install allure
# If the above method does not work, use the following methodThe curl - o allure - server. TGZ - Ls https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.6.0/allure-2.6.0.tgz sudo Tar -zxvf allure-2.6.0.tgz -c /opt/ sudo ln-sThe/opt/allure - server/bin/allure/usr/bin/allure allure - versionThe Scoop tool (Chocolatey doesn't know why it couldn't be installed) is the best way to install Windows
# to install/run (https://juejin.cn/post/6844904017823285262)
Check whether scCOP is installed successfully
scoop --version
# installation allure
scoop install allure
# Check allure to see if it was installed successfully
allure --version
Copy the code
Pytest integrated Allure
Allure needs to be configured in both the test file and the test wildcard file (conftest.py) to take effect.
1. Allure
Aullre has several features:
@allure. Feature # is used to define the feature under test and the demand point of the product under test. @allure. Story # is used to define the user scenario of the feature under test, i.e. the sub-feature point with allure. Attach # is used to input additional information to the test report, usually test data. @pytest.allure. Step # Is used to output some generic functions as test steps to the report, where this function is called to output steps to the reportCopy the code
2. Pytest integrated Allure
Sample test files, generate test data, and further generate allure test reports
#! /usr/bin/env python
# -*- encoding: utf-8 -*-
""" @File : test_allure_shopping.py @Time : 2019/12/1017:34 @Author : Crisimple @Github : https://crisimple.github.io/ @Contact : [email protected] @License : (C)Copyright 2017-2019, Micro-Circle @Desc : None """
import pytest
import allure
# allure. Feature
@allure. Feature (" report shopping cart ")
class TestAllure(object):
Define user scenarios
@allure. Story (" Add to cart ")
def test_add_goods_cart(self):
Call the step function
login("crisimple"."123456")
# Break the test case into several steps and print the test steps into the test report, step two
with allure.step("Browse merchandise") :# allure. Attach -- Print some additional information
allure.attach(Products "1"."C")
allure.attach("Item 2"."C")
Step # 3
with allure.step("Add goods"):
allure.attach(Products "1".2)
allure.attach("Item 2".3)
Step # 4
with allure.step("Check Commodity"):
allure.attach("Item 1 added successfully"."Two of them.")
allure.attach("Failed to join item 2"."Total of 0")
@allure. Story (" Keep shopping ")
def test_continue_shopping_cart(self):
login("crisimple"."123456")
allure.attach("Three goods".4)
print("Continued shopping success")
@allure. Story (" Reduce product failure ")
def test_edit_shopping_cart(self):
login("crisimple"."123")
assert 0
@pytest.mark.skip(reason=" Delete shopping cart not executed ")
@allure. Story (" Delete shopping cart ")
def test_delete_shopping_cart(self):
login("crisimple"."123")
print()
When this function is called, the report outputs a step. The step name is usually the function name. Such a function is usually called a step function
@allure. Step (" User login ")
def login(user, passwd):
if user == "crisimple" and passwd == "123456":
print(user, passwd)
print("Login successful")
else:
print(user, passwd)
print("Login failed. Please try again.")
Copy the code
Generate test reports
1. Pytest Generates a test report
Execute all test cases
pytest ./Allure/test_allure_shoping.py --alluredir ./Allure/result/
Specify features or Stories to execute a portion of the test cases, such as the test cases for the 'Add to cart' subfunction under 'Report cart'
pytest ./Allure/test_allure_shopping.py --allure_features="Report shopping cart" --allure_stories="Add to cart" ../Allure/part_result/
Copy the code
Generate test reports
Generate test reports
allure generate ./Alluer/result/ -o ./Allure/report/ --clean
Open the test reportAllure open -h 127.0.0.1 -p 8083./ allure /report/Copy the code
Open the test report, cowhide is can switch the Chinese version
Overview Categories Behavior Graphs Timeline PackagesCopy the code
Allure and Jenkins
For large-scale test teams, automated test deployment will be integrated into Jenkins and built into automated deployment.
4.1 Jenkins configures Allure
Install Allure plugin
4.2 create a job
The configuration paths must be consistent
source env/bin/activate
echo "**************Welcome to env**************"
echo "**************pytest create test data**************"Pytest/full path /Allure/test_allure_shopping.py --alluredir${WORKSPACE}/allure-results/
echo "**************report has generated done**************"
Copy the code
4.3 Project Execution
Build the project immediately.