轉載自:http://www.cnblogs.com/jerry-yin/articles/4812012.html
今天研究了一下基於RFS自動化測試框架實現HTTP的POST/GET請求發送執行自動化測試的過程。
首先還是要先感謝萬能的google(PS:因為在百度中完全無法找到相關信息),同時還要感謝github上面那些無私奉獻的軟件工程師們(PS:因為這里需要用到github上面原創作者的安裝和使用過程)。
好了,感謝完了,現在就是翻譯了。
第一步:安裝及配置RFS環境
略(詳細求度娘吧)
第二步:下載robotframework-request支持包。
使用github工具鏈接到https://github.com/bulkan/robotframework-requests(也可以直接用網頁打開下載里面的全部內容)
剩下的安裝過程和詳細介紹在倉庫里面其實都有描述,本人僅僅充當一下翻譯工作。
1.使用pip命令執行庫安裝
pip install -U robotframework-requests
2.安裝成功后即可打開RIDE添加測試用例。
如:
| Settings | ||||
| Library | Collections | |||
| Library | RequestsLibrary | |||
| Test Cases | ||||
| Get Requests | ||||
| Create Session | github | http://api.github.com | ||
| Create Session | http://www.google.com | |||
| ${resp}= | Get Request | / | ||
| Should Be Equal As Strings | ${resp.status_code} | 200 | ||
| ${resp}= | Get Request | github | /users/bulkan | |
| Should Be Equal As Strings | ${resp.status_code} | 200 | ||
| Dictionary Should Contain Value | ${resp.json()} | Bulkan Savun Evcimen |
3. 庫API介紹。
| Keyword |
Arguments |
Documentation |
| Create Ntlm Session |
alias, url, auth, headers={}, cookies=None, timeout=None, proxies=None, verify=False |
創建一個HTTP會話: url:即服務器的url alias:使用Robot Framework的別名表示當前會話。 header:使用默認的headers字段 auth:NTLM鑒權需用[‘domain’,’username’,’password’]格式 timeout:會話超時時長 proxies:代理服務器的url verify:如果需要證書請求則置為true |
| Create Session |
alias, url, headers={}, cookies=None, auth=None, timeout=None, proxies=None, verify=False |
創建一個HTTP會話: url:即服務器的url alias:使用Robot Framework的別名表示當前會話。 header:使用默認的headers字段 auth:NTLM鑒權需用username&password格式 timeout:會話超時時長 proxies:代理服務器的url verify:如果需要證書請求則置為true |
| Delete |
alias, uri, data=(), headers=None, allow_redirects=None |
棄用,查看delete request |
| Delete All Sessions |
刪除全部的會話 |
|
| Delete Request |
alias, uri, data=(), headers=None, allow_redirects=None |
使用別名刪除會話 Alias:需要刪除的會話的別名 |
| Get |
alias, uri, headers=None, params={}, allow_redirects=None |
棄用:使用Get Request |
| Get Request |
alias, uri, headers=None, params={}, allow_redirects=None |
根據提供的別名查找會話並在會話中發送GET請求 |
| Head |
alias, uri, headers=None, allow_redirects=None |
棄用:使用Head Request |
| Head Request |
alias, uri, headers=None, allow_redirects=None |
根據提供的別名查找會話並在會話中發送HEAD請求 |
| Options |
alias, uri, headers=None, allow_redirects=None |
棄用:使用Options Request |
| Options Request |
alias, uri, headers=None, allow_redirects=None |
根據提供的別名查找會話並在會話中發送Options請求 |
| Post |
alias, uri, data={}, headers=None, files={}, allow_redirects=None |
棄用:使用Post Request |
| Post Request |
alias, uri, data={}, headers=None, files={}, allow_redirects=None |
根據提供的別名查找會話並在會話中發送POST請求 |
| To Json |
content, pretty_print=False |
將返回的數據轉換為JSON格式 |
