Closed nitrocode closed 8 years ago
Hello NitroCode, here is an example, how you could change custom fields with scope specification for all test cases of one specific project
from testlink import TestlinkAPIClient, TestLinkHelper
from testlink.testlinkerrors import TLResponseError
import sys, os.path
# precondition
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
tl_helper = TestLinkHelper()
myTestLink = TestlinkAPIClient(tl_helper._server_url, tl_helper._devkey,
verbose=False)
def iterTCasesfromTProject(api, TPid):
""" returns as iterator all test cases for project TPid """
deep=1
details='only_id'
for TSinfo in api.getFirstLevelTestSuitesForTestProject(TPid):
print(" Iter suite", TSinfo['name'], "with ID", TSinfo['id'])
for TCid in api.getTestCasesForTestSuite(TSinfo['id'], deep, details):
TCdata = api.getTestCase(TCid)[0] #really only one TC?
print(" TC %(full_tc_external_id)s Version %(version)s %(creation_ts)s - %(name)s " % TCdata)
yield TCdata
# loop over all test cases for project - 'NEW_PROJECT_API-34'
# changes the custom field 'cf_tc_sd_string' of these cases to 'newValue'
# !! works only for custom field with scope 'Specification' !!
TProjectName = 'NEW_PROJECT_API-34'
CFname='cf_tc_sd_string'
CFvalue='newValue8'
TPinfo = myTestLink.getTestProjectByName(TProjectName)
TPid = TPinfo['id']
print("For all test cases of project", TPinfo['name'], "with ID", TPid)
print("there custom field", CFname, "will be updated to", CFvalue)
for TCdata in iterTCasesfromTProject(myTestLink, TPid):
TCexID = TCdata['full_tc_external_id']
TCversion = int(TCdata['version'])
oldCFvalue = myTestLink.getTestCaseCustomFieldDesignValue(
TCexID, TCversion, TPid, CFname, 'value')
myTestLink.updateTestCaseCustomFieldDesignValue(
TCexID, TCversion, TPid, {CFname : CFvalue})
newCFvalue= myTestLink.getTestCaseCustomFieldDesignValue(
TCexID, TCversion, TPid, CFname, 'value')
print(" CF value changed", oldCFvalue, "->", newCFvalue)
For other examples, please see TestLinkExample.py and TestLinkExample_CF_KW.py
Regards Luiko
Hello NitroCode, there is mismatch in your requirements: Your header line focus on "test plans", your description on "test projects". Do you have to iter over all test cases of a test plan or of a test project? Regards Luiko
Thanks iczub. I fixed the title of the issue. And I was hoping there would be an easier function to do this but I guess no matter what, this procedure will require recursive iteration.
Thank you for the python code!
Hi! We have a 30k test cases and we're trying to "uncheck" one of our custom fields for our test cases for a specific project. In order to do this using the database, we have to traverse the database in order to find the software project and then add each test case that is in the correct software project to an array, and then we can iterate through that array to "uncheck" this custom field.
Is there a way to modify a specific test case's custom field using the API?
Thanks