Python加requests框架实现接口自动化测试
2021-05-31 23:03
标签:info 框架 sage art alt poi log res customer 找了一个不需要验证码登录的网站,康爱多网上药店,第一次研究Python+requests框架实现接口自动化,选择登录-加购-下单-取消订单-删除订单一条业务链五个接口测试,代码如下: import requests # 登录 最终测试结果: Python加requests框架实现接口自动化测试 标签:info 框架 sage art alt poi log res customer 原文地址:https://www.cnblogs.com/zengyu0714/p/14728540.html
import time
session = requests.session()
body = {
‘userName‘: ‘xxxxxxxxxxx‘,
‘pass‘: ‘xxxxxxxxx‘
}
login = session.post(‘https://user.360kad.com/Login/AjaxLoginV2‘, data=body)
print(login.text)
# 加入购物车
cartparam = {
‘id‘: 1406,
‘quantity‘: 1,
‘buyType‘: 0,
‘sellerCode‘: ‘‘,
‘rd‘: 0.7634724674063651
}
cart = session.get(‘https://www.360kad.com/cart/AddCart‘, params=cartparam)
print(cart.text)
# 提交订单
orderdata = {
‘AddressId‘: 11710216491,
‘PayType‘: 1,
‘InvoiceType‘: 0,
‘InvoiceTitle‘: ‘‘,
‘InvoiceCustomerType‘: 1,
‘InvoiceDutyParagraph‘: ‘‘,
‘IsInvoice‘: 0,
‘CartType‘: 0,
‘SendTimeType‘: 0,
‘Remark‘: ‘‘,
‘CouponCode‘: ‘‘,
‘PointsAmt‘: 0,
‘SendType‘: 1,
‘IsFreightInsurance‘: ‘false‘,
‘IsExchangeInsurance‘: ‘false‘
}
order = session.post(‘https://cart.360kad.com/Order/CreateOrder‘, data=orderdata)
print(order.text)
time.sleep(3)
# 取消订单
orderid = order.json()[‘Message‘] # 调用上一接口订单编号,变量名为orderid
ordercancel = {
‘orderCode‘: orderid,
‘cancelTypeCode‘: 200005,
‘cancelReason‘: ‘%E4%B8%8D%E6%83%B3%E4%B9%B0%E4%BA%86‘,
‘_‘: 1620053063259
}
cancelorder = session.get(‘https://user.360kad.com/Order/CancelOrder‘, params=ordercancel)
print(cancelorder.text)
time.sleep(2)
# 删除订单
orderdel1 = {‘orderCode‘: orderid}
orderdel = session.get(‘https://user.360kad.com/Order/Del‘, params=orderdel1)
print(orderdel.text)
下一篇:Go语言实现汉诺塔游戏
文章标题:Python加requests框架实现接口自动化测试
文章链接:http://soscw.com/index.php/essay/89843.html