#coding:utf-8
import xlrd,requests,json
import sys
reload(sys)
sys.setdefaultencoding("utf8")
url1 = 'http://xxx.xxx.x.xxx/x/x/merchant.login'
xlsfile1 = r'E:/Testcoder.xls'
#获取excel中的测试数据
def excel_data():
# 打开xlsfile1xls文件
book = xlrd.open_workbook(xlsfile1)
# 读取book文件中的第一个sheet
api_sheet = book.sheet_by_index(0)
# 获取sheet中有多少行有数据
nrows = api_sheet.nrows
# 循环读取每行数据
for i in range(1,nrows):
# 读取i行0列的值
idr = api_sheet.cell(i,0).value
phone = api_sheet.cell(i,1).value
password = api_sheet.cell(i,2).value
apt = api_sheet.cell(i,3).value
remarks = api_sheet.cell(i,4).value
# 把数据存在data1中
data1 = {"phone":phone,"password":password,"apt":apt}
# 调用 info函数
ac_text = info(url1, data1)
# 读取json数据
masser = json.loads(ac_text)
dfs = int(masser['code'])
if dfs == 0:
print idr,remarks
else:
print idr,remarks,masser['message']
strs = idr+remarks+masser['message']
# 调用io_write函数
io_write(strs+"\n")
#获取页面内容
def info(url,date2):
# 模拟post请求
r = requests.post(url, data=date2)
# 获取数据
return r.text
#写入文件
def io_write(strs):
# 文件保存路径
file = r'E:/Testcoder.txt'
try:
file_object = open(file, 'a')
# 写入
file_object.write(strs)
finally:
# 关闭
file_object.close()
if __name__=="__main__":
excel_data()
python 登录接口测试
最新推荐文章于 2024-06-24 21:11:55 发布