zoukankan      html  css  js  c++  java
  • 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:

    1. Open config.inc.php
    2. Search for  /** XML-RPC API availability (disabled by default) */ $tlCfg->api->enabled = FALSE;
    3. Change FALSE to TRUE $tlCfg->api->enabled = TRUE;
    4. Save config.inc.php
    5. Login to Testlink UI as admin
    6. Go to 'My Settings'
    7. Under API interface, click 'Generate new key'
    8. Copy the key generated
    9. 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.

  • 相关阅读:
    ionic入门之AngularJS扩展基本布局
    ionic入门之AngularJS扩展(一)
    test
    面试题小整理
    使用Code first 进行更新数据库结构(数据迁移)
    SQL模糊查询与删除多条语句复习
    GridView 根据要求显示指定值
    个人工作记录---工作中遇到的sql查询语句解析
    数据库,inner join,left join right join 的区别
    利用set实现去重
  • 原文地址:https://www.cnblogs.com/cursorkey/p/5636178.html
Copyright © 2011-2022 走看看