atp
一、
新建atp目录,该目录下包含bin(存放启动程序等)、config(存放配置程序)、lib(存放过程程序)、logs(存放生成的日志)、cases(存放用例的excel文件)五个目录,并新建一个txt文件teadme.txt,用于书写说明文档。
二、
1、
首先在lib目录下创建tools.py文件,打开excel表格,若打开失败,则生成log;若打开成功,则读取excel中的用例
tools.py如下
import xlrd
from xlutils.copy import copy
from config.setting import my_log,MAIL_INFO,TO,CC
import yagmail
from lib import my_request
import time
def readExcel(file_path):
try:
book = xlrd.open_workbook(file_path)
except Exception as e:
my_log.error('打开用例出错,文件名是%s'%file_path)
return []
else:
all_case = [] #存放所有的用例
sheet = book.sheet_by_index(0)
for i in range(1,sheet.nrows):
row_data = sheet.row_values(i)
all_case.append(row_data[4:8])
return all_case
在config目录下创建setting.py,编辑配置信息,如日志文件名、存放用例的目录等
setting.py如下
import nnlog,os BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) LOG_FILE_NAME = 'atp.log'#日志文件名 ABS_FILE_PATH = os.path.join(BASE_PATH,'logs',LOG_FILE_NAME) my_log = nnlog.Logger(ABS_FILE_PATH) #日志信息 CASE_PATH = os.path.join(BASE_PATH,'cases') #存放用例的目录
os.path.dirname
os.path.abspath
os.path.join
nnlog.Logger 2、在lib目录下创建my_requests.py文件,用于访问接口、并将返回的结果转化为text格式。(json->text、data->text)
import requests
from config.setting import my_log
def post(url,data,header=None,cookies=None,is_json=False):
try:
if is_json:
res = requests.post(url, json=data, headers=header, cookies=cookies).text
else:
res = requests.post(url,data=data,headers=header,cookies=cookies).text
except Exception as e:
my_log.error('接口请求出错,%s'%e)
res = str(e)
return res
def get(url,data,header=None,cookies=None):
try:
res = requests.get(url,params=data,headers=header, cookies=cookies).text
except Exception as e:
my_log.error('接口请求出错,%s'%e)
res = str(e)
return res
3、运行用例,并将返回结果和用例结果写入excel文件中。
在lib目录下的tools.py文件中添加以下程序:
def check_res(res:str,check:str):
new_res = res.replace('": "','=').replace('": ','=')
for c in check.split(','):
if c not in new_res:
return '失败'
return '通过'
def write_res(file_name,res_list):
book = xlrd.open_workbook(file_name)
new_book = copy(book)
sheet = new_book.get_sheet(0)
for row,data in enumerate(res_list,1):
res,status = data
sheet.write(row,8,res) #写入返回结果和运行状态
sheet.write(row,9,status)
new_book.save(file_name)
def str_to_dict(s:str,seq='&'):
#username=niuhanyang&password=123456
d = {}
if s.strip():
for tmp in s.split(seq):
k,v = tmp.split('=')#username,niuhanyang
d[k]=v
return d
def run_case(all_case):
all_res = []
for case in all_case:
url,method,data,check = case
my_log.info('正在运行%s'%url)
data = str_to_dict(data) #把请求参数转成字典
if method.upper()=='POST':
res = my_request.post(url,data)
else:
res = my_request.get(url,data)
status = check_res(res,check) #校验结果
all_res.append([res,status])
return all_res
4、在bin目录下创建start.py文件,启动程序
from lib import my_request
from lib import tools
def main():
all_case = tools.readExcel(r'F:\besttest\python自动化\day-nn\day10\测试用例.xlsx')
all_res = tools.run_case(all_case)
tools.write_res(r'F:\besttest\python自动化\day-nn\day10\测试用例.xlsx')
main()
atp的更多相关文章
- Erp中的ATP和CTP是什么?两者有什么区别?
可用量承诺(Available to Promise,ATP),是一种库存匹配模型,意在最大限度地利用库存产品对客户订单需求做出及时和准确的反应,缩短交货提前期.降低库存水准: 可用生产能力承诺(Ca ...
- poj 1818 ATP
ATP 题意:足球锦标赛使用二分的策略,每次淘汰剩下人的一半,并且数据表明:排名相差k(include)之内的运动员,胜负难料,否则排名前的必定战胜排名后的:问给定n(n = 2x, x∈N, n & ...
- 自学Linux Shell15.2-作业控制命令(jobs/bg/nice/renice/at/atp/atrm/crontab)
点击返回 自学Linux命令行与Shell脚本之路 15.1-作业控制命令(jobs/bg/nice/renice/at/atp/atrm/crontab) 1 控制作业 1.1查看作业 (jobs ...
- 接口自动化(atp,utp)
atp:数据驱动 utp:代码驱动 pip install -r file.txt #安装文件里面有的模块 pip freeze > file.txt #导出你已经安装好的第三方模块
- Available to Promise (ATP) in SAP-SD
One short note before we start off the subject: Availability refers to the projections of future mat ...
- ATP学姐的模拟赛
ATPの水题大赛 声明:不是我觉得这题水,这就是本场模拟赛的名称. T1:求所有的$n$位数中有几个数满足:每一位要么是$A$要么是$B$,并且这个$n$位数的每一位加起来是$A$或$B$的倍数. $ ...
- SAP ATP邏輯可用性檢查
[转http://tqmeng.blog.163.com/blog/static/169263916201162002414612/]SAP ATP邏輯可用性檢查1.可用性檢查群組OVZ2主要用於檢查 ...
- 在SAP C4C里触发SAP ERP的ATP check和Credit check
在C4C里创建一个新的Sales Quote: 添加三个行项目: 执行action "Request External Pricing"会从ERP更新pricing信息,触发ATP ...
- ATP自造8Gb内存颗粒供DDR3使用
随着整个行业已经全面转向DDR4内存,不少厂商都陆续停产了DDR3,并准备好了迎接DDR5,但对于很多特殊用户,尤其是网络和嵌入式领域,仍然对DDR3有着强劲且持续的需求. 工业内存存储厂商ATP E ...
随机推荐
- mysql忘记root密码的处理方法
在linux下,如果忘记了mysql中root用户的密码可以采用以下办法解决. 1. 修改my.cnf,加入skip-grant-tables 修改mysql的配置文件my.cnf,在[mysqld] ...
- 利用HADOOP中的jar写一个RPC
RPC调用需要服务端和客户端使用相同的协议: 协议: package cn.itcast.bigdata.hadooprpc.protocol; public interface IUserLogin ...
- [原创]Java使用反射及自定义注解实现对象差异性比较
Java项目C中 有一处逻辑,对于资源数据(类型为ResourceItem,拥有int/double/boolean/String类型数十个字段),需要比对资源数据每次变更的差异,并描述出变更情况.并 ...
- accept巨坑
在做node.js时, 我们要把一个资源发送回前端,需要用到以下一句: res.setHeader('Content-Type', mime ); mime,全称即Multipurpose Inter ...
- zookeeper java api(使用java代码操作zookeeper)
1 导入相关的pom依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId&g ...
- 微信小程序怎么获取用户输入
能够获取用户输入的组件,需要使用组件的属性bindchange将用户的输入内容同步到 AppService. <input id="myInput" bindchange=& ...
- Solidity payable 方法表现
pragma solidity ^; contract Person { string public name; uint age; uint private weight; string inter ...
- while 循环和do while循环
while循环是先检测条件符合不符合,符合才执行循环体内容,不符合就跳过while循环. 就和一个房间有两个门,一个前门,一个后门,while循环是当你进入前门的时候有人会检查你的身份,只有身份符合条 ...
- c语言实践:求两个数的最大公约数
我的思路是这样的:比如12和16这两个数.先理解一下概念,什么叫最大公约数.就是12有很多个因数,16也有很多个因数,这两堆因数中有一些重合的因数,在这些重合的因数中找到那个最大的.那么最大公约数一定 ...
- JAVA中mark()和reset()用法
根据JAVA官方文档的描述,mark(int readlimit)方法表示,标记当前位置,并保证在mark以后最多可以读取readlimit字节数据,mark标记仍有效.如果在mark后读取超过rea ...