Python+Request+Allure for API interface test automation (1)

       Let me briefly record the process of my attempt to automate interface testing. A basic goal is to be able to use python to write interface test code, and to make it simple enough so that people who do not know python language can easily complete the interface test case writing by referring to examples, and to be able to be integrated with Jenkins to automatically repeat Execution, the test results can be displayed in a chart. Both development and deployment were based on Windows systems, and we encountered many pitfalls during the process. The information on the Internet was too scattered, and we needed to refer to and collect it from multiple sources to get satisfactory results.

(1) python environment preparation

1. Install Python3;

https://www.python.org/downloads/

2. Download the Python development IDE tool pycharm;

http://www.jetbrains.com/pycharm/download/

Registration code: http://idea.lanyus.com

3. Install pip3

https://pypi.org/project/pip/

4. Use pip3 to install common python modules

pip install -U pytest

pip install -U requests

pip install -U requests

pip install -U hashlib

pip install -U json

5. Check PowerShell

Run Powershell as administrator

Run $PSVersionTable in PowerShell to see the version number. The version number must be greater than 3.

6. Install allure

https://docs.qameta.io/allure/#_installing_a_commandline

7. Integrate pytest+allure

https://docs.qameta.io/allure/#_pytest

(2) Jenkins environment preparation

1. Install Java’s JDK;

https://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Download the war package of jenkins;

http://mirrors.jenkins-ci.org/windows/latest

3. Download tomcat

https://tomcat.apache.org/download-80.cgi

Modify the encoding corresponding to *encoding in the tomcat/conf/logging.properties file to UTF-8

4. jenkins plug-in

The Jenkins plug-in is a big pitfall. Since the domestic network is blocked, it is impossible to download the plug-in directly using the default Site, so I have been struggling here for a long time.

System Management-》Plug-in Management-》Advanced

Update Site :https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

Install plug-ins such as allure/html/Git/Pipeline/Python/Ant/maven/Github/Email/PMD/Findbug

5. All configurations of jenkins

System Management-》Global tool configuration Configure Maven, JDK, Python, Allure Commandline, Ant, etc.

(3) API interface testing (especially important)

1. Build a free-style software project

2. Source code management

Source Code Management :Subversion

2、Build

Windows batch tasks:

pytest -s -q --alluredir allure-results --html html\test.html

exit 0

3、Post-build Actions

Results->Path: allure-results

Report path:allure-report

 

Guess you like

Origin blog.csdn.net/zhangzhaokun/article/details/89928976
Recommended