Example TestLink XMLRPC Clients in Perl

There are not many good examples floating around of Perl clients for TestLink’s XMLRPC API. There are two examples included with the 1.9.3 source, but they are very brief. I wrote two scripts to support a first-blush attempt at automated test running, and while they will get a lot more refinement over time, I thought abstracted versions of them might be beneficial for others trying to write Perl clients (or in any language – they perl samples were so sparse I largely based my script on the python example).

Test Runner

The first script is an example test runner, run-testplan-simple.pl, which can be found at https://github.com/jetmore/TestLink-Misc/blob/master/scripts/run-testplan-simple.pl or inline and collapsed at the end of this post. In terms of a full-featured test runner this is still pretty sparse, but it has some string points as an example:

  • A demonstration of several more API methods than the standard perl example script
  • An attempt at a reusable error checking function for api responses
  • A method for storing external test information in test cases
  • Example of posting results back to TestLink via tl.reportTCResult

Based on the amount of Google hits I’ve seen on other TestLink posts I’ve made, it looks like the usage information for tl.reportTCResult will be useful for people.

In my opinion the most useful thing in this script is the generalized error checking. The TestLink API is a mess in terms of standardized responses. There’s no “this is an error response” flag, so you have to determine errors heuristically, which is less than ideal. The isResponseError() function is my attempt to identify as many failure conditions as possible in one function.

The variables $testServer, $APIKey, and $projectName at the top of the script need to be uncommented and populated with the appropriate values. An API Key for your TestLink install can be generated from your user page in the TestLink UI.

Test Reporter

The second script is a reporter. Because we are in very early stages of implementing automated testing, we have many tests that are blocking (we wrote tests for functionality that isn’t implemented yet, and I chose to register that as a blocked test case in TestLink). So, at the moment, individual test case status is not very interesting to me. What is interesting is changes in status. If a test passed two nights ago, but blocked last night, I want to know about it.

I wrote get-testplan-status.pl (https://github.com/jetmore/TestLink-Misc/blob/master/scripts/get-testplan-status.pl) to do this reporting for me. This script is largely similar to run-testplan-simple.pl above, but it is a read-only script, which might make it more interesting for initial exploring.

This script also makes use of the non-standard API call getExecutionResults(). I wrote this new interface to allow more than one result to be returned for a test case. See https://www.jetmore.org/john/blog/2012/03/missing-testlink-api-function-getexecutionresults/ for more details on the function, including the code itself.

As with run-testplan-simple.pl, the variables $testServer, $APIKey, and $projectName at the top of the script need to be uncommented and populated with the appropriate values.

Code

The code for these two scripts at the time I wrote this post is included inline below, hopefully minimized…

run-testplan-simple.pl

get-testplan-status.pl

Leave a Reply

Your email address will not be published. Required fields are marked *