首页 > 代码库 > Python之TestLink模块

Python之TestLink模块

1.安装:pip install TestLink-API-Python-client

2.Python连接上TestLink:

1 import testlink
2 
3 url = http://10.138.30.4:82/testlink/lib/api/xmlrpc/v1/xmlrpc.php
4 key = 14115ec841a5c22a5b095158d2eb7
5 
6 tlc = testlink.TestlinkAPIClient(url, key)

3.获取TestLink上的信息:

1 def get_information_test_project():
2     print("Number of Projects      in TestLink: %s " % tlc.countProjects())
3     print("Number of Platforms  (in TestPlans): %s " % tlc.countPlatforms())
4     print("Number of Builds                   : %s " % tlc.countBuilds())
5     print("Number of TestPlans                : %s " % tlc.countTestPlans())
6     print("Number of TestSuites               : %s " % tlc.countTestSuites())
7     print("Number of TestCases (in TestSuites): %s " % tlc.countTestCasesTS())
8     print("Number of TestCases (in TestPlans) : %s " % tlc.countTestCasesTP())
9     tlc.listProjects()

4.获取test suite:

1 def get_test_suite():
2     projects = tlc.getProjects()
3     top_suites = tlc.getFirstLevelTestSuitesForTestProject(projects[0]["id"])
4     for suite in top_suites:
5         print (suite["id"], suite["name"])

5.创建测试用例集:

1 def create_test_suite(project_id, test_suite_name, test_suite_describe, father_id):
2     if father_id == "":
3         tlc.createTestSuite(project_id, test_suite_name, test_suite_describe)
4     else:
5         tlc.createTestSuite(project_id, test_suite_name, test_suite_describe, parentid=father_id)

6.创建测试用例:

1 def create_test_case(father_id, data):
2     tlc.initStep(data[0][2], data[0][3], automation)
3     for i in range(1, len(data)):
4         tlc.appendStep(data[i][2], data[i][3], automation)
5     tlc.createTestCase(data[0][0], father_id, "1", "timen.xu", "", preconditions=data[0][1])

7.获取测试用例:

1 def get_test_case(test_case_id):
2     test_case = tlc.getTestCase(None, testcaseexternalid=test_case_id)
3     for i in test_case:
4         print ("序列", "执行步骤", "预期结果")
5         for m in i.get("steps"):
6             print (m.get("step_number"), m.get("actions"), m.get("expected_results"))

8.发送测试结果给TestLink:

1 def report_test_result(test_plan_id, test_case_id, test_result):
2     tlc.reportTCResult(None, test_plan_id, None, test_result, "", guess=True,
3                        testcaseexternalid=test_case_id, platformname="0")

备注:发送测试结果给TestLink,1.9.14版本暂时不支持每个步骤的结果反馈,下一个版本1.9.15可支持每个步骤结果反馈。

文章来源:http://blog.csdn.net/temanm/article/details/51505474

Python之TestLink模块