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

來源:互聯網
上載者:User

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

相比SeleniumLibrary,Selenium2Libarary的優勢如下:

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

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

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

如果你用windows: 

https://github.com/rtomac/robotframework-selenium2library/downloads

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

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

Github下載:

https://github.com/rtomac/robotframework-selenium2library

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

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

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

http://pypi.python.org/pypi/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.

   解決辦法:官網http://code.google.com/p/selenium/downloads/list下載對應IEDriver.exe,並將其放在python目錄下

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.