依赖库:TestLink-API-Python-client,xlrd
通过pip安装: python3 -m pip install TestLink-API-Python-client (笔者本地有多个版本python,只有一个版本直接python就可以)
url: 替换自己的testLink地址 http://xx.xx.xx.xx:xxxx/testlink/lib/api/xmlrpc/v1/xmlrpc.php
key: 登录testLink后点击上方个人账号进入个人中心,新页面点击 '生成新的秘钥’获取
一、确定excel模板
1.查看TestLink-API-Python-client提供的创建用例方法
def createTestCase(self, *argsPositional, **argsOptional):
""" createTestCase: Create a test case
positional args: testcasename, testsuiteid, testprojectid, authorlogin,
summary
optional args : steps, preconditions, importance, executiontype, order,
internalid, checkduplicatedname, actiononduplicatedname,
status, estimatedexecduration
argument 'steps' will be set with values from .stepsList,
- when argsOptional does not include a 'steps' item
- .stepsList can be filled before call via .initStep() and .appendStep()
otherwise, optional arg 'steps' must be defined as a list with
dictionaries , example
[{'step_number' : 1, 'actions' : "action A" ,
'expected_results' : "result A", 'execution_type' : 0},
{'step_number' : 2, 'actions' : "action B" ,
'expected_results' : "result B", 'execution_type' : 1},
{'step_number' : 3, 'actions' : "action C" ,
'expected_results' : "result C", 'execution_type' : 0}]
"""
# store current stepsList as argument 'steps', when argsOptional defines
# no own 'steps' item
if self.stepsList:
if 'steps' in argsOptional:
raise TLArgError('confusing createTestCase arguments - ' +
'.stepsList and method args define steps')
argsOptional['steps'] = self.stepsList
self.stepsList = []
return super(TestlinkAPIClient, self).createTestCase(*argsPositional,
**argsOptional)
分析该方法:
①positional args:testcasename, testsuiteid, testprojectid, authorlogin,summary这些参数必填
其中testprojectid可以根据项目名去获取,testsuiteid也可以获取稍后讲获取方法(其中一种我自己写了一个递归函数来获取一个项目下所有的目录),所以我是将几个必要的参数写在了excel(testcasename,authorlogin,summary)
②optional args中都是可选参数,可以根据自己的项目组习惯或规范来使用
2.excel模板示例
二、读取excel
我是根据列名来获取用例对应的参数,所以列名必须严格按照模板来,列的位置可以随意调整
excel的sheet是默认读取了第一页即index[0]
def read_excel(file_path):
"""
读取用例数据
:return:
"""
case_list = []
case_list_dic = []
try:
book = xlrd.open_workbook(file_path) # 打开excel
except Exception as error:
logger.error('路径不在或者excel不正确 : ' + str(error))
return error
else:
sheet = book