当前位置: 首页 > news >正文

门户网站设计思路先锋设计网站

门户网站设计思路,先锋设计网站,精美网页欣赏,商户网站建设公司本节介绍#xff0c;使用python实现接口自动化实现。 思路#xff1a;讲接口数据存放在excel文档中#xff0c;读取excel数据#xff0c;将每一行数据存放在一个个列表当中。然后获取URL,header,请求体等数据#xff0c;进行请求发送。 结构如下 excel文档内容如下#x… 本节介绍使用python实现接口自动化实现。 思路讲接口数据存放在excel文档中读取excel数据将每一行数据存放在一个个列表当中。然后获取URL,header,请求体等数据进行请求发送。 结构如下 excel文档内容如下 一、Common与Config包 Config里面的config.ini主要存放的默认的路径内容等如excel文件的地址,工作簿名称 Common里面主要是一些通用的方法目前只需要读取config里面的数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import configparser import os.path #读取config里面的数据 class ReadConfig:     def __init__(self):         self.filePath  os.path.abspath(os.path.dirname(os.path.dirname(__file__)))\\config\\config.ini         print(self.filePath)         self.config  configparser.ConfigParser()         self.config.read(self.filePath,encodingutf-8)     def get_data(self,section,key):         return self.config.get(section,key)     def get_list(self,section):         return self.config.items(section) if __name__  __main__:     conf  ReadConfig()     print(conf.get_data(excel, file_path)) 二、excel包 主要是实现读取excel表格数据此处用的是openpyxl进行实现 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import openpyxl class ReadExcel:     def __init__(self,excel_path,sheet_name):         self.excel_path  excel_path         self.sheet_name  sheet_name     def get_data(self,row):         workbook  openpyxl.load_workbook(self.excel_path)         sh  workbook[self.sheet_name]         data  []         for c in list(sh.rows)[row]:             data.append(c.value)         return data if __name__  __main__:     ex  ReadExcel(request.xlsx,Sheet1)     print(ex.get_data(0))     print(ex.get_data(1))     print(ex.get_data(2))     print(ex.get_data(3))     print(ex.get_data(4)) 三、requests包 主要用于发送请求这里只写了常用的get post请求需要可以加其他的。 由于post请求体有多种此处只区分了两种其他的可以加上。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 import json import requests class Request:     def get_url(self,url,headersNone,parasNone):         if urlNone:             print(URL地址为空)         elif paras  None:             r  requests.get(url,headersheaders,paramsparas)         else:             r  requests.get(url, headersheaders, paramsjson.loads(paras))         return r     def post_url(self,url,content_type,headersNone,payloadNone):         if urlNone:             print(URL地址为空)         else:             if content_type  application/json:                payload_json  json.dumps(payload)                r  requests.post(url,headersheaders,datapayload_json)             elif content_type application/x-www-form-urlencoded:                 r  requests.post(url,headersheaders,datapayload)             else:                 print(no this content-type)             return r     def choose_method(self,method,url,content_type,headersNone,payloadNone):         if method  get:             return self.get_url(url,headers,payload)         elif method  post:             return self.post_url(url,content_type,headers,payload)         else:             print(no this method request) 四、testcases包 使用pytest框架进行自动化测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import json import pytest from autoStruct.apiAuto.common.requests import Request from autoStruct.apiAutoTesting.common.readConfig import ReadConfig from autoStruct.apiAutoTesting.excel.readExcel import ReadExcel class TestApi:     def setup_class(self):         file_path  ReadConfig().get_data(excel, file_path)         sheet_name  ReadConfig().get_data(excel, sheet_name)         self.ex  ReadExcel(file_path, sheet_name)     pytest.mark.parametrize(num,[1,2,3,4,5])     def testcase(self,num):             data  self.ex.get_data(num)             print(data)             if data[3]None:                 r  Request().choose_method(data[1],data[0],data[4],json.loads(data[2]),data[3])             else:                 r  Request().choose_method(data[1], data[0], data[4], json.loads(data[2]), json.loads(data[3]))             print(r.text) if __name__  __main__:     pytest.main([-vs,testapi.py]) Python接口自动化测试零基础入门到精通2023最新版
http://www.lakalapos1.cn/news/45195/

相关文章:

  • asp建设网站太原百度公司地址
  • 网站文章不显示工程建筑模板价格
  • 小榄做网站怎样做心理咨询网站
  • 科技公司网站制作公司网站建设费入何科目
  • 网站开发劳动合同范本网站建设的实训技术总结
  • 用层还是表格做网站快别人网站的字体
  • 网站建设设备行业网站建设策划方案
  • 建设视频网站要求吗专做美妆的视频网站
  • 个人网站logo生成网站文件app
  • 网站死链接怎么删除wordpress多域名配置文件
  • 安庆网站建设工作室推荐邵阳网站建设
  • 巫山那家做网站厉害织梦手机网站怎么修改密码
  • 如何创建一个站点软文有哪些
  • 潍坊设计网站建设铭万做的网站怎么样
  • 同声传译公司网站建设石家庄购物网站排名
  • 有关建筑网站建设方案东莞齐诺做网站
  • 新网站做百度百科中国seo排行榜
  • 网站建设与管理工作内容安徽网站关键字优化
  • 公司怎么建设网站淄博网站建设电话咨询
  • 临沂城乡建设管理局网站wordpress 文章图片自动添加
  • 做网站提供服务器吗查询网站备案密码是什么
  • 台州路桥做网站的公司石家庄房产网上备案查询
  • 网站浏览器兼容性通用网页版qq空间登录入口官网
  • 柳州市城市建设局网站视频推广平台
  • 网站开发设计技术wordpress 密码明文
  • 西安+医疗网站建设魔改wordpress主题
  • 第三方网站做app花都网站建设公司天蝎信息
  • 怎样用织梦建设网站wordpress发布网站
  • 领取流量网站海诚网站建设
  • 怎么做有数据库的网站公众号seo排名软件