资源描述:
《python学习笔记-excel用例输入.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.python学习笔记(接口自动化框架V2.0)这个是根据上次框架版本进行的优化用python获取excel文件中测试用例数据通过requets测试接口、并使用正则表达式验证响应信息内容生成xml文件测试报告版本更新内容:1.整理了CreateTest.test_main()流程逻辑2.优化了testcase.xls文件格式3.添加了生成XML文件测试报告代码如下:1#!/usr/bin/envpython2#-*-coding:utf_8-*-3#获取测试用例文件excel45importxlrd6importjson789classCreateExcel
2、:10def__init__(self):优质范文.11pass1213@classmethod14defopen_excel(cls):15path="testcase.xls"16workbook=xlrd.open_workbook(path)17table=workbook.sheets()[0]18returntable1920#获取sheet2122@classmethod23defget_nrows(cls,table):24nrows=table.nrows25returnnrows2627#获取行号2829@classmethod30def
3、get_id(cls,table,nrows):31testid=[]32foriinrange(1,nrows):33testid.append(table.cell(i,0).value)34returntestid3536@classmethod37defget_name(cls,table,nrows):38testname=[]39foriinrange(1,nrows):40testname.append(table.cell(i,1).value)41returntestname4243#获取用例name4445@classmethod46de
4、fget_data(cls,table,nrows):47testdata=[]48foriinrange(1,nrows):49try:50data=json.loads(table.cell(i,2).value)51testdata.append(data)52exceptValueError:53testdata.append(None)54returntestdata5556#获取data接口参数优质范文.5758@classmethod59defget_url(cls,table,nrows):60testurl=[]61foriinrange(
5、1,nrows):62testurl.append(table.cell(i,3).value)63returntesturl6465#获取接口测试url6667@classmethod68defget_method(cls,table,nrows):69testmethod=[]70foriinrange(1,nrows):71testmethod.append(table.cell(i,4).value)72returntestmethod7374#获取接口测试method7576@classmethod77defget_pattern(cls,tabl
6、e,nrows):78testpattern=[]79foriinrange(1,nrows):80testpattern.append(table.cell(i,5).value)81returntestpattern8283#获取接口期望响应结果841#!/usr/bin/envpython2#-*-coding:utf_8-*-3#测试核心组件45importrequests6importre7fromdatetimeimportdatetime8fromcreateexcelimportCreateExcel9fromxml.domimportmin
7、idom10importsys111213classCreateTest:14reload(sys)15sys.setdefaultencoding("utf-8")16优质范文.17#避免字符串写入文件出错1819def__init__(self):20pass2122@classmethod23deftest_api(cls,method,url,data):24globalresults25try:26ifmethod=="post":27results=requests.post(url,data)28ifmethod=="get":29result
8、s=requests.get(url,data)30