使用Python自动将Excel测试用例导入TestLink管理工具中,代码如下:
#coding=utf-8
import xlrd
from testlink import TestlinkAPIClient
#from __builtin__ import isinstance
TLURL = 'http://172.16.xx.xx/testlink/lib/api/xmlrpc/v1/xmlrpc.php'    #testlink url
DEVKey = '73e53369b9f4dc9a88a16e7620a5ce33'                            #admin user key
tlc = TestlinkAPIClient(TLURL, DEVKey)
tlc.createTestCase
animbus = tlc.getTestProjectByName('animbus_test')       #Test_Project
data = xlrd.open_workbook('C:\Users\Administrator\Desktop\rally.xlsx')   #testcase excel
table1 = data.sheet_by_index(0)
apiSuiteID = '938'      #Test_Suite ID
apiSubSuites = tlc.getTestSuitesForTestSuite('938')
#for ID, suite in apiSubSuites.items():
#    print ID, suite['name']
suites = {suite['name']:suite for (ID, suite) in apiSubSuites.items()}
suite_id=''
for i in range(0,table1.nrows):
row = table1.row_values(i)
if row[0] == '*':
if row[1] in suites.keys():
suite_id = suites[row[1]]['id']
print row[1], suite_id
else:
suite = tlc.createTestSuite('11', row[1], '', parentid='938')   # 11 for Test_Project id
suite_id = suite[0]['id']
print row[1], suite_id
else:
tlc.initStep(None, None, 1)  #两个None分别代表测试步骤、预期结果,这里我不写,故为None
newCase = tlc.createTestCase(row[1], suite_id, animbus['id'],
'admin', '')
print newCase[0]['id']
  注意:
  TestLink中的测试套件名字和Excel里的测试套件名字,必须一致,包括空格;当然,也不必事先在TestLink中创建好。
  下图,为我的Excel中的Rally的测试用例格式,若用此代码,则格式必须一致。