Test automation using Testlink XMLRPC API - steps and sample python client program
Testlink is a very user friendly and powerful test case management tool. Alongwith manual test execution and tracking you can also use it alongwith your automated tests to report results via xmlrpc dynamically.
If you need more info on Testlink check out my article here - TestLink - Free, open source test case management tool
Here's a sample Testlink API client implementation using python. I found that most sample programs available on the net don't work. One of the main issues I noticed with the sample programs was that they are passing the input as a string whereas it is expecting a dictionary. This sample testlink api python client program works. This is only a guideline to get you started. Please refer to the API manual for a detailed list of Testlink API calls supported at:
http://www.teamst.org/_tldoc/1.8/phpdoc_api/TestlinkAPI/TestlinkXMLRPCSe...
You will find the actual xmlrpc.php inside the <testlink hom>/lib/api
Sample Testlink API client in python:
"""
Testlink API Sample Python Client implementation
"""
import xmlrpclib
class TestlinkAPIClient:
# substitute your server URL Here
SERVER_URL = "http://localhost/testlink/lib/api/xmlrpc.php"
def __init__(self, devKey):
self.server = xmlrpclib.Server(self.SERVER_URL)
self.devKey = devKey
print "devKey in init: %s" %devKey
def getTestCaseIDByName(self,devKey):
data = {"devKey":devKey, "testcasename":"Test Case 1", "testsuitename":"Test Suite 1"}
return self.server.tl.getTestCaseIDByName(data)
def reportTCResult(self, tcid, tpid, status):
data = {"devKey":self.devKey, "tcid":tcid, "tpid":tpid, "status":status}
return self.server.tl.reportTCResult(data)
def getInfo(self):
return self.server.tl.about()
def sayHello (self):
return self.server.tl.sayHello()
def getProjects (self, devKey):
print "DevKey: %s" %devKey
data = {"devKey":devKey}
return self.server.tl.getProjects(data)
if __name__ == '__main__':
devKey = "abc04556463cd813a1ea05caf042d42f"
# substitute your Dev Key Here
client = TestlinkAPIClient (devKey)
# get info about the server
print client.getInfo()
# retval = client.sayHello()
#retval = client.getProjects(devKey)
retval = client.getTestCaseIDByName(devKey)
print 'retval: ', retval
Please note, you will need to generate a devKey for this to work from within your Testlink installation.
Steps to enable Testlink API via xmlrpc and generate dev key:
- Open config.inc.php
- Search for
/** XML-RPC API availability (disabled by default) */
$tlCfg->api->enabled = FALSE; - Change FALSE to TRUE
$tlCfg->api->enabled = TRUE; - Save config.inc.php
- Login to Testlink UI as admin
- Go to 'My Settings'
- Under API interface, click 'Generate new key'
- Copy the key generated
- Substitute your newly generated devKey in the client program
Example: client = TestlinkAPIClient(devKey="abc04556463cd813a1ea05caf042d42f")
This should be sufficient for a test the Testlink xmlrpc API client server communication. You can then go ahead and use the client program as a library to be called from within your python test scripts (talking from a Selenium python user perspective). You could do similar implementation with other scripts.
Hope you find this useful.