Skip to content

Latest commit

 

History

History
163 lines (122 loc) · 6.61 KB

usage.rst

File metadata and controls

163 lines (122 loc) · 6.61 KB

TestLink-API-Python-client Usage

How to talk with TestLink in a python shell

Connect TestLink, count existing projects and get test case data:

[PYENV]\testlink\Scripts\activate
set TESTLINK_API_PYTHON_SERVER_URL=http://[YOURSERVER]/testlink/lib/api/xmlrpc/v1/xmlrpc.php
set TESTLINK_API_PYTHON_DEVKEY=[Users devKey generated by TestLink]
python
>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> tls.countProjects()
3
>>> tls.getTestCase(None, testcaseexternalid='NPROAPI3-1')
[{'full_tc_external_id': 'NPROAPI3-1', 'node_order': '0', 'is_open': '1', 'id': '2757', ...}]

Ask the TestLink API Client, what arguments a API method expects:

import testlink
tlh = testlink.TestLinkHelper()
tls = tlh.connect(testlink.TestlinkAPIClient)
print tls.whatArgs('createTestPlan')
> createTestPlan(<testplanname>, <testprojectname>, [note=<note>], [active=<active>],
                 [public=<public>], [devKey=<devKey>])
>  create a test plan

or generate a description of all implemented API method:

import testlink
tlh = testlink.TestLinkHelper()
tls = tlh.connect(testlink.TestlinkAPIClient)
for m in testlink.testlinkargs._apiMethodsArgs.keys():
    print(tls.whatArgs(m), '\n')

Copy test cases

Copy an existing test case into another test suite with changed name:

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> tc_info = tls.getTestCase(None, testcaseexternalid='NPROAPI-3')
[{'full_tc_external_id': 'NPROAPI-3', ..., 'id': '5440',  'version': '2',
  'testsuite_id': '5415', 'tc_external_id': '3','testcase_id': '5425', ...}]
>>> tls.copyTCnewTestCase(tc_info[0]['testcase_id'], testsuiteid=newSuiteID,
                                         testcasename='a new test case name')

Create a new test case version with changed summary and importance:

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> tc_info = tls.getTestCase(None, testcaseexternalid='NPROAPI-3')
[{'full_tc_external_id': 'NPROAPI-3', ..., 'id': '5440',  'version': '2',
  'testsuite_id': '5415', 'tc_external_id': '3','testcase_id': '5425', ...}]
>>> tls.copyTCnewVersion(tc_info[0]['testcase_id'], summary='new summary',
                                                    importance='1')

Default is, that the last version of a test case is used for the copy. If a different version should be used, specify the required version as second argument. Examples:

>>> tls.copyTCnewTestCase(tc_info[0]['testcase_id'], 1, testsuiteid=newSuiteID,
                                         testcasename='a new test case name')
>>> tls.copyTCnewVersion(tc_info[0]['testcase_id'], 1, summary='new summary',
                                                       importance='1')

Report test results

Using the TestLink API Client - failed test case with none default reporter (argument 'users' usable with TL >= 1.9.10):

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> import testlink
>>> tls.reportTCResult(a_TestCaseID, a_TestPlanID, 'a build name', 'f',
                       'some notes',
                       user='a user login name', platformid=a_platformID)

Using the TestLink Generic API Client - passed test case with none default reporter:

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIGeneric)
>>> import testlink
>>> tls.reportTCResult(a_TestPlanID, 'p', testcaseid=a_TestCaseID,
                       buildname='a build name', notes='some notes',
                       user='a login name', platformid=a_platformID)

Using the TestLink Generic API Client - blocked test case with alternative optional args, default reporter (user for devKey)

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIGeneric)
>>> exTCID = tls.getTestCase(testcaseid=a_TestCaseID)[0]['full_tc_external_id']
>>> tls.reportTCResult(a_TestPlanID, 'b', testcaseexternalid=exTCID,
                       buildid='a build name', platformname='a platform name')

List keywords

Using the api method - keywords for all test cases of one test suite

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> ts_kw = tls.getTestCasesForTestSuite(SuiteID, False, 'full', getkeywords=True)

Using the api method - keywords for all test cases of a test suite and their sub suites

>>> ts_kw = tls.getTestCasesForTestSuite(SuiteID, True, 'full', getkeywords=True)

Using the service method - keyword list without internal details for one test case

>>> tc_kw = tls.listKeywordsForTC(5440)
>>> tc_kw = tls.listKeywordsForTC('NPROAPI-3')

Using the service method - keyword lists without internal details for all test cases of one test suite

>>> ts_kw = tls.listKeywordsForTS('5415')

Run examples

Running example, how to use the class TestlinkAPIClient, with connection parameter defined as command line arguments [1]:

[PYENV]\testlink\Scripts\activate
python example\TestLinkExample.py
               --server_url http://[YOURSERVER]/testlink/lib/api/xmlrpc.php
               --devKey [Users devKey generated by TestLink]

Running example, how to use the class TestlinkAPIGeneric, with connection parameter defined as environment variables [2]:

[PYENV]\testlink\Scripts\activate
set TESTLINK_API_PYTHON_SERVER_URL=http://[YOURSERVER]/testlink/lib/api/xmlrpc/v1/xmlrpc.php
set TESTLINK_API_PYTHON_DEVKEY=[Users devKey generated by TestLink]
python example\TestLinkExampleGenericApi.py

Run unittests

Run unittests with TestLink Server interaction:

[PYENV]\testlink\Scripts\activate
set TESTLINK_API_PYTHON_SERVER_URL=http://[YOURSERVER]/testlink/lib/api/xmlrpc.php
set TESTLINK_API_PYTHON_DEVKEY=[Users devKey generated by TestLink]
cd test\utest
python -m unittest discover -s test\utest-online

Run unittests without TestLink Server interaction:

[PYENV]\testlink\Scripts\activate
cd test\utest
python -m unittest discover -s test\utest-offline
[1]TestLinkExample.py creates a new test project NEW_PROJECT_API-[CountProjects+1].
[2]TestLinkExampleGenericApi.py creates a new test project PROJECT_API_GENERIC-[CountProjects+1].