forked from lczub/TestLink-API-Python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestLinkExample_CF_KW.py
More file actions
247 lines (210 loc) · 10.1 KB
/
Copy pathTestLinkExample_CF_KW.py
File metadata and controls
247 lines (210 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Copyright 2013-2014 Luiko Czub, TestLink-API-Python-client developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------
"""
Shows how to use the TestLinkAPI for custom fields
This example requires a special existing project with special custom fields
assigned
a) run example TestLinkExample.py
- this creates a project like NEW_PROJECT_API-7
if some additional project are created since running that example, adapt
variable projNr in this script your are reading currently
b) load custom field definitions customFields_ExampleDefs.xml
TL - Desktop - System - Define Custom Fields - Import
c) assign custom fields to project NEW_PROJECT_API-7
TL - Desktop - Test Project - Assign Custom Fields
d) load keyword definitions keywords_ExampleDefs.xml
TL - Desktop - Test Project - Keyword Management
Script works with:
TestProject NEW_PROJECT_API-7
- TestSuite B - First Level
- TestCase TESTCASE_B
- TestPlan TestPlan_API_GENERIC A (Platform Small Bird)
- Build TestlinkAPIGeneric v0.x.y
Script creates custom values for TestCase TESTCASE_B
- scope test specification and test execution
Script returns custom field values from TestPlan and TestSuite, if the user has
added manually some values.
Cause of missing knowledge, how ids of kind
- requirement and requirement specifications
- testplan - testcase link
could be requested via api, these example does not work currently.
Script returns keywords from test case TESTCASE_B, if the user has assigned
manually some values.
"""
from testlink import TestlinkAPIClient, TestLinkHelper
from testlink.testlinkerrors import TLResponseError
import sys, os.path
# precondition a)
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
#
# alternative precondition b)
# SERVEUR_URL and KEY are defined as command line arguments
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
# --devKey 7ec252ab966ce88fd92c25d08635672b
#
# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL
# has changed from
# (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php
# to
# (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
tl_helper = TestLinkHelper()
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI for CustomFields.
=> requires an existing project NEW_PROJECT_API-*''')
myTestLink = tl_helper.connect(TestlinkAPIClient)
#projNr=len(myTestLink.getProjects())+1
projNr=len(myTestLink.getProjects())
NEWPROJECT="NEW_PROJECT_API-%i" % projNr
NEWPREFIX="NPROAPI%i" % projNr
NEWTESTPLAN_A="TestPlan_API A"
# NEWTESTPLAN_B="TestPlan_API B"
# NEWPLATFORM_A='Big Bird %i' % projNr
NEWPLATFORM_B='Small Birds'
# NEWPLATFORM_C='Ugly Bird'
NEWTESTSUITE_A="A - First Level"
NEWTESTSUITE_B="B - First Level"
NEWTESTSUITE_AA="AA - Second Level"
# NEWTESTCASE_AA="TESTCASE_AA"
NEWTESTCASE_B="TESTCASE_B"
# myApiVersion='%s v%s' % (myTestLink.__class__.__name__ , myTestLink.__version__)
# NEWBUILD_A='%s' % myApiVersion
# NEWBUILD_B='%s' % myApiVersion
NEWATTACHMENT_PY= os.path.realpath(__file__)
this_file_dirname=os.path.dirname(NEWATTACHMENT_PY)
NEWATTACHMENT_PNG=os.path.join(this_file_dirname, 'PyGreat.png')
# Servers TestLink Version
myTLVersion = myTestLink.testLinkVersion()
# used connection settings
print myTestLink.connectionInfo()
print ""
# get information - TestProject
newProject = myTestLink.getTestProjectByName(NEWPROJECT)
print "getTestProjectByName", newProject
newProjectID = newProject['id']
print "Project '%s' - id: %s" % (NEWPROJECT,newProjectID)
# get information - TestPlan
newTestPlan = myTestLink.getTestPlanByName(NEWPROJECT, NEWTESTPLAN_A)
print "getTestPlanByName", newTestPlan
newTestPlanID_A = newTestPlan[0]['id']
print "Test Plan '%s' - id: %s" % (NEWTESTPLAN_A,newTestPlanID_A)
response = myTestLink.getTotalsForTestPlan(newTestPlanID_A)
print "getTotalsForTestPlan", response
response = myTestLink.getBuildsForTestPlan(newTestPlanID_A)
print "getBuildsForTestPlan", response
newBuildID_A = response[0]['id']
newBuildName_A = response[0]['name']
# get information - TestSuite
response = myTestLink.getTestSuitesForTestPlan(newTestPlanID_A)
print "getTestSuitesForTestPlan", response
newTestSuiteID_A=response[0]['id']
newTestSuiteID_AA=response[1]['id']
newTestSuiteID_B=response[2]['id']
newTestSuite = myTestLink.getTestSuiteByID(newTestSuiteID_B)
print "getTestSuiteByID", newTestSuite
# list test cases with assigned keywords
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, True,
'full', getkeywords=True)
print "getTestCasesForTestSuite (deep=True)", response
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, False,
'full', getkeywords=True)
print "getTestCasesForTestSuite (deep=False)", response
# get informationen - TestCase_B
response = myTestLink.getTestCaseIDByName(NEWTESTCASE_B, testprojectname=NEWPROJECT)
print "getTestCaseIDByName", response
newTestCaseID_B = response[0]['id']
print "Test Case '%s' - id: %s" % (NEWTESTCASE_B, newTestCaseID_B)
newTestCase_B = myTestLink.getTestCase(testcaseid=newTestCaseID_B)[0]
print "getTestCase", newTestCase_B
# return keyword list for TestCase_B
response = myTestLink.listKeywordsForTC(newTestCaseID_B)
print "listKeywordsForTC", response
# return keyword lists for all test cases of test newTestSuite_B
response = myTestLink.listKeywordsForTS(newTestSuiteID_B)
print "listKeywordsForTS", response
# new execution result with custom field data
# TC_B passed, explicit build and some notes , TC identified with internal id
newResult = myTestLink.reportTCResult(newTestCaseID_B, newTestPlanID_A,
newBuildName_A, 'p', "bugid 4711 is assigned",
platformname=NEWPLATFORM_B, bugid='4711',
customfields={'cf_tc_ex_string' : 'a custom exec value set via api',
'cf_tc_sd_listen' : 'ernie'})
print "reportTCResult", newResult
# get execution results
lastResult = myTestLink.getLastExecutionResult(newTestPlanID_A, newTestCaseID_B,
options={'getBugs' : True})[0]
print "getLastExecutionResult", lastResult
# map of used ids
args = {'devKey' : myTestLink.devKey,
'testprojectid' : newProjectID,
'testcaseexternalid' : newTestCase_B['full_tc_external_id'],
'version' : int(newTestCase_B['version']),
'tcversion_id' : lastResult['tcversion_id'],
'executionid' : lastResult['id'],
'linkid' : 779,
'testsuiteid': newTestSuiteID_B,
'testplanid': lastResult['testplan_id'],
'reqspecid': 7789,
'requirementid': 7791}
# get CustomField Value - TestCase Execution
response = myTestLink.getTestCaseCustomFieldExecutionValue(
'cf_tc_ex_string', args['testprojectid'], args['tcversion_id'],
args['executionid'] , args['testplanid'] )
print "getTestCaseCustomFieldExecutionValue", response
# update CustomField Value - TestCase SpecDesign
response = myTestLink.updateTestCaseCustomFieldDesignValue(
args['testcaseexternalid'], args['version'],
args['testprojectid'],
{'cf_tc_sd_string' : 'A custom SpecDesign value set via api',
'cf_tc_sd_list' : 'bibo'})
print "updateTestCaseCustomFieldDesignValue", response
# get CustomField Value - TestCase SpecDesign
#response = myTestLink._callServer('getTestCaseCustomFieldDesignValue', args)
response = myTestLink.getTestCaseCustomFieldDesignValue(
args['testcaseexternalid'], args['version'],
args['testprojectid'], 'cf_tc_sd_string', 'full')
print "getTestCaseCustomFieldDesignValue full", response
response = myTestLink.getTestCaseCustomFieldDesignValue(
args['testcaseexternalid'], args['version'],
args['testprojectid'], 'cf_tc_sd_string', 'value')
print "getTestCaseCustomFieldDesignValue value", response
response = myTestLink.getTestCaseCustomFieldDesignValue(
args['testcaseexternalid'], args['version'],
args['testprojectid'], 'cf_tc_sd_list', 'simple')
print "getTestCaseCustomFieldDesignValue simple", response
# get CustomField Value - TestCase Testplan Design
response = myTestLink.getTestCaseCustomFieldTestPlanDesignValue(
'cf_tc_pd_string', args['testprojectid'], args['tcversion_id'],
args['testplanid'], args['linkid'])
print "getTestCaseCustomFieldTestPlanDesignValue", response
# get CustomField Value - TestSuite
response = myTestLink.getTestSuiteCustomFieldDesignValue(
'cf_ts_string', args['testprojectid'], args['testsuiteid'])
print "getTestSuiteCustomFieldDesignValue", response
# get CustomField Value - TestPlan
response = myTestLink.getTestPlanCustomFieldDesignValue(
'cf_tp_string', args['testprojectid'], args['testplanid'])
print "getTestPlanCustomFieldDesignValue", response
# get CustomField Value - Requirement Specification
response = myTestLink.getReqSpecCustomFieldDesignValue(
'cf_req_sd_string', args['testprojectid'], args['reqspecid'])
print "getReqSpecCustomFieldDesignValue", response
# get CustomField Value - Requirement Specification
response = myTestLink.getRequirementCustomFieldDesignValue(
'cf_req_string',args['testprojectid'], args['requirementid'])
print "getRequirementCustomFieldDesignValue", response