摘要:
TestLink 是基于web的测试用例管理系统,主要功能是测试用例的创建、管理和执行,并且还提供了一些简单的统计功能。
主要内容:
testlink官网:http://www.testlink.org/
1.安装: pip install TestLink-API-Python-client
2.Python连接上testlink:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import testlink
manual = 1 # 手动
automation = 2 # 自动
# 连接test link
url = "http://139.196.201.225/lib/api/xmlrpc/v1/xmlrpc.php"
key = "08f4b9ea9dc24e91698fdf5ebfac0441" # 我这个key是错误的key
tlc = testlink.TestlinkAPIClient(url, key)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
3.获取testlink上的信息:
def get_information_test_project():
print("Number of Projects in TestLink: %s " % tlc.countProjects())
print("Number of Platforms (in TestPlans): %s " % tlc.countPlatforms())
print("Number of Builds : %s " % tlc.countBuilds())
print("Number of TestPlans : %s " % tlc.countTestPlans())
print("Number of TestSuites : %s " % tlc.countTestSuites())
print("Number of TestCases (in TestSuites): %s " % tlc.countTestCasesTS())
print("Number of TestCases (in TestPlans) : %s " % tlc.countTestCasesTP())
tlc.listProjects()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
4.获取 test suite
def get_test_suite():
projects = tlc.getProjects()
top_suites = tlc.getFirstLevelTestSuitesForTestProject(projects[0]["id"])
for suite in top_suites:
print suite["id"], suite["name"]
- 1
- 2
- 3
- 4
- 5
5.创建测试用例集
def create_test_suite(project_id, test_suite_name, test_suite_describe, father_id):
if father_id == "":
tlc.createTestSuite(project_id, test_suite_name, test_suite_describe)
else:
tlc.createTestSuite(project_id, test_suite_name, test_suite_describe, parentid=father_id)
- 1
- 2
- 3
- 4
- 5
6.创建测试用例
def create_test_case(father_id, data):
tlc.initStep(data[0][2], data[0][3], automation)
for i in range(1, len(data)):
tlc.appendStep(data[i][2], data[i][3], automation)
tlc.createTestCase(data[0][0], father_id, "1", "timen.xu", "", preconditions=data[0][1])
- 1
- 2
- 3
- 4
- 5
7.获取测试用例
def get_test_case(test_case_id):
test_case = tlc.getTestCase(None, testcaseexternalid=test_case_id)
for i in test_case:
print "序列", "执行步骤", "预期结果"
for m in i.get("steps"):
print m.get("step_number"), m.get("actions"), m.get("expected_results")
- 1
- 2
- 3
- 4
- 5
- 6
8.发送测试结果给testlink
def report_test_result(test_plan_id, test_case_id, test_result):
tlc.reportTCResult(None, test_plan_id, None, test_result, "", guess=True,
testcaseexternalid=test_case_id, platformname="0")
- 1
- 2
- 3
备注:发送测试结果给testlink,1.9.14 版本暂时不支持每个步骤的结果反馈,下一个版本1.9.15可支持每个步骤结果反馈。
总结:
Keep Learning
参考文献:
TestLinkExample.py
本人利用Bootstrap + EasyUI + Django开发网站:http://www.xuyangting.com/ 欢迎来访
欢迎加QQ群 -> 阳台测试 -> 239547991(群号)