python3+Robot Framework+PyCharm 環境部署

1、涉及軟件

  1. python:RF是基於python 的,因此須要有python環境
  2. wxPython:是Python語言的一套優秀的GUI圖形庫。容許Python程序員很方便的建立完整的、功能鍵全的GUI用戶界面。 RIDE 是基於這個庫開發的,因此這個必須安裝,python和wxpython的版本是須要對應的。

  3. Robot Famework:是一款python編寫的功能自動化測試框架。具有良好的可擴展性,支持關鍵字驅動,能夠同時測試多種類型的客戶端或者接口,能夠進行分佈式測試執行。主要用於輪次不少的驗收測試和驗收測試驅動開發(ATDD)。
  4. Robot Framework-Ride:是Robot Famework的圖形操做前端,用於建立、組織、運行測試;
  5. Selenium:自動化測試工具,它主要是用於 Web 應用程序的自動化測試,但並不僅侷限於此,同時支持全部基於 web 的管理任務自動化。
  6. Robot Framework-selenium2libraryRobot Framework的Web測試庫,它在內部使用Selenium工具
  7. Browser drivers:瀏覽器驅動,安裝庫以後,您仍須要爲要在測試中使用的全部瀏覽器安裝瀏覽器和特定於操做系統的瀏覽器驅動程序。
  8. decorator:Python 裝飾器。
  9. Pycharm:一種Python IDE,帶有一整套能夠幫助用戶在使用Python語言開發時提升其效率的工具,好比調試、語法高亮、Project管理、代碼跳轉、智能提示、自動完成、單元測試、版本控制。此外,該IDE提供了一些高級功能,以用於支持Django框架下的專業Web開發。
  10. IntelliBotRobot Framework的Pycharm 插件,可以使編輯器識別robotframework的腳本文件。

2、安裝步驟

一、Python 3.7.4 

官網下載:http://www.python.org/downloadhtml

安裝:建議使用安裝包形式安裝前端

配置環境變量python

驗證:控制檯輸入 python –Vgit

二、wxPython

pip命令安裝:pip install  wxPython程序員

驗證:控制檯輸入 python import wxPythongithub

三、Robot Framework

pip install robotframeworkweb

四、Robot Framework-Ride

pip install robotframework-ridechrome

五、Selenium

pip install seleniumapi

此步驟可省略,直接進入下一步,下一步的安裝包包含此內容。瀏覽器

clip_image001[7]

六、Robot Framework-seleniumlibrary

pip install robotframework-selenium2library

升級使用最新的庫 SeleniumLibrary
pip install --upgrade robotframework-seleniumlibrary

clip_image001

七、Browser  drivers

1)手動下載

下載地址:https://seleniumhq.github.io/selenium/docs/api/py/index.html#drivers

下載完畢後解壓至特定目錄,並添加路徑至path變量中。

2)pip命令下載

使用名爲WebdriverManager的工具,它能夠找到最新版本或在須要時爲您找到任何版本的相應Web驅動程序,而後下載並連接/複製到正確的位置。工具能夠在全部主要操做系統上運行,並支持下載Chrome,Firefox,Opera和Edge網絡驅動程序。舉例以下:

pip install webdrivermanager webdrivermanager firefox chrome --linkpath / usr / local / bin

八、decorator

pip install decorator

clip_image001[5]

九、Pycharm

官網:https://www.python.org/ 下載安裝,本文中使用版本爲2019.1.3

十、IntelliBot

IntelliBot是Pycharm的插件,經過Pycharm進行安裝

1)、安裝IntelliBot

File—>settings—>Plugins—>搜索 IntelliBot—>install

 

2)、配置robotframework的文件類型識別

File—>settings—>Editor—>File Types  -->Robot Feature –>在Registered Patterns 中添加兩種類型:*.txt,*.robot

點擊保存

image

3)、運行配置

File—>settings—>Tools—>External Tools –>添加兩個運行配置。

image

The robot script is new in Robot Framework 3.0. Prior to that, there were pybot, jybot and ipybot scripts that executed tests using Python, Jython and IronPython, respectively. These scripts were removed in Robot Framework 3.1 and nowadays robot must be used regardless the interpreter.

Robot Framework 3.0 後,pybot、jybot、ipybot 被移除,僅支持robot使用。

a、suite 運行時配置

name:   Robot Run TestSuite

Program:  D:\Python37\Scripts\pybot.bat  (python安裝目錄下面pybot.bat的路徑,若是「D:\Python36\Scripts\」有加環境變量,這裏能夠直接寫pybot.bat)

Arguments:   -d results $FileName$  (-d results 意思是生成的結果放到results 目錄下面,$FilePath$是執行測試套件或者單條用例的路徑)

Working directory:   $FileDir$  (工做目錄,上面一個參數的results 目錄會建立在這個目錄的下一級)

name: Robot Run TestSuite

Program: D:\Python\Python37\Scripts\robot.exe

Arguments: -d results $FileName$

Working directory: $FileDir$

b、case 運行時配置

name:   Robot Run SingleTestCase

Program:  D:\Python37\Scripts\pybot.bat

Arguments:   -d results -t "$SelectedText$" ./

Working directory:   $FileDir$

以上配置致使用例執行失敗,替換爲以下配置

name:   Robot Run SingleTestCase

Program:  D:\Python\Python37\Scripts\robot.exe

Arguments:   -d results "$SelectedText$"

Working directory:   $FileDir$

4)、robot 腳本運行驗證

測試腳本以下:

*** Settings *** Library Selenium2Library *** Test Cases *** test01 [Documentation] 測試淘寶 Open Browser https://login.taobao.com/member/login.jhtml chrome Click Element xpath=//*[@id="J_Quick2Static"] Sleep 1 Input Text xpath=//*[@id="TPL_username_1"]    123 Input Text xpath=//*[@id="TPL_password_1"]    123 ${title_1} Get Title Click Button xpath=//*[@id="J_SubmitStatic"] Sleep 2 ${title_2} Get Title should not contain ${title_2} ${title_1} Close browser

 

選中腳本,右鍵—>External Tools –>Robot Run TestSuite

image

執行結果:

image

測試報告以下:

image

3、可能遇到的問題

在設置robot 運行配置時,可能會發現本身的Python安裝路徑中找不到pybot.bat文件,解決辦法以下:

1.打開目錄:D:\Python37\Scripts\

2.新建一個pybot.txt的文本

3.文本內容輸入:

@Echo off python -m robot.run %*

4.保存文件,修改文件後綴爲.bat

5.大功告成!

相關文章
相關標籤/搜索