当前位置:网站首页>Pytest learning ----- detailed explanation of the request for interface automation test
Pytest learning ----- detailed explanation of the request for interface automation test
2022-07-06 17:49:00 【Peng Yuyan in the testing industry】
One 、 Interface automation implementation
Tool classes realize interface automation :
1.Postman+Newman+git/svn+jenkins
2.jmeter+Ant+git/svn+jenkins
Build a code framework to realize interface automation :
Use the development language + Tool class : Such as Java、Python
Two 、 Why do you build an interface automation framework
1. agile development , When iterating over a product project , Generally, the number of interfaces is relatively large , It is convenient for the team to realize interface test version control .( Main cause )
2. The function of the tool is too rigid , Some interfaces are completely impossible to implement ( For example, complex encryption interface , Signature interface, etc ,postman Only use md5 encryption )
3. There are many interfaces with different protocols in the interface project .
4. It's difficult to make mistakes , Inconvenient positioning , It needs to be combined with packet capturing .
5. There is no way to generate beautiful test reports , Especially for outsourcing companies .
6. Multiple interfaces in series , Database validation , Log monitoring, etc
7. Some companies do web automation + Interface automation .
3、 ... and 、Python+requests The module realizes interface automation
1.requests Third party libraries are mainly used to send http request , Interface automation
install requests library :pip install requests

2.requests Overall view
request :
1.requests.get() send out get request
2.requests.post() send out post request
3.requests.delete() send out delete request
4.requests.put() send out put request
5.requests.request() The core approach
Respond to :
import requests
rep = requests.request()
# Return string data
print(rep.text)
# Returns data in dictionary format
print(rep.json())
# Return status code
print(rep.status_code)
# return cookies
print(rep.cookies)
# Returns the encoding format
print(rep.encoding)
# Return response header
print(rep.headers)
3. Interface practice
Request mode :get、post、delete、put
Request parameter type : Key value pair 、JSON Format 、 File format .
import time
import pytest
import requests
# class setup_class:
class TestSendRequsets:
# def setup(self):
# print(" Before each use case is executed ")
# def teardown(self):
# print(" After each use case is executed ")
# @pytest.fixture()
def test_getImgCode(self):
# Interface url
t = time.time()
timess = str(int(round(t * 1000)))
times = str(int(t))
url = "http://124.71.230.185:9002/jeecg-boot/sys/randomImage/" + "" + timess
# Parameters
data = {
"_t": times,
}
# # get request
rep = requests.request('get', url, params=data)
print(rep.text)
# Only execute smoke
# @pytest.mark.smoke
def test_Login(self):
# post request
url = "http://124.71.230.185:9002/jeecg-boot/sys/login"
# Parameters
data = {
"captcha": "[email protected]#2019",
"checkKey": 1637811815838,
"password": "123456",
"remember_me": 1,
"username": "admin"
}
rep = requests.request('post', url, json=data)
statues = rep.json()["success"]
message = rep.json()["message"]
if statues:
print(message)
else:
# raise Exception(message)
print(message)
if __name__ == '__main__':
pytest.main(['-vs']);
Use case management framework : install pytestpip install pytest
The default rules :
1. Test file with test End or already test start
2. Test function to test_ start
3. Test method with Test start , But not with init() Method ;
Be careful :
get Request by params Pass parameters
post Request by json perhaps data Pass parameters , The difference is that :
data:
The data packet dict Dictionary type : By default, the request header is application/x-www-form-urlencoded, Said to form Form transmission , Format a=1&b=2&c=3
json:
The data packet : Whether it's dict Type or str type , The default is application/json, Format {"a":1,"b":2}
json.dumps(data), serialize , Convert data in dictionary format into str Data of type
json.loads(data), Deserialization , hold str Convert format to dictionary format .
![]()
The following is the supporting information , For doing 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you !
Last : It can be in the official account : Programmer Xiaohao ! Get a free copy of 216 Page software testing engineer interview guide document information . And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One button, three links ! Friends who like software testing , You can join our testing technology exchange group :779450660 There are various software testing resources and technical discussions )
边栏推荐
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
- Flink parsing (VII): time window
- Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
- 重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- 基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
- 04 products and promotion developed by individuals - data push tool
- Flink analysis (II): analysis of backpressure mechanism
- Debug xv6
- Solr appears write Lock, solrexception: could not get leader props in the log
猜你喜欢
![[ASM] introduction and use of bytecode operation classwriter class](/img/0b/87c9851e577df8dcf8198a272b81bd.png)
[ASM] introduction and use of bytecode operation classwriter class

C WinForm series button easy to use

Flink analysis (II): analysis of backpressure mechanism

面试突击62:group by 有哪些注意事项?

酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅

Automatic operation and maintenance sharp weapon ansible Foundation

scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月

After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer

Grafana 9 is officially released, which is easier to use and more cool!

Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
随机推荐
Flink parsing (III): memory management
Mysqlimport imports data files into the database
Growth of operation and maintenance Xiaobai - week 7
The art of Engineering (3): do not rely on each other between functions of code robustness
传统家装有落差,VR全景家装让你体验新房落成效果
[introduction to MySQL] third, common data types in MySQL
Selenium test of automatic answer runs directly in the browser, just like real users.
VR全景婚礼,帮助新人记录浪漫且美好的场景
The NTFS format converter (convert.exe) is missing from the current system
Unity粒子特效系列-闪星星的宝箱
Development and practice of lightweight planning service tools
Unity particle special effects series - treasure chest of shining stars
FlutterWeb浏览器刷新后无法回退的解决方案
Flet教程之 13 ListView最常用的滚动控件 基础入门(教程含源码)
How uipath determines that an object is null
虚拟机启动提示Probing EDD (edd=off to disable)错误
Openharmony developer documentation open source project
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
学 SQL 必须了解的 10 个高级概念
Flink parsing (IV): recovery mechanism