The use of Allure in python (obtain selenium test report)

Note: Use of pytest

One method that can be used to set the way python runs test cases is pytest:
Insert image description here

The file name must start with test_ or end with _test

Test case/method function name must start with test_

Class name CamelCase naming The first letter of the word is capitalized and starts with Test

1.Allure download and installation

Download the .zip compressed package installation file for win system

Insert image description here

After downloading and installing Allure and decompressing it, put the path of its bin directory into the environment variable.

Local Allure installation path D:\BaiduNetdiskDownload\allure-2.13.1\bin

Insert image description here

2.Creation of python project and writing of test code

Create a new project in the python environment. Open the Terminal in the lower left corner. You need to use the pip command to download pytest selenium and allure-pytest

pip install pytest
pip install selenium
pip install allure-pytest

After the python code is written, you need to import allure and pytest

import allure
import pytest
# 测试用例1  断言 判断1==1是否成立运行通过
def test_demo1():
    assert 1==1

3. Test code execution and generate Allure report

Test code execution and generation of allure test reports in .json format and convert test reports into .html format for browser viewing

Where test_allure_demo1.py is the file name where the test case is located

(venv) D:\PyCharm\PythonProject\seleniumAllurereport>pytest test_allure_demo1.py 
--alluredir=output 

(venv) D:\PyCharm\PythonProject\seleniumAllurereport>allure generate output -o report --clean
(1) The Allure test case runs and generates a test report (a .json file at the beginning) and then opens the test report in the web page

(2) The Allure report is converted from .json to .html format so that it can be opened in the browser

Try not to use the following. The web version of the test report cannot be opened repeatedly.

Insert image description here

(3) The location of the test report opened by Allure in the browser is C:\Users\Administrator\AppData\Local\Temp

Insert image description here

Click Terminal in python to enter the command line

First execute the code and run it in the form of pytest test_allure_demo1.pyThe generated allure report is a file in .json format

Create a new output folder in the python project and put the .json format report file generated by allure into it.

(venv) D:\PyCharm\PythonProject\seleniumAllurereport>pytest test_allure_demo1.py --alluredir=output

In python environment, enter the command line from Terminal to execute allure serve output

(venv) D:\PyCharm\PythonProject\seleniumAllurereport>allure serve output

If 'allure' is displayed it is not recognized as an internal or external command, operable program or batch file.

(Restart pycharm and try allure serve output again.
If it still doesn't work, take the following method and enter the path where the python project is located on the cmd command line and execute it.
allure serve output statement (just)

We can view allure's report in another way

win+R enter cmd to enter the command line

Switch to the path where the python project is located D:\PyCharm\PythonProject\seleniumAllurereport>

Enter the command allure serve output. After running, the report web page will pop up.

D:\PyCharm\PythonProject\seleniumAllurereport>allure serve output

(output is the folder name of the allure report in the python project folder after the test case is executed in the python project. There is a .json file inside)

The report generated after executing allure serve output on the cmd command line is

C:\Users\Administrator\AppData\Local\Temp\ directory. Remember to delete it in time.

Guess you like

Origin blog.csdn.net/weixin_44992225/article/details/130587413