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 ...
随机推荐
- springboot成神之——springboot入门使用
springboot创建webservice访问mysql(使用maven) 安装 起步 spring常用命令 spring常见注释 springboot入门级使用 配置你的pom.xml文件 配置文 ...
- 图灵机器人,web录音实现自动化交互问答
一.图灵机器人 介绍 图灵机器人 是以语义技术为核心驱动力的人工智能公司,致力于“让机器理解世界”,产品服务包括机器人开放平台.机器人OS和场景方案. 官方地址为: http://www.tuling ...
- Halcon学习之边缘检测函数
sobel_amp ( Image : EdgeAmplitude : FilterType, Size : ) 根据图像的一次导数计算图像的边缘 close_edges ( Edges, EdgeI ...
- leetcode343
public class Solution { public int IntegerBreak(int n) { ) { ; } ) { ; } var max = int.MinValue; ; i ...
- asp.net js 存取cookie
asp.net //传进来的 public BaseController(BaseHttpHandler handler, HttpContext context) // { //根据地址设置cook ...
- Python基础学习七 Excel操作
python操作excel,python操作excel使用xlrd.xlwt和xlutils模块, xlrd模块是读取excel的,xlwt模块是写excel的,xlutils是用来修改excel的. ...
- 季逸超:90后IT少年的“盖茨梦”
2月15日,"90后"独立开发者季逸超在其微博称,个人获得徐小平和红杉资本投资,成立了Peak Labs--以贝尔和施乐为目标的实验室. 谁是季逸超?他现年20岁,曾单独一人做出猛 ...
- mac配置git mergetool为p4merge(2013笔记整理)
既有环境: 1)下载安装p4merge 2)安装git 下面是配置p4merge为git mergetool的步骤 1. /usr/local/bin下创建extMerge文件: $ cat > ...
- Nginx 下配置Laravel 错误404
宝塔的访问路径改一下 在站点的配置文件下面server里面加上 location / { try_files $uri $uri/ /index.php?$query_string; } 然后重启Ng ...
- 获取文件的后缀名。phpinfo
1: function get_extension($file){ //strrchr 返回 .jpg substr :1 是从1开始. substr(strrchr($file,'.'),1) } ...