Robot Framework是一款python語言編寫,通用的功能自動化測試框架。它使用了比較易用的表格數據語法,基于關鍵字驅動測試,主要用來驗收測試和驗收測試驅動開發(ATDD)。
本文主要介紹Robot Framework在python2.7環境下的安裝及一個http接口自動化測試demo。
使用pip命令安裝:
pip install robotframework
wxPython是python下非常優秀的GUI圖形庫,這里安裝是由于RIDE需要用到。
特別強調下,RIDE GUI目前必須要用wxPython 2.8.12.1版本。
原文如下:
"RIDE's GUI is implemented using wxPython toolkit. Only wxPython 2.8.12.1 with Unicode support is officially supported. Possible new releases in wxPython 2.8 series ought to work fine too. wxPython 3.0 support is one of the priorities for future development."
下載地址:http://sourceforge.net/projects/wxpython/files/wxPython/2.8.12.1/
百度網盤地址:http://pan.baidu.com/s/1dFc8M1z
RIDE是一個圖形界面的用于創建、組織、運行測試的軟件。
使用pip命令安裝:
pip install robotframework-ride
看名字就知道,這是Robot Framework的內部HTTP測試庫。
使用pip命令安裝:
pip install robotframework-httplibrary
windows環境下打開命令提示符cmd,輸入ride.py進入RIDE界面,如下
FILE->NEW Project新建測試項目,可以填寫項目名稱、選擇路徑
我們需要導入httplibrary庫,選擇Library,填寫http庫名稱HttpLibrary.HTTP
選擇測試項目demo,右鍵New Test Case,填寫測試用例名稱
每個庫提供的API都不一樣,我們可以在RIDE中按F5快捷鍵打開Search Keywords進行查找,這樣可以獲取API關鍵詞的名稱,參數及文檔介紹。
也可相關庫的官方網站查看相關API及demo,如httplibrary庫:
http://peritus.github.io/robotframework-httplibrary/HttpLibrary.html
參考官方提供的demo,我們編寫一個簡單的HTTP Get請求頁面返回302后的跳轉測試用例:
https://github.com/peritus/robotframework-httplibrary/#usage
測試流程解析如下:
新建http請求后發送Get /302請求,判斷返回結果;然后進行頁面跳轉并驗證頁面是否包含"generating different HTTP codes"字符。
在RIDE頁面,按F8快捷鍵執行測試,可以看到執行結果為pass,同時生成了三個結果文件
在RIDE頁面,按CTRL+R快捷鍵查看測試報告Report,CTRl+L查看測試日志Log
至此我們使用Robot Framework框架,跑完了一個http接口的自動化測試demo,很簡單淺顯,后續根據實際使用情況再繼續更新。
原文轉自:http://www.cnblogs.com/lovesoo/p/7748487.html