直接贴上代码...转载请注明出处哦。网上各种找,也没有找到完善的代码。有误之处请包含。分享给需要的小伙伴(创建case网上很多帖子。)如有不明请留言
class TLinkHandle(object):
def __init__(self):
baseurl =localReadConfig.get_testlink('baseurl')
key = localReadConfig.get_testlink('key')
self.projectname = localReadConfig.get_testlink('projectname')
self.tlc=testlink.TestlinkAPIClient(baseurl,key)
def getProjectId(self, projectName):
if projectName == "":
raise ValueError
else:
id = self.tlc.getProjectIDByName(projectName)
if id == -1:
return False
else:
return id
def getAllProjects(self):
total_projects = self.tlc.countProjects()
projects = self.tlc.getProjects()
return total_projects, projects
#获取项目name获取项目id
def getProjectIDByName(self,projectname):
return self.tlc.getProjectIDByName(projectname)
#获取项目测试计划
def getProjectTestPlans(self,projectId):
return self.tlc.getProjectTestPlans(projectId)
#根据测试计划id获取Suite列表
def getTestSuitesForTestPlan(self,planId):
return self.tlc.getTestSuitesForTestPlan(planId)
#根据suite 的id获取测试用例列表
def getTestCasesForTestSuite(self,suitId):
return self.tlc.getTestCasesForTestSuite(suitId,True,'')
def getTestSteps(self,test_case_external_id):
return self.tlc.getTestCase(None, testcaseexternalid=test_case_external_id)
if __name__ == '__main__':
testlink = TLinkHandle()
# testlink上所有项目的名称
print(testlink.getAllProjects())
# 指定项目id
pid = testlink.getProjectIDByName(testlink.projectname)
print('pid',pid)
#获取该项目下测试计划
planid = testlink.getProjectTestPlans(pid)
print('planid',planid)
# 获取指定项目的测试计划suite套件,planid[0] 测试取的一个对象。正式需要循环
suites = testlink.getTestSuitesForTestPlan(planid[0]['id'])
print('suites:',suites)
#获取某个测试套件下的用例列表
cases = testlink.getTestCasesForTestSuite(suites[0]['id'])
print('cases:',cases[0])
#获取某个测试用例的测试步骤
print('step:',testlink.getTestSteps(cases[0]['external_id']) )
有不明白的,加群QQ 833077481交流