【Python】实现将testlink上的用例指定格式保存至Excel,用于修改上传
背景
前一篇博客记录的可以上传用例到testlink指定用例集的脚本,内部分享给了之后,同事希望能将testlink上原有的用例下载下来,用于下次修改上传,所有有了本文脚本。
具体实现
获取用例信息
def download_testcase():
"""
获取(下载)testlink上面指定用例集的数据
:return:
"""
datas = []
for data in tlc.getTestCasesForTestSuite(father_id, True, 'full'):
actions = []
expected_results = []
name = data["name"]
summary = data["summary"]
preconditions = data["preconditions"]
importance = data["importance"]
execution_type = data["execution_type"]
author = data["author_id"]
# print(json.dumps(data, indent=4))
for i in range(len(data["steps"])):
actions.append(data["steps"][i]["actions"])
expected_results.append(data["steps"][i]["expected_results"])
datas.append((name, preconditions, '\n'.join(actions), '\n'.join(expected_results), format_execution_type(execution_type), format_auth(author), format_importance(importance), summary))
进行数据转换
def format_execution_type(source_data):
"""
转换执行方式
:param source_data:
:return:
"""
switcher = {
'2': "自动化",
'1': "手工"
}
return switcher.get(source_data, "Param not defind")
def format_importance(source_data):
"""
转换优先级
:param source_data:
:return:
"""
switcher = {
'1': "低",
'2': "中",
'3': "高"
}
return switcher.get(source_data, "Param not defind")
def format_auth(source_data):
"""
转换作者:可以通过testlink的user表查询到对应id->name对
:param source_data:
:return:
"""
switcher = {
'100': "tester_name",
}
return switcher.get(source_data, "Param not defind")
保存至Excel
def save_suits(file_path, datas):
"""
保存用例
:param file_path: 保存路径
:param datas:
:return:
"""
book = xlrd.open_workbook(file_path, formatting_info=True) # 读取Excel
new_book = copy.copy(book) # 复制读取的Excel
sheet = new_book.get_sheet(0) # 取第一个sheet页
line_num = 1
for i in range(0, len(datas)):
name, preconditions, actions, expected_results, execution_type, author, importance, summary = datas[i]
sheet.write(line_num, 0, u'%s' % name)
sheet.write(line_num, 1, u'%s' % preconditions)
sheet.write(line_num, 2, u'%s' % actions)
sheet.write(line_num, 3, u'%s' % expected_results)
sheet.write(line_num, 4, u'%s' % execution_type)
sheet.write(line_num, 5, u'%s' % author)
sheet.write(line_num, 6, u'%s' % importance)
sheet.write(line_num, 7, u'%s' % summary)
line_num += 1
report_path = os.path.abspath(os.path.join('download'))
if not os.path.exists(report_path):
os.makedirs(report_path)
suits_name = get_suites(father_id)["name"]
new_book.save(os.path.abspath(os.path.join(report_path, '用例集_{}@{}.xlsx'.format(suits_name, time.strftime('%Y.%m.%d@%H%M%S')))))
def get_suites(suite_id):
"""
获取用例集信息
:return:
"""
try:
suites = tlc.getTestSuiteByID(suite_id)
return suites
except testlink.testlinkerrors.TLResponseError as e:
# traceback.print_exc()
logger.warning(str(e).split('\n')[1])
logger.warning(str(e).split('\n')[0])
return
使用方法
环境依赖
| 环境依赖 | 安装方法 |
|---|---|
| Python3 | 略 |
| xlrd库 | pip install xlrd |
| testlink库 | pip install TestLink-API-Python-client |
| xlutils | pip install xlutils |
具体方法
- 将上述的代码保存到一个文件中,底部添加下列代码进行调用
if __name__ == "__main__":
url = "http://localhost/lib/api/xmlrpc/v1/xmlrpc.php"
key = "6c3fe0796142db21" # 这个key是错误的key
tlc = testlink.TestlinkAPIClient(url, key)
father_id = "274539" # 想要下载的用例集的ID,可通过在testlink界面选取用例集,然后点击右键获取
download_testcase()
- 目录结构参考,与上一篇文章的脚本放在了一起
D:\Project\UPLOAD_DATA2TESTLINK
│ download_testcase.py
│ logger_better.py
│ upload_excel_data.py
│
└─testCase
down_load_template.xls
- 在上一步的文件同一目录下创建一个testCase文件夹,创建一个xls文件,文件格式如下:

【Python】实现将testlink上的用例指定格式保存至Excel,用于修改上传的更多相关文章
- python完成加密参数sign计算并输出指定格式的字符串
加密规则: 1.固定加密字符串+字符串组合(key/value的形式,并通过aissc码排序), 2.通过sha1算法对排序后的字符串进行加密, 3.最终输出需要的参数sign 4.完成请求参数数据的 ...
- Python Socket 编程——聊天室演示样例程序
上一篇 我们学习了简单的 Python TCP Socket 编程,通过分别写服务端和client的代码了解主要的 Python Socket 编程模型.本文再通过一个样例来加强一下对 Socket ...
- python小练习1:设计这样一个函数,在桌面的文件夹上创建10个文本,以数字给它们命名。
python小练习1:设计这样一个函数,在桌面的文件夹上创建10个文本,以数字给它们命名. 使用for循环即可实现: for name in range(1,11): desktop_path='C: ...
- Python 进行 SSH 操作,实现本地与服务器的链接,进行文件的上传和下载
Python 进行 SSH 操作,实现本地与服务器的链接,进行文件的上传和下载 2018年5月26日 19:03 阅读 375 评论 7 我本地和服务器的连接一直使用的是 Xshell 5,而在与服务 ...
- python+pytest接口自动化(12)-自动化用例编写思路 (使用pytest编写一个测试脚本)
经过之前的学习铺垫,我们尝试着利用pytest框架编写一条接口自动化测试用例,来厘清接口自动化用例编写的思路. 我们在百度搜索天气查询,会出现如下图所示结果: 接下来,我们以该天气查询接口为例,编写接 ...
- python oop培训文档里面的 正宗oop、多个函数间反复return传参、多个文件无限复制粘贴扣字、无效废物滑稽类4种方式的例子。(2)
把文档里面说的几种范式发出来. 4种编程范式实现一个人吃喝拉撒长身体的代码.语法很简单,思想模拟了所有程序员写代码时候的代码规划设计想法. 0.我不反对复制粘贴的写法,可以百度搜索复制粘贴网上现有的, ...
- [教程]K8Cscan调用外部程序(Win/Linux批量上控/执行多条命令/保存结果)
0x000 调用原理 Cscan调用外部程序有两种方式,一是编写DLL,二是配置文件 编写DLL文件对于不懂编程的人来说可能会很难(虽然支持各语言) 由于考虑到很多人不会编程或会编程又急用无法短时间转 ...
- 《在纹线方向上进行平滑滤波,在纹线的垂直方向上进行锐化滤波》 --Gabor增强的具体实践
<在纹线方向上进行平滑滤波,在纹线的垂直方向上进行锐化滤波> --Gabor增强的具体实践 一.问 ...
- [PHP学习教程 - 文件]002.修改上传文件大小限制(File Upload Limit)
引言:通常大家直装xampp之后,默认的文件上传大小应该被设定成2M左右,这个时候如果上传超过2M的东西,就会报错,让人非常尴尬.如何修改呢? 导航索引: 概念 FTP常用API FTP封装类 其他 ...
随机推荐
- [MongoDB] 安装MongoDB配置Replica Set
MongoDB的环境主要包括StandAlone,Replication和Sharding. StandAlone:单机环境,一般开发测试的时候用. Replication:主从结构,一个Primar ...
- Spring 加载配置文件的方式
我们常用的加载context文件的方法有如下三个: 1.FileSystemXmlApplicationContext 这个方法是从文件绝对路径加载配置文件,例如: ApplicationContex ...
- 免费访问:谷歌搜索,Gmail邮箱,Chrome商店
分享个免费的google的服务的方法 1,插件下载: http://note.youdao.com/noteshare?id=6a3e52f8d4ccf63c751eeddd625a118d 2,使用 ...
- couldn't connect to host
“couldn't connect to host” 这样的错误可能是主机不可到达,或者端口不可到达. ping OK只代表主机可以到达. 端口不可到达可能是由于HTTP 服务器未启动或者监听在其他端 ...
- Python开发【项目】:RPC异步执行命令(RabbitMQ双向通信)
RPC异步执行命令 需求: 利用RibbitMQ进行数据交互 可以对多台服务器进行操作 执行命令后不等待命令的执行结果,而是直接让输入下一条命令,结果出来后自动打印 实现异步操作 不懂rpc的请移步h ...
- 前端 html span标签
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- nodejs通过代理(proxy)发送http请求(request)
有可能有这样的需求,需要node作为web服务器通过另外一台http/https代理服务器发http或者https请求,废话不多说直接上代码大家都懂的: var http = require('htt ...
- Java Thread 如何处理未捕获的异常?
Java Thread是不允许异常抛出到本线程之外的,Runnable接口的public abstract void run()是不允许throws Exception的,这在编译时就通不过. 线程异 ...
- 一、Mosquitto 介绍&安装
一.Mosquitto 介绍 一款实现了消息推送协议 MQTT v3.1 的开源消息代理软件,提供轻量级的,支持可发布/可订阅的的消息推送模式,使设备对设备之间的短消息通信变得简单,比如现在应用广泛的 ...
- PAT 1137 Final Grading[一般][排序]
1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...