testlink+jenkins+python api接口測試環境搭建

前提:
1、安裝Testlink
2、安裝Jenkins
3、安裝python

獲取testlink個人密鑰
Testlink相關配置與用例管理
爲了批量設置接口ip,端口(主要是這兩個),協議信息(僅用於展示),需要對項目,計劃,套件等必要的配置,以及客戶端環境變量配置

a)API相關配置
如下,登陸Testlink,進入用戶管理-查看用戶,如下

點擊目標用戶(例中爲admin),打開如下界面

點擊生成新的密鑰,如下
在這裏插入圖片描述
或者是點擊“編輯用戶按鈕”按鈕進入界面
在這裏插入圖片描述
在運行python腳本端進行環境變量的配置,如下:
1、新建系統環境變量“TESTLINK_API_PYTHON_DEVKEY”,變量值爲上述祕鑰

2、新建“TESTLINK_API_PYTHON_SERVER_URL”系統環境變量,變量值爲“
http://{host}/testlink/lib/api/xmlrpc/v1/xmlrpc.php”,其中host爲testlink的訪問地址

測試是否生效:

C:\Users\laiyu>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> tls.testLinkVersion()
'1.9.14'

注意:如果還不行,提示404錯誤,則還需要配置testlinkhelper.py 中的DEFAULT_SERVER_URL,將其設置爲http://{host}/testlink/lib/api/xmlrpc/v1/xmlrpc.php
python_installation_home\Lib\site-packages\TestLink-API-Python-client-master\build\lib\testlink\testlinkhelper.py

打開pycharm,新建test.py
安裝TestLink-API-Python-client

import testlink

url = 'http://{host}/testlink/lib/api/xmlrpc/v1/xmlrpc.php'
key = '剛剛生成的API密鑰'

tlc = testlink.TestlinkAPIClient(url, key)
# 獲取testlink上的信息
def get_information_test_project():
    print("Number of Projects      in TestLink: %s " % tlc.countProjects())
    print("Number of Platforms  (in TestPlans): %s " % tlc.countPlatforms())
    print("Number of Builds                   : %s " % tlc.countBuilds())
    print("Number of TestPlans                : %s " % tlc.countTestPlans())
    print("Number of TestSuites               : %s " % tlc.countTestSuites())
    print("Number of TestCases (in TestSuites): %s " % tlc.countTestCasesTS())
    print("Number of TestCases (in TestPlans) : %s " % tlc.countTestCasesTP())
    tlc.listProjects()

get_information_test_project()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章