Python 自動化測試開源(免費)工具集

Python 自動化測試工具集

這篇文章主要介紹Python在進行自動化測試可以利用的工具集,

每一個工具都可以解決特定的問題,目的不外乎是

  • 1. 達成自動化測試的特目標
  • 2. 讓自動化測試程式更好維護
  • 3. 自動化測試更容易開發

所以,自動化測試沒有一定要用這篇文章”所有”的工具,在適當的情境與類似的問題下,讀者可以採用其中一兩項。

這篇筆者介紹幾個在 Python 中解決一些特定領域問題的自動化測試開源”免費”工具與使用情境。

 UnitTest

提到 Python unitTest 的測試,筆者會建議使用這兩個模組。 unitTest 與 Nose。

UnitTest 其實不只有在做 “unit” Testing單元測試才使用,對於整合 or End 2 End 的測試我們主要使用 UnitTest 達到下列目的:

  • setUP ….test….tearDown: 透過setup 與 teardown 我們可以為每一次的測試程式準備相關的資料與所需環境。
  • 測試結果與測試報告:透過 unitTest 的寫法,可以讓我們方便的將每一個method/function 變成測試個案。每個測試個案成功與失敗都可以透過 unitTest  report 輸出為 XML or HTML。

為什麼要用 Nose 呢?

想想有一個情境。我們已經寫好 20 測試程式。執行的話可能會:

  • python testcase1.py
  • python testcase2.py
  • python testcase3.py
  • ……

使用 nose 就不需要這些步驟,因為 nose 會搜尋整個目錄所有的測試程式自動啟動執行。當然 nose也可以指定特定的 testcase程式執行。

另外,nose 有許多的模組可以使用,其中最方便的就是測試結果報告。 HTML or XML 格式都有。因為 Python 內建的 unitTest 的測試報告沒有 HTML或是XML的輸出格式。如果需要將測試結果輸出到 Jenkins DashBoard我們就可以透過 nose輸出為 XML。

unitTest/Nosetests 相關連結下載

  • unittest – is a library to make unit testing distributed with python out of the box.
  • nosetests – is a nicer testing for python.

Web Automation

對於 python來說進行網站自動化測試主要有兩種方式。一個是啟動瀏覽器針對網頁畫面操作。

另外一種方式則是針對 Web service API 直接操作,送出 http get/Post.

Selenium 與 splinter 都是啟動瀏覽器針對網頁畫面自動化測試的方式。

splinter 特別在於將原本 Selenium WebDriver/Python 的程式再進一步做一些簡化。

  • selenium webdriver – Browser automation tool.
  • splinter – A tool for test web applications with a simple for find elements, form actions, and others browser actions.

 

Windows UI 自動化測試

Selenium 最大的缺點就是無法處理 Windows native UI。因此,當遇到 windows native UI 時,

Selenium通常要呼叫外部執行程式 (例如 AutoIT)完成。

除了 AutoIT之外,這邊介紹幾個 Python 可以處理 Windows native UI 的自動化測試模組。

  • PywinAuto + SWAPY
  • PyAutoGUI – A cross-platform module for GUI automation for human beings. Visual Image actions. 但是螢幕解析度有問題??
  • 如何檢查 windows UI
    • SWAPY, Au3Info, Inspect, Windows Detective

Behavior Driven Testing

為什麼要採用 BDD ?

  • behave – BDD tool
  • robotframework – A generic test automation framework for acceptance testing and acceptance test-driven development (ATDD)

Http

Data Driven Testing

Page Object

  • webium – A Page Object pattern implementation library for Python

 

PyCharm IDE

 

參考資訊

https://github.com/atinfo/awesome-test-automation

其它參考資訊

Leave a Reply

Your email address will not be published. Required fields are marked *