1. 程式人生 > >RobotFramework+seleniumlibrary Web自動化測試 (三)

RobotFramework+seleniumlibrary Web自動化測試 (三)

考慮到selenium2的功能更為完善,為避免後續可能出現的問題,計劃將seleniumlibrary 升級為 selenium2library,

相比SeleniumLibrary,Selenium2Libarary的優勢如下:

1.由於將通過起Server然後向瀏覽器注入JS,通過JS引擎操縱瀏覽器的方式改為了直接操縱瀏覽器介面的方式,Selenium2Library速度有了顯著提升,穩定性也得到了進一步加強。

2.能夠越過瀏覽器沙箱操控其它資源,比如:檔案上傳,彈出的windows窗體等。

3.因為底層的webdriver使用blocking Api( 頁面請求發出後,瀏覽器等待結果的返回,其間不能做後續操作),那些噁心的wait和don’t wait 引數就可以扔掉了。

如果你用windows: 

在上面頁面上下載對應的安裝包,一路點選next就安裝好了。後面的命令列安裝方式可以略過。

————————————————————————

Github下載:

可以直接下載zip檔案,也可以用svn工具下載原始碼。

在命令列模式進入下載好的檔案目錄(如果下載的是zip,解壓到一個資料夾),執行setup.py install來安裝。

如果提示錯誤,可能是你沒有安裝python的setuptools,先安裝它再嘗試上面步驟。

另外有兩個庫是seleniuim2中必須的

easy_install decorator

easy_install docutils


驗證安裝是否成功:

Selenium2Library個出了一個很cool的驗收測試。

我們使用它提供的驗收測試就能檢視是否安裝成功,並且順便測試了selenium2Library的測試。

我們可以在命令列進入它的Test子目錄然後執行run_test.py python ie

這個指令碼的作用其實是起了一個微型的webserver,然後用瀏覽器訪問這個server,作為被測系統。

最後呼叫robotframework對這個被測系統進行測試。如果看到絕大部分pass了,說明你裝好了。

新增的關鍵字:

  • Get Selenium Speed
  • Get Selenium Timeout
  • Log Title
  • Log Location

引數改變的關鍵字

  • Choose File – Pulled remote files support
  • Click Button – Removed dont_wait argument
  • Click Element – Removed dont_wait and coordinates arguments
  • Click Image – Removed dont_wait argument
  • Click Link – Removed dont_wait argument
  • Double Click Element – Removed dont_wait and coordinates arguments
  • Go Back – Removed dont_wait argument
  • Open Context Menu – Removed offset argument
  • Press Key – Removed dont_wait argument
  • Select All From List – Removed wait argument
  • Select Radio Button – Removed wait argument
  • Submit Form – Removed dont_wait argument

移除的關鍵字

  • Flex-related keywords
  • Add Location Strategy
  • Call Selenium API
  • Capture Screenshot (better support for Capture Page Screenshot in Selenium 2/WebDriver, and conversely no support for full screen screenshot)
  • Drag And Drop (requires Advanced User Interactions API which isn’t quite ready to support this)
  • Press Key Native (requires Advanced User Interactions API which isn’t quite ready to support this)
  • Start Selenium Server
  • Stop Selenium Server
  • Wait Until Page Loaded (Selenium 2/WebDriver is blocking API, so this is not important/less important)

只可惜,我裝完之後,除了兩個case是pass外,其餘都是fail。。。。出現了各種各樣的問題:

1. 使用firefox時候,報TypeError: environment can only contain strings

   解決辦法:(待補充)

2. 使用IE時候,報WebDriverException: Message: 'IEDriver executable needs to be available in the path.

3. 重灌後執行pybot提示:

'"[PYTHON_EXECUTABLE]"' is not recognized as an internal or external command, operable program or batch file.
檢視環境變數設定正確,重新安裝無效。搜尋robotframework的issue庫。有下面解決方法:
在python的script資料夾下找到robot_postinstall.py這個檔案執行以下就解決問題了。
出現這種情況的條件是:win7,原有2.6.3版本沒有解除安裝乾淨,然後裝了2.7.4版本。
這是issue列表中的帖子連結:http://code.google.com/p/robotframework/issues/detail?id=810