程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python interface automation testing (2) the idea of interface automation

編輯:Python

When we want to use python Send a http On request , have access to requests library ; When we want to test an interface, we can also pass requests Library to request interface , Here is an example to illustrate :

for example , We need to access an interface http://localhost:8080/login, This is a login interface , The request method is post, The request parameter is username and password, Header information is "Content-Type": "application/json", use requests The request code is as follows :

import requests
data = {
"username": "admin",
"password": "123456"
}
header = {
"Content-Type": "application/json",
}
res = requests.post(url="http://localhost:8080/login", json=data, headers=header)
print(res.text)

From the code above, we can see our data data Request header 、 And How to send the request All mixed together , If it is a single interface, it is OK to say , But there will be dozens in our actual scene 、 Hundreds of interfaces , If you want to write like this, it will be difficult to maintain , At this time, we need some special treatment :

1、 Data separation :

Put the data ( Request parameters ) Put forward separately , Manage alone

2、requests Library secondary encapsulation :

requests Modeling , So that there is no python Basic testers can also write use cases

3、 Public method encapsulation :

For example, mail sending method 、 Database connection method .....

4、 Checkpoint encapsulation :

Second encapsulation assertion method

5、 Use case execution :

Single or batch execution of use cases

6、 The report :

Send test report or nail group report

A set of interface automation is basically this idea , There may be some differences , But the general direction is similar


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved