TestLink::API - Provides an interface to TestLink's XMLRPC api via HTTP
version 0.011
use TestLink::API; my $tl = TestLink::API->new('http://tl.test/testlink/lib/api/xmlrpc/v1/xmlrpc.php', 'gobbledygook123'); #Look up test definitions my $projects = $tl->getProjects(); my $suites = $tl->getTLDTestSuitesForProject($projects->[0]->{'id'}); my $childsuites = $tl->getTestSuitesForTestSuite($suites->[0]->{'id'}); my $tests = $tl->getTestCasesForTestSuite($childsuites->[0]->{'id'}); #Look up test plans/builds my $plans = $tl->getTestPlansForProject($projects->[0]->{'id'}); my $tests2 = $tl->getTestCasesForTestPlan($plans->[0]->{'id'}); my $builds = $tl->getBuildsForTestPlan($plans->[0]->{'id'}); #Set results my $testResults = doSomethingReturningBoolean(); my $results = $tl->reportTCResult($tests2->[0]->{'id'},$plans->[0]->{'id'},$builds->[0]->{'id'}, $testResults ? 'p' : 'f'); $tl->uploadExecutionAttachment($results->{'id'},'test.txt','text/plain',encode_base64('MOO MOO MOOOOOO'),'bovine emissions','whee')
TestLink::API provides methods to access an existing TestLink account. You can then do things like look up tests, set statuses and create builds from lists of tests. The getter methods cache the test tree up to whatever depth is required by your getter calls. This is to speed up automated creation/reading/setting of the test db based on existing automated tests. Cache expires at the end of script execution. (TODO use memcached controlled by constructor, with create methods invalidating cache?) Getter/setter methods that take args assume that the relevant project/testsuite/test/plan/build provided exists (TODO: use cache to check exists, provide more verbose error reason...), and returns false if not. Create methods assume desired entry provided is not already in the DB (TODO (again): use cache to check exists, provide more verbose error reason...), and returns false if not. It is by no means exhaustively implementing every TestLink API function. Designed with TestLink 1.9.9, but will likely work on (some) other versions.
TestLink::API
Creates new TestLink::API object.
API URL
KEY
Returns TestLink::API object if login is successful.
my $tl = TestLink::API->new('http://tl.test/testlink/lib/api/xmlrpc/v1/xmlrpc.php', 'gobbledygook123');
apiurl and apikey can be accessed/set:
$url = $tl->apiurl; $tl = $tl->apiurl('http//some.new.url/foo.php');
Creates new Test plan with given name in the given project.
NAME
PROJECT
NOTES
ACTIVE
PUBLIC
Returns (integer) test plan ID if creation is successful.
my $tpid = $tl->createTestPlan('shock&awe', 'enduringfreedom');
Creates new 'Build' (test run in common parlance) from given test plan having given name and notes.
TEST PLAN ID
Returns true if case addition is successful, false otherwise.
$tl->createBuild(1234, "Bossin' up", 'Crushing our enemies, seeing them driven before us and hearing the lamentations of their support engineers.');
Creates new TestSuite (folder of tests) in the database of test specifications under given project id having given name and details. Optionally, can have a parent test suite (this is an analog to a hierarchical file tree after all) and what order to have this suite be amongst it's peers.
PROJECT ID
DETAILS
PARENT TESTSUITE ID
ORDER
Returns (integer) build ID on success, false otherwise.
$tl->createTestSuite(1, 'broken tests', 'Tests that should be reviewed', 2345, -1);
Creates new Project (Database of testsuites/tests) with given name and case prefix. Optionally, can have notes, options, set the project as active/inactive and public/private.
CASE PREFIX
OPTIONS
Returns (integer) project ID on success, false otherwise.
$tl->createTestProject('Widgetronic 4000', 'Tests for the whiz-bang new product', {'inventoryEnabled=>true}, true, true);
Creates new test case with given test suite id and project id. Author, Summary and Steps are mandatory for reasons that should be obvious to any experienced QA professional. Execution type and Test order is optional.
TEST SUITE ID
TEST PROJECT ID
AUTHOR
SUMMARY
STEPS
PRECONDITIONS
EXECUTION
Returns (HASHREF) with Test Case ID and Test Case External ID on success, false otherwise.
$tl->createTestCase('Verify Whatsit Throbs at correct frequency', 123, 456, 'Gnaeus Pompieus Maximus', 'Make sure throbber on Whatsit doesn't work out of harmony with other throbbers', '1. Connect measurement harness. 2. ??? 3. PROFIT!', 'automated', 2);
Report results of a test case with a given ID, plan and build ID. Set case results to status given. Platform is mandatory if available, otherwise optional. Notes and Bug Ids for whatever tracker you use are optional.
CASE ID
BUILD ID
STATUS
PLATFORM
BUG ID
Returns project ID on success, false otherwise.
$tl->reportTCResult('T-1000', 7779311, 8675309, 'Tool Failure', 'Skynet Infiltration Model 1000', 'Catastrophic systems failure due to falling into vat of molten metal' 'TERMINATOR-2');
TEST CASE ID
TEST VERSION
SUT PLATFORM
EXECUTION ORDER
URGENCY
Returns true if case addition is successful.
$tl->addTestCaseToTestPlan(666, 'cp-90210', 121, '3.11', 'OS2/WARP', 3, 1);
Uploads the provided file and associates it with the given execution.
EXECUTION ID
FILENAME
MIMETYPE
CONTENT
TITLE
DESCRIPTION
Returns true if attachment addition is successful.
$tl->uploadExecutionAttachment(1234, 'moo.txt', 'text/cow', APR::Base64::encode('MOO MOO MOOOOOO'), 'MOO', 'Test observed deranged bleatings of domestic ungulates, please investigate.');
$tl->uploadTestCaseAttachment(1234, 'doStuff.t', 'text/perl', APR::Base64::encode($slurped_file_content), 'doStuff.t', 'Test File.');
Get all available projects
Returns array of project definition hashes, false otherwise.
$projects = $tl->getProjects;
Gets some project definition hash by it's name
Returns desired project def hash, false otherwise.
$projects = $tl->getProjectByName('FunProject');
Gets some project definition hash by it's ID
$projects = $tl->getProjectByID(222);
Gets the testsuites in the top level of a project
GET TESTS
Returns desired testsuites' definition hashes, 0 on error and -1 when there is no such project.
$projects = $tl->getTLDTestSuitesForProject(123);
Gets the testsuites that are children of the provided testsuite.
TESTSUITE ID
Returns desired testsuites' definition hashes, false otherwise.
$suites = $tl->getTestSuitesForTestSuite(123); $suitesWithCases = $tl->getTestSuitesForTestSuite(123,1);
Gets the testsuite(s) that match given name inside of given project name. WARNING: this will slurp the entire testsuite tree. This can take a while on large projects, but the results are cached so that subsequent calls are not as onerous.
TESTSUITE NAME
DO REGEX
$suites = $tl->getTestSuitesByName(321, 'hugSuite'); $suitesr = $tl->getTestSuitesByName(123, qr/^hug/, 1);
Gets the testsuite with the given ID.
TESTSUITE_ID
Returns desired testsuite definition hash, false otherwise.
$tests = $tl->getTestSuiteByID(123);
Gets the testsuites that match given name inside of given project name.
RECURSE
RETURNMODE
Returns desired case definition hashes, false otherwise.
$tests = $tl->getTestCasesForTestSuite(123,1,1);
Gets the test case with the given external ID (e.g. projprefix-123) at provided version.
VERSION
Returns desired case definition hash, false otherwise.
$case = $tl->getTestCaseByExternalId('eee-123');
Gets the test case with the given internal ID at provided version.
$case = $tl->getTestCaseById(28474,5);
CASE NAME
SUITE NAME
PROJECT NAME
TC_PATH_NAME
$case = $tl->getTestCaseByName('nugCase','gravySuite','chickenProject');
Gets the attachments for some case.
Returns desired attachment definition hash, false otherwise. Content key is the file base64 encoded.
$att = $tl->getTestCaseAttachments('CP-222');
Gets the test plans within given project id
Returns desired test plan definition hashes, false otherwise.
$plans = $tl->getTestPlansForProject(23);
Gets the test plan within given project name
PLAN NAME
Returns desired test plan definition hash, false otherwise.
$suites = $tl->getTestPlanByName('nugs','gravy');
Gets the builds for given test plan
PLAN ID
Returns desired builds' definition hashes, false otherwise.
$builds = $tl->getBuildsForTestPlan(1234);
Gets the cases in provided test plan
Returns desired tests' definition hashes sorted by parent test plan ID, false otherwise.
Example output: { 1234 => [{case1},{case2},...], 33212 => [cases...]} Example usage: $builds = $tl->getTestCasesForTestPlan(1234);
Gets the latest build for the provided test plan
Returns desired build definition hash, false otherwise.
$build = $tl->getLatestBuildForTestPlan(1234);
Gets the desired build in project id by name
BUILD NAME
$build = $tl->getBuildByName('foo',1234);
Gets the results summary for a test plan, even though what you really want is results by build/platform
Returns Hash describing test results.
$res = $tl->getTotalsForTestPlan(2322);
Return all info for all (or only the specified) projects. It will have the entire testsuite hierarchy and it's tests/attachments in an array of HASHREFs. The idea would be that you then could encode as JSON/XML as a backup, or to facilitate migration to other systems.
The project hashes will be what you would expect from getProjectByName calls. Those will have a key 'testsuites' with a list of it's child testsuites. These testsuites will themselves have 'testsuites' and 'test' keys describing their children. Both the test and testsuite hashes will have an 'attachment' parameter with the base64 encoded attachment as a string if the get_attachments option is passed.
WARNING: I have observed some locking related issues with cases/suites etc. Sometimes calls to get tests/suites during dumps fails, sometimes subsequent calls to getTestSuites/getTestCasesForTestSuite fail. If you are experiencing issues, try to put some wait() in there until it starts behaving right. Alternatively, just XML dump the whole project and use XML::Simple or your tool of choice to get the project tree.
ALSO: Attachment getting is not enabled due to the underlying XMLRPC calls appearing not to work. This option will be ignored until a workaround can be found.
GET ATTACHMENTS
FLATTEN
Returns ARRAYREF describing everything.
$ultradump = $tl->dump(); $dumpWithAtts = $tl->dump('TestProject',1); $flatDump = $tl->dump('testProj',0,1);
XMLRPC::Lite
cPanel, Inc. graciously funded the initial work on this project.
George S. Baugh <teodesian@cpan.org>
Neil Bowers <neil@bowers.com>
The development version is on github at http://github.com/teodesian/TestLink-Perl and may be cloned from git://github.com/teodesian/TestLink-Perl.git
This software is copyright (c) 2014 by George S. Baugh.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install TestLink::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TestLink::API
CPAN shell
perl -MCPAN -e shell install TestLink::API
For more information on module installation, please visit the detailed CPAN module installation guide.