2016年7月5日 星期二

Python 轉成 Exe 執行檔-Py2Exe

Hello~ Everyone!!!

今天想跟各位聊聊寫 Python 有時會遇到的問題,如何將寫好的 Python Script ".py檔" 轉成 Windows 作業系統可執行的 ".exe檔" ???

雖然在 Windows 系統上也可以執行 ".py" 但是先決條件是系統需安裝好 Python 甚至 Script 呼叫的程式庫都必須一併安裝好,不然當執行 .py 程式時一定會出錯。這時解決之道就是將寫好的 .py 程式轉成 .exe 的執行檔,使用者只需 "Double Click" 就可以輕輕鬆鬆執行程式,完全不需理會系統有沒有安裝 Python 或呼叫的程式庫等等...這是多美麗的結局啊!!!

接下來就開始這一節內容Py2Exe 依慣例一樣先來一張這一節的圖解說明: 

Step 1: First have to install correct version for Python. Py2Exe officially only support Python 2.x doesn't support Python 3.x, for this case download the last version of Python 2.7.11 here or download from official website as below.
https://www.python.org/downloads/release/python-2711/


Step 2: Double click "python-2.7.11.msi" to install Python 2.7



Step 3: Keep as default "Install for all users" then click "Next >"


Step 4: Select destination directory for Python. Normally install at "C:\Python27\" then click "Next >"


Step 5: Add python.exe to Path, select "Will be installed on local hard drive"





Step 6: Click "Finish" to complete Python installation.


Step 7: Verify Python installation. Open "cmd" then type "python -V"


Step 8: Second, download Py2Exe from here or from official website as below.
https://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/


Step 9: After download completed double click "py2exe-0.6.9.win32-py2.7.exe"



Step 10: Click "Next >


Step 11: Double check "Python Directory" and "Installation Directory" then click "Next >"


Step 12: Click "Next >"


Step 13: Click "Completed" for finish Py2Exe installation.


Step 14: This case have to install PyQt4 for the Python script file AddressBook_v10.py


Step 15: Third, download PyQt4 from here or from official websit as below.
https://www.riverbankcomputing.com/software/pyqt/download


Step 16: After download completed double click "PyQt4-4.11.4-"gpl-Py2.7-Qt4.8.7-x32.exe" 


Step 17: Click "Next >"


Step 18: License agreement, Click "I Agree"


Step 19: Keep check all components as default then click "Next >"


Step 20: Install location keep as default at "C:\Python27\" then click "Install"



Step 21: Click "Finish" for completed the installation.


Step 22: Now have to create a setup.py  for compiler Python script or download from here. (setup.py and AddressBook_v1.0.py all put in C:\Python27\)




Step 23: Open "cmd" and type "cd C:\Python27" then run "python setup.py py2exe" after Enter get the error message "MSVCP90.dll" has been missing.


Step 24: Download MSVCP90.dll from here then save under "C:\Python27\"


Step 25: Run "python setup.py py2exe" again.


Step 26: After compiled "AddressBook_v1.0.exe" has been created under "C:\Python27\dist\"



Step 27: Run "AddressBook_v1.0.exe" will get the error message in yellow.



Step 28: Modify setup.py become "setup_fix.py" or download from here.



Step 29: Run "python setup_fix.py py2exe"


Step 30: After finished compiler run "AddressBook_v1.0.exe" again.


Step 31: Can double click from"File Explorer" as well.


Step 32: Congratulation!!! It's work!!!


經過落落長的安裝 > 寫程式 > 執行編譯 > 有錯誤 > 改程式 > 再執行編譯 > 成功建立 .exe檔回想起來這過程是多漫長啊 @@,不過經由一步一步的說明,相信大家都可以成功完成的。

其實這些步驟說穿了,不外乎把握住下面幾個原則:

  • Python2.7、Py2Exe、PyQt4 都要下載對版本,目前測試結果只支援 x86 就是 32bit 的版本。
  • Py2Exe 目前只支援 Python 2.x 的版本,並不支援 Python 3.x 版本。
  • 執行 Py2Exe 編譯後,會在 C:\Python27\ 產生2個 Folder "build" 和 "dist"。
  • 一定要將 msvcp90.dll 放到 C:\Python27\ 的目錄底下。
  • 大部分的 setup.py 的寫法都用下面的方法:

from py2exe.build_exe import py2exe
from distutils.core import setup
setup( console=[{"script": "main.py"}] )
*大部分都會有錯誤出現!!!

官網有提供另一種寫法如下:
from distutils.core import setup
import py2exe
setup(windows=[{"script" : "main.py"}], options={"py2exe" : {"includes" : ["sip"]}})
*main.py for convert to main.exe

各位如果有認真看的話,應該不難發現 setup_fix.py 就是用以上這種方法寫的。在練習的過程如果真的還是遇到解不了的問題,歡迎留言提問,太陽哥再幫忙想辦法解決 :D
這一節我們就先介紹到這邊,我們下回見~ Bye Bye!!!

~ See you ~

參考出處:
https://www.python.org/
http://www.py2exe.org/index.cgi/FrontPage
https://www.riverbankcomputing.com/software/pyqt/download



2016年7月4日 星期一

Squish GUI Tester 測試工具

Hello~ Everyone!!!

今天這一節要來介紹一下 Froglogic 公司旗下的一個 GUI(Graphical User Interface) 測試工具 —Squish
首先我們先來聊聊什麼是 "Squish",它是一個跨平台、跨技術的 GUI 自動化測試工具,一般多用於 GUI 的功能性回歸測試使用。而目前所支援的平台如下:
  • Desktop:

  • Mobile:
  • Web:
  • Embedded:

目前業界有很多公司大都選擇 Squish GUI 測試,這大大縮短了測試時間並提升軟體的品質。

而這一節的內容大致會介紹一下 Squish 的安裝方式與測試方法,開始介紹前一樣先來張圖解大綱:


Step 1: First open Squish official website then click "Try Squish now"


Step 2: Fill in the form then click "Click to Download Squish GUI Tester"


Step 3: The Website will guide you how to download and also can download from below.
  • Desktop
  1. squish-6.0.3-windows.exe
  • Mobile
  1. squish-6.0.3-ios-windows.exe
  2. squish-6.0.3-android-win32.exe
  • Web
Step 4: Double click "squish-6.0.3-windows.exe" to  install Squish for test Desktop Windows version.


Step 5: Select a directory to extract Squish then click 



Step 6: Enter the License Key get from froglogic's email after register an account.


Step 7: Select "Accept" then click "Next >"


Step 8: Double click the License Type should be under "Evaluation version" then click "Next >"


Step 9: Check "Start the forglogic Squish IDE now" then click "Finish" for first start Squish IDE



9.1: Squish IDE main console.


Step 10: Create a new Squish Test Suite that got two way as below.
10.1: Click 


10.2: Click File > New Test Suite...


Step 11: Enter "Test Suite Name" and select "Test Suite folder's parent folder" then click "Next >"


Step 12: Choose GUI toolkit for test. This case select "Windows" then click "Finish(First time create test suite please follow the step 12.1)


12.1: Click "Next >" for select "Scripting Language"(ex. Python) then click "Next >"



12.2: Select Application "addressbook.exe" under test then click "Finish"


Step 13: The new test suite "TestSuite1" has been created ready.


Step 14: Create a new test case as below. Click 


14.1: Another way to create test case. Click File > New Test Case...


14.2: Enter "Test Case Name" and select "Script Test Case" then click "Finish"


Step 15: Record the test case. Click 


15.1: Select "addressbook" for the test application then click "OK"


Step 16: Show "Application" and "Control Bar"



Step 17: Fill in the detail as below for record the scenario then click "儲存".



Step 18: Select "Control Bar" then "Insert Verifications > Screenshot"


Step 19: Check the main object then click for select target "Object"




Step 20: Click "Save and Insert Verifications" then click "確認" finish the scenario record.




Step 21: Click for run the test then all pass and success show like as below.



Step 22: Now try the "Fail Case" change the script "001" to "002"

Step 23: Click for test again.


Step 24: Show "Object Not Found" then click "Pick New Object"



24.1: Select the testing "Object" and click then the window turn to "Red"


Step 25: Click "Retry" to continue the test.


Step 26: Show the "Test Results" is "Failed"


經過了漫長的安裝與攏長的測試過後,相信各位應該對 Squish 有了初步的概念。
不管是測試方法與測試概念,經由同一測試腳本修改 Script 就會有成功與失敗的兩種測試結果,這說明此測試情境是可行的。

雖然這次做的測試是執行在 Windows 底下的應用程式,以後還有機會我們會分別做 Web GUI 與 Mobile GUI 的測試案例。這一節就先介紹到這裡,我們下次見~ Bye Bye!!!

~ See you ~

參考出處:
https://www.froglogic.com/index.php