Python+Request+Allure进行API接口测试自动化(一)

       简单记录一下我尝试进行接口自动化测试的过程。一个基本目标就是能够用python来写接口测试代码,并且要做到足够简单,能够让不太懂python语言的人也可以很容易参照例子完成接口的测试用例编写,并且和jenkins能够集成起来自动反复执行,测试结果可以图表的方式显示出来。开发和部署都是用Windows系统,期间有碰到很多坑,网上的资料太零散了,要多方参考和收集才能得到满意的结果。

(一)python环境准备

1、安装Python3;

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

2、下载Python开发IDE工具pycharm;

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

注册码:http://idea.lanyus.com

3、安装pip3

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

4、pip3来安装python常用模块

pip install -U pytest

pip install -U requests

pip install -U requests

pip install -U hashlib

pip install -U json

5、检查PowerShell

以管理员身份运营 Powershell

在PowerShell中运行 $PSVersionTable 来看版本号,要求版本号大于3

6、安装allure

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

7、集成pytest+allure

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

(二)Jenkins环境准备

1、安装Java的JDK;

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

2、下载jenkins的war包;

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

3、下载tomcat

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

修改tomcat/conf/logging.properties文件中的*encoding对应的编码为 UTF-8

4、jenkins插件

Jenkins的插件是一个大坑,由于国内的网络被屏蔽了,直接用默认的Site是无法下载插件的,这里就折腾了很久。

系统管理-》插件管理-》Advanced

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

安装 allure/html/Git/Pipeline/Python/Ant/maven/Github/Email/PMD/Findbug等插件

5、jenkins全部配置

系统管理-》全局工具配置 配置 Maven、JDK、Python、Allure Commandline、Ant 等

(三)API接口测试(特别重要)

1、建一个自由风格的软件项目

2、源代码管理

Source Code Management :Subversion

2、Build

Windows批处理任务:

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

exit 0

3、Post-build Actions

Results->Path: allure-results

Report path:allure-report

 

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值