-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathTestLinkExample_CF_KW.py
314 lines (264 loc) · 13.3 KB
/
TestLinkExample_CF_KW.py
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Copyright 2013-2017 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-34
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-34
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-34
- 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 adds keywords KeyWord01 KeyWord02 KeyWord03 to test case TESTCASE_B,
removes keyword KeyWord02 again.
Script adds keywords KeyWord01 KeyWord02 to test case TESTCASE_AA,
removes keyword KeyWord01 again.
"""
from testlink import TestlinkAPIClient, TestLinkHelper
from testlink.testlinkerrors import TLResponseError
import sys, os.path
from platform import python_version
# 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)
myPyVersion = python_version()
myPyVersionShort = myPyVersion.replace('.', '')[:2]
NEWPROJECT="NEW_PROJECT_API-%s" % myPyVersionShort
NEWPREFIX="NPROAPI%s" % myPyVersionShort
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) )
response = myTestLink.getProjectKeywords(newProjectID)
print("getProjectKeywords", response)
# 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 )
# get informationen - TestCase_B
response = myTestLink.getTestCaseIDByName(NEWTESTCASE_B, testprojectname=NEWPROJECT)
print( "getTestCaseIDByName", response )
newTestCaseID_B = response[0]['id']
tc_b_full_ext_id = myTestLink.getTestCase(newTestCaseID_B)[0]['full_tc_external_id']
print( "Test Case '%s' - id: %s - ext-id %s" % (NEWTESTCASE_B, newTestCaseID_B, tc_b_full_ext_id) )
# get informationen - TestCase_AA
response = myTestLink.getTestCaseIDByName(NEWTESTCASE_AA, testprojectname=NEWPROJECT)
print( "getTestCaseIDByName", response )
newTestCaseID_AA = response[0]['id']
tc_aa_full_ext_id = myTestLink.getTestCase(newTestCaseID_AA)[0]['full_tc_external_id']
print( "Test Case '%s' - id: %s - ext-id %s" % (NEWTESTCASE_AA, newTestCaseID_AA, tc_aa_full_ext_id) )
# add keywords to TestCase B and TestCase AA
response = myTestLink.addTestCaseKeywords(
{tc_b_full_ext_id : ['KeyWord01', 'KeyWord03', 'KeyWord02'],
tc_aa_full_ext_id : ['KeyWord01', 'KeyWord02', 'KeyWord03']})
print( "addTestCaseKeywords", response )
# remove keywords from TestCase B and TestCase AA
response = myTestLink.removeTestCaseKeywords(
{tc_b_full_ext_id : ['KeyWord02'],
tc_aa_full_ext_id : ['KeyWord01', 'KeyWord03']})
print( "removeTestCaseKeywords", response )
# list test cases with assigned keywords B
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, True,
'full', getkeywords=True)
print( "getTestCasesForTestSuite B (deep=True)", response )
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, False,
'full', getkeywords=True)
print( "getTestCasesForTestSuite B (deep=False)", response )
# get informationen - TestCase_B again
newTestCase_B = myTestLink.getTestCase(testcaseid=newTestCaseID_B)[0]
print( "getTestCase B", newTestCase_B )
# return keyword list for TestCase_B
response = myTestLink.listKeywordsForTC(newTestCaseID_B)
print( "listKeywordsForTC B", response )
# return keyword lists for all test cases of test newTestSuite_B
response = myTestLink.listKeywordsForTS(newTestSuiteID_B)
print( "listKeywordsForTS B", response )
# list test cases with assigned keywords AA
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_A, True,
'full', getkeywords=True)
print( "getTestCasesForTestSuite A (deep=True)", response )
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_A, False,
'full', getkeywords=True)
print( "getTestCasesForTestSuite A (deep=False)", response )
# get informationen - TestCase_AA again
newTestCase_AA = myTestLink.getTestCase(testcaseid=newTestCaseID_AA)[0]
print( "getTestCase AA", newTestCase_AA )
# return keyword list for TestCase_AA
response = myTestLink.listKeywordsForTC(newTestCaseID_AA)
print( "listKeywordsForTC AA", response )
# return keyword lists for all test cases of test newTestSuite_A
response = myTestLink.listKeywordsForTS(newTestSuiteID_AA)
print( "listKeywordsForTS AA", response )
response = myTestLink.getTestCaseKeywords(testcaseid=newTestCaseID_B)
print("getTestCaseKeywords B", response)
response = myTestLink.getTestCaseKeywords(testcaseid=newTestCaseID_AA)
print("getTestCaseKeywords AA", 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_number' : lastResult['tcversion_number'],
'executionid' : lastResult['id'],
'linkid' : 779,
'testsuiteid': newTestSuiteID_B,
'testplanid': lastResult['testplan_id'],
'reqspecid': 7789,
'requirementid': 7791,
'buildid':newBuildID_A}
# get CustomField Value - TestCase Execution
response = myTestLink.getTestCaseCustomFieldExecutionValue(
'cf_tc_ex_string', args['testprojectid'], args['tcversion_number'],
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_number'],
args['testplanid'], args['linkid'])
print( "getTestCaseCustomFieldTestPlanDesignValue", response )
# update CustomField Value - TestSuite SpecDesign
response = myTestLink.updateTestSuiteCustomFieldDesignValue(
args['testprojectid'], args['testsuiteid'],
{'cf_ts_string' : 'A custom TestSuite value set via api'})
print( "updateTestSuiteCustomFieldDesignValue", 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 )
# update CustomField Value - Build
response = myTestLink.updateBuildCustomFieldsValues(
args['testprojectid'], args['testplanid'], args['buildid'],
{'cf_b_string' : 'A custom Build value set via api'})
print( "updateBuildCustomFieldsValues", response )