Python接口自动化
接口自动化基础
Automatic_tester
在自动化的道路越走越远
展开
-
8.接口自动化下载图片
import requests def downloadImage(): url = "https://csdnimg.cn/cdn/content-toolbar/csdn-logo_.png?v=20190924.1" with requests.get(url)as response: data = response.content w...原创 2020-04-01 14:08:11 · 207 阅读 · 0 评论 -
7.requests用yaml做数据驱动
#读取yaml文件 import yaml, os class Conf(object): def __init__(self, file): self.file = file def readYaml(self, sec, key): with open(self.file, encoding='utf-8') as fp: ...原创 2020-03-19 10:29:06 · 524 阅读 · 0 评论 -
6.python接口自动化保持Session会话
import requests url = "https://www.xxx.com/login" s = requests.session() # 建立一个Session data = {"name": "admin", "password": "123456" } response = s.post(url, data=data) # session登录...原创 2019-12-31 13:53:30 · 595 阅读 · 0 评论 -
5.python接口自动化读取json、yaml、ini文件
testdata.json文件: { "user1": {"account":"admin","password":"654321","message":"登录成功" }, "user2": {"account":"admins","password":"654321","message":"登录成功"} } testdata.ini文件: [user] account=admi...原创 2019-12-30 10:28:44 · 403 阅读 · 0 评论 -
4.python接口自动化常用的加密算法MD5,sha256
MD5加密算法 # md5加密算法 import hashlib class Secret(object): def __init__(self, word): self.word = word # md5加密方式 def Md5(self): return hashlib.md5(self.word.encode('utf-8')...原创 2019-12-27 10:45:05 · 310 阅读 · 0 评论 -
3.python接口自动化ddt数据驱动
一、数据驱动参数文件Params.json { "账号错误,密码错误": {"account": "admindsa", "password": "123456d","result": "账号或者密码错误"}, "账号正确,密码错误": {"account": "admin", "password": "123","result": "账号或者密码错误"}, "...原创 2019-12-27 10:24:43 · 462 阅读 · 0 评论 -
2.python接口自动化发送post请求上传文件
import requests #打开文件 fileData={'file':open(log.gif).'rb'} #发送请求 response=requests.post('https://www.xxx.fileupload',files=fileData) #查看请求结果 print(response.json())原创 2019-12-27 10:11:26 · 729 阅读 · 0 评论 -
1.python接口自动化发送post请求
request库中发送post请求且参数类型为json的两大传参方式: 1.使用‘json=data’直接传参 import requests #定义接口地址 url="https://www.xxx.com/api/ih/login" #构造参数 data={"account":"admin","password":"654321"} #发送请求 response=requests.pos...原创 2019-12-27 10:03:15 · 318 阅读 · 0 评论