日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python自动化接口测试excel用例串行之行_python 读取 Excel 自动化执行测试用例

發(fā)布時間:2024/7/5 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python自动化接口测试excel用例串行之行_python 读取 Excel 自动化执行测试用例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python 讀取 Excel 自動化執(zhí)行測試用例

Excel 測試用例的讀取

安裝 python 操作Excel 的庫

pip install xlrd/xlwt/xlutils (安裝三個操作庫)

接口請求代碼構(gòu)建

import requests

from random import randint

import xlrd

import json

class My_request(object):

# 對返回值進行處理

def __str__(self):

# return "%r"%self.connect()

return str("%r"%self.connect())

# 獲取表格數(shù)據(jù)

def connect(self):

excelDir = '../data/動畫繪本館測試用例.xls'

# 打開Excel文件 formatting_info=True :保持原樣式

self.workBook = xlrd.open_workbook(excelDir,formatting_info=True)

# 獲取所有表名

sheets = self.workBook.sheet_names()

# 需要執(zhí)行的sheet

workSheet = self.workBook.sheet_by_name('測試用例2')

# 獲取一行

# cellData = workSheet.row_values(1)

# 獲取單元格 獲取的不是字符串 而是excel 格式參數(shù)

cellData = workSheet.cell(1, 0)

return cellData.value

# token函數(shù) 調(diào)用函數(shù)就可獲取token值 再用到新增接口

def get_token(self):

# 獲取token

token_urls = 'http://47.96.181.17:9090/rest/toController'

payload = {'userName': 'J201903070064', 'password': '362387359'}

# 發(fā)送請求 json 請求體

res = requests.post(token_urls, json=payload)

return res.json()['token']

# 新增用戶接口

def add_user(self,bodyData):

"""

:param bodyData: request body

:return: res data

"""

self.addUsr_url = 'http://47.96.181.17:9090/rest/ac01CrmController'

# 對字符串轉(zhuǎn)換字典 json 串

self.payload = json.loads(bodyData)

# 對手機號進行參數(shù)化

self.payload['aac030'] = f'134{randint(11111111,99999999)}'

self.header_addusr = {'Content-Type': 'application/json', 'X-AUTH-TOKEN': self.get_token()}

# # 發(fā)送請求 url 請求體

res = requests.post(self.addUsr_url,json=self.payload,headers = self.header_addusr)

self.rest = res.json()

# 打印輸出結(jié)果 是否注冊成功

print(res.json())

return res.json()

def write_index(self,datas):

from xlutils.copy import copy

# 對表復(fù)制 原始的測試用例不會改變

newWoekBook = copy(self.workBook)

# 取拷貝的excel的sheet 下標(biāo)

newSheet = newWoekBook.get_sheet(1)

# 寫入數(shù)據(jù) 第一行第一列

newSheet.write(1, 1, datas)

# 保存新生成的 excel對象

newWoekBook.save('../data/res.xls')

def write_in(self):

# 如果已經(jīng)有數(shù)據(jù)了 就需要對原表進行復(fù)制

if self.rest['message'] == '成功':

info = 'pass'

self.write_index(info)

else:

info = 'fail'

self.write_index(info)

if __name__ == '__main__':

re = My_request()

re.add_user(re.connect())

re.write_in()

測試結(jié)果寫入到Excel

文件不存在 — 新建excel — 寫 — xlwt

文件本身存在–另存為寫入excel–xlutils

def write_index(self,datas):

from xlutils.copy import copy

# 對表復(fù)制 原始的測試用例不會改變

newWoekBook = copy(self.workBook)

# 取拷貝的excel的sheet 下標(biāo)

newSheet = newWoekBook.get_sheet(1)

# 寫入數(shù)據(jù) 第一行第一列

newSheet.write(1, 1, datas)

# 保存新生成的 excel對象

newWoekBook.save('../data/res.xls')

def write_in(self):

# 如果已經(jīng)有數(shù)據(jù)了 就需要對原表進行復(fù)制

if self.rest['message'] == '成功':

info = 'pass'

self.write_index(info)

else:

info = 'fail'

self.write_index(info)

總結(jié)

以上是生活随笔為你收集整理的python自动化接口测试excel用例串行之行_python 读取 Excel 自动化执行测试用例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。