Skip to content

Latest commit

 

History

History
220 lines (159 loc) · 8.91 KB

usage.rst

File metadata and controls

220 lines (159 loc) · 8.91 KB

TestLink-API-Python-client Usage

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 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')

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)
>>> 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)
 >>> 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')

This test result uses the external test case id and not the internal.

  • argument 'execduration' and 'timestamp' usable with TL >= 1.9.14:
  • argument 'steps' usable with TL >= 1.9.15:
>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> tls.reportTCResult(None, newTestPlanID_A, None, 'f', '', guess=True,
                       testcaseexternalid=tc_aa_full_ext_id, platformname=NEWPLATFORM_A,
                       execduration=3.9, timestamp='2015-09-18 14:33',
        steps=[{'step_number' : 6, 'result' : 'p', 'notes' : 'result note for passed step 6'},
               {'step_number' : 7, 'result' : 'f', 'notes' : 'result note for failed step 7'}]  )

uploading attachments can be done in two different ways

with a file descriptor:

a_file_obj=open(A_VALID_FILE_PATH)
newAttachment = myTestLink.uploadExecutionAttachment(a_file_obj, A_Result_ID,
                                 'Attachment Title', 'Attachment Description')

with a file path:

a_file_path=A_VALID_FILE_PATH
newAttachment = myTestLink.uploadExecutionAttachment(a_file_path, A_Result_ID,
                                 'Attachment Title', 'Attachment Description')

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')

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
[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].

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

Under Py26, unittest2 must be used.

If for debugging reasons the original exchanged XML data are needed, initialise the API client with the optional argument verbose set to True:

>>> tlh = testlink.TestLinkHelper()
>>> tls = testlink.TestlinkAPIClient(tlh._server_url, tl._devkey, verbose=True)
 send: b"POST /testlink/lib/api/xmlrpc/v1/xmlrpc.php HTTP/1.1\r\nHost: ...
       <?xml version='1.0'?>\n<methodCall>\n<methodName>tl.getUserByLogin</methodName>\n<params>...</params>\n</methodCall>\n"
 reply: 'HTTP/1.1 200 OK\r\n'
 header: Date header: Server header: ... body: b'<?xml version="1.0"?>\n<methodResponse>\n  <params> ...'
 body: b'</name><value><string>1</string></value></member>\n</struct></value>\n  <value><struct>\n ...'
 body: b'...  </params>\n</methodResponse>\n'