歡迎關注【無量測試之道】公眾號,回復【領取資源】,
Python編程學習資源干貨、
Python+Appium框架APP的UI自動化、
Python+Selenium框架Web的UI自動化、
Python+Unittest框架API自動化、
資源和代碼 免費送啦~
文章下方有公眾號二維碼,可直接微信掃一掃關注即可。
禪道是非常實用的項目管理平台,它在業界也是非常有名的,對於使用它來對bug進行管理也是相當便捷的,今天簡單分享一下如何通過 api 來提交bug到禪道,代碼如下:
1 import requests 2 loginhost="http://zen.beta.cn/index.php?m=user&f=login" #登錄url 3 add_bughost="http://zen.beta.cn/index.php?m=bug&f=create&productID=10&branch=0&extra=moduleID=0" #new bug url 4 5 def add_bug(): 6 header={'Content-Type': "application/x-www-form-urlencoded; charset=utf-8"}#設置請求頭 7 datas={"account":"$admin","password":"123456"} #定義請求的數據 8 s=requests.session() #實例化一個session對象 9 response=s.post(loginhost,headers=header,data=datas)#使用session發起請求 10 11 print(response.content) 12 13 data = { 14 "product": "10", # int 所屬產品 * 必填 15 "openedBuild": "master", # int | trunk 影響版本 * 必填 16 "branch": "2", # int 分支 / 平台 17 "module": "434", # int 所屬模塊 18 "project": "84", # int 所屬項目 19 "assignedTo": "baoyi", # string 指派給 20 "deadline": "2020-07-28", # date 截止日期 日期格式:YY - mm - dd,如:2019 - 01 - 01 21 "type": "codeerror", #bug類型 22 "bugPhase": "live",#bug在什么環境發現 23 "severity": "3", # int 嚴重程度 取值范圍:1 | 2 | 3 | 4 24 "pri": "3", # int 優先級 取值范圍:0 | 1 | 2 | 3 | 4 25 "keywords": "", # string 關鍵詞 26 "title": "feedback", #標題 27 "story":1143, #需求 28 "steps": "set bug link in here" # string 重現步驟 29 } 30 responses=s.post(add_bughost,headers=header,data=data) 31 print(responses.content.decode("utf-8")) 32 33 if __name__ == '__main__': 34 add_bug()
簡單說明下,requests庫的session會話對象可以跨請求保持某些參數,換句話說,就是比如你使用session成功的登錄了某個網站,則在再次使用該session對象請求該網站的其他網頁都會默認使用該session之前使用的cookie等參數。
運行代碼后效果如下:

備注:我的個人公眾號已正式開通,致力於測試技術的分享,包含:大數據測試、功能測試,測試開發,API接口自動化、測試運維、UI自動化測試等,微信搜索公眾號:“無量測試之道”,或掃描下方二維碼:

添加關注,讓我們一起共同成長!
