打算用Protractor做網頁End-to-End測試。Protractor是Angular的主流測試工具,End-to-End測試時會開啟瀏覽器連上網站模擬各種操作,以使用者角度實際驗證功能是否正常。

第一步要在開發機器Windows 8安裝node.js跟Protractor,主要參考Paul Li圖文並茂的介紹文-Protractor - 環境設定篇,安裝大致順利,但過程遇到一些小亂流,特筆記之。

第一個問題來自公司的特殊網路環境,基於資安監管要求,網管設備攔截HTTPS傳輸從中抽換SSL憑證,換上的中間人憑證被npm打搶,得到CERT_UNTRUSTED certificate not trusted錯誤。

解決方法有二,第一種是使用指令npm config set strict-ssl false關閉憑證安全檢查,但此舉對資安有小潔癖的我如同脫光衣服上街,嗯湯呀嗯湯。故我採用比較迀迴但安全的第二種做法,讓npm認可公司網管設備的SSL憑證。方法是匯出網路設備使用的CA根憑證:(以下為示意圖)

格式請Base64編碼的CER:

接著使用npm config set cafile=c:\folder_name\ca_cert_file.cer信任網路設備憑證,終於能如願下載模組。

此時,我遇到第二個問題:

安裝相關模組node-gyp(可跨平台編譯二進位程式庫的工具)時,冒出Can't find Python executable "python", you can set the PYTHON env variable錯誤。依官方文件,node-gyp需要Python 2.7(Python最新版為3.4,但node-gyp適用舊版)及Visual Studio C++ 2010,心想我的Visual Studio 2013有裝C++環境,應該也能Build吧!結果:

冒出錯誤error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, pleaswe install Visual Studio 2010 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right–click the solution, and then selecting "Upgrade Solution…". [C:\Users\jeffrey\AppData\Roaming\npm\node-modules\protrator\node_modules\selenium-webdriver\node_modules\ws\node_modules\bufferutil\build\bufferutil.vcxproj]

修改bufferutil.vcxproj調成改用VS2013編譯是最直覺最快的解決方案,但發現bufferutil.vcxproj為動態下載取得產生,安裝失敗就消失,無從改起。很不甘心為此要多安裝VS2010,所幸npm夠貼心,有個msvs_version參數可以克服問題。使用指令:npm config set msvs_version 2013,終於順利安裝好Protractor。


Comments

Be the first to post a comment

Post a comment