基於RFS(robot framework selenium)框架模擬POST/GET請求執行自動化接口測試

轉載自:http://www.cnblogs.com/jerry-yin/articles/4812012.htmlhtml

 

今天研究了一下基於RFS自動化測試框架實現HTTP的POST/GET請求發送執行自動化測試的過程。git

首先仍是要先感謝萬能的google(PS:由於在百度中徹底沒法找到相關信息),同時還要感謝github上面那些無私奉獻的軟件工程師們(PS:由於這裏須要用到github上面原創做者的安裝和使用過程)。github

好了,感謝完了,如今就是翻譯了。json

第一步:安裝及配置RFS環境api

略(詳細求度娘吧)服務器

第二步:下載robotframework-request支持包。cookie

使用github工具連接到https://github.com/bulkan/robotframework-requests(也能夠直接用網頁打開下載裏面的所有內容)框架

剩下的安裝過程和詳細介紹在倉庫裏面其實都有描述,本人僅僅充當一下翻譯工做。dom

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 google http://www.google.com  
  ${resp}= Get Request google /
  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格式

相關文章
相關標籤/搜索