- 1安裝指南
- 2各類自動化工具
- 2.1安裝 Java SDK 8
- 2.2安裝 Maven
- 2.3安裝 Git
- 2.4*安裝 GitLab-Runner
- 2.5安裝 Python3
- 2.6安裝 setuptools 與 pip
- 2.7安裝 Chrome 瀏覽器
- 2.8安裝 Chrome 瀏覽器驅動
- 2.9安裝 RobotFramework 等 python 庫
- 2.10安裝 IDE
- 2.10.1PyCharm / IDEA
- 2.10.2Visual Studio Code
- 2.10.3Robotframework-Ride (RIDE) - 不建議用
- 3常見問題
當我們在本地電腦開發自動化測試,或者在流水線上或其他環境上部署新的跑自動化用例的機子時候,我們需要安裝一系列相關的軟件包。此文爲此給出了安裝指南。
安裝指南
- 範圍:
- 個人開發用機
- 個人開發用的手提電腦、桌面機等
- 測試專用虛擬機
- 各項目通過GitLab流水線共同使用
- 或在甲方內部網絡的測試機
- 測試專用物理機
- APP測試的手機模擬器需要先搭建一個虛擬機,所以用物理機可以更穩定和流暢(待更新)
- 個人開發用機
- 操作系統:
- 如果是測試專用機,推薦使用 Ubuntu 20,已有Python3,工具支持度好,可自動化程度高,免費,開源,更新及時;但是企業微信無支持。
- 個人的本地開發環境,推薦用MacOS 。MacOS terminal 的命令類似Linux,體驗良好。Windows 問題很多。
- 內存:8G+
- CPU內核:4+
-
安裝工具:
-
命令行安裝工具
Ubuntu
MacOS
Windows
Ubuntu命令行安裝工具apt
$
sudo
apt
install
-h
Ubuntu命令行安裝工具 dpkg, 可以安裝下載後的deb包,如:
$
sudo
dpkg -i google-chrome-stable_current_amd64.deb
MacOS命令行安裝工具brew
% brew
install
-i
setup.exe
-
Python命令行安裝工具 pip,通過阿里雲鏡像安裝各軟件,適用於Windows(Admin權限的Git Bash),Ubuntu Linux和MacOS
-
各類自動化工具
安裝 Java SDK 8
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
安裝 Maven
http://maven.apache.org/download.cgi
安裝 Git
Windows 系統會自動安裝Git Bash,下面會用得到。
*安裝 GitLab-Runner
(*僅要配置流水線公用的Runner時需要,個人使用的電腦不需要裝)
官方下載地址:https://docs.gitlab.com/runner/install
登記成爲GitLab-Runner:
C:\Users\AIT\Downloads>gitlab-runner-windows-amd64.exe install C:\Users\AIT\Downloads>gitlab-runner-windows-amd64.exe start C:\Users\AIT\Downloads>gitlab-runner-windows-amd64.exe register --non-interactive --executor "shell" --url "https://gitlab.devops.cndatacom.com/" --registration-token "Dda5eJz8AzTzTQpdPvqR" --description "windows" --tag-list "windows+android" --run-untagged= "true" --locked= "true" --access-level= "not_protected" Runtime platform arch=amd64 os=windows pid=2024 revision=8925d9a0 version=14.1.0 Registering runner... succeeded runner=Dda5eJz8 Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! |
安裝 Python3
官方下載地址:https://www.python.org/downloads/
建議下載3.8.x版本的安裝包。
下載後雙擊文件安裝,默認安裝路徑爲:C:\Users\Administrator\AppData\Local\Programs\Python\Python38(可自行更改安裝路徑)
python安裝完成後,必須配置環境變量,在Path變量中加入python的兩個路徑:
Windows => System => Advanced System Settings => Advanced tab => Environment Variables => Path => Edit => New
C:\Users\Administrator\AppData\Local\Programs\Python\Python38;
C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Scripts。
配置完環境變量,在cmd命令行窗口輸入python,提示如下信息表示安裝成功。
>python -V Python 3.8.10 |
安裝 setuptools 與 pip
如果python安裝過程已安裝setuptools與pip,此步驟可以省略不做。否則,按這個鏈接操作安裝pip:install pip on windows - jmbkeyes - 博客園 (cnblogs.com)。
查看python是否有安裝setuptools與pip,可cmd命令行輸入pip list。
編輯pip.conf 文件,默認使用阿里雲鏡像:
$ cat /etc/pip .conf # 運行在 Git Bash 或其他 Shell 中 [global] index-url=http: //mirrors .aliyun.com /pypi/simple/ [ install ] trusted-host=mirrors.aliyun.com |
安裝 Chrome 瀏覽器
- 推薦用 Chrome - https://www.google.cn/chrome
-
如果知道版本號,可以直接下載,例如,在Ubuntu系統下,下載 97.0.4692.71-1:
wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb
-
- 注意:Chrome 版本98+ 有問題,建議只更新到版本97, https://stackoverflow.com/questions/70967207/selenium-chromedriver-cannot-construct-keyevent-from-non-typeable-key
安裝 Chrome 瀏覽器驅動
Chromedriver(谷歌)下載地址(注意需要與谷歌瀏覽器版本對應):https://registry.npmmirror.com/binary.html?path=chromedriver/
chromedriver 下載完成解壓後,將chromedriver.exe文件放到python安裝目錄(C:\Users\Administrator\AppData\Local\Programs\Python\Python38)。對應的谷歌瀏覽器也是如此。Linux 或者 MacOS,推薦將chromedriver安裝到 /usr/local/bin。
安裝 RobotFramework 等 python 庫
按照下載好的 requirements.txt 安裝相關的python庫:
pip install -r requirement.txt -i https://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
安裝完畢,1)對照下表確認 python 庫版本符合:
2)運行 robot --help 確認Robot Framework 安裝成功並能執行。
安裝 IDE
選擇一個 IDE 做robot framework 文件(.robot)的編輯/運行器,不建議用 RIDE:
-
PyCharm / IDEA
- 安裝插件:
- Hyper Robot Framework Support (Windows 不要安裝,有問題)
- Robot Framework Language Server
- Robot Framework Support
- Run Robot Framework file
- YAML
- Git
- 安裝插件:
-
Visual Studio Code
- 安裝插件:
- Python
- Robot Framework Intellisense
- Robot Framework Language Server
- robotframework
- robotcode(僅支持python3.8+)
- Robotframework Debugger
- 安裝插件:
-
Robotframework-Ride (RIDE) - 不建議用
- 安裝 wxPython
- pip install wxPython==4.0.7.post2 -i https://mirrors.aliyun.com/pypi/simple/
- 安裝 robotframework-ride
- pip install robotframework-ride -i https://mirrors.aliyun.com/pypi/simple/
- 安裝 wxPython
常見問題
使用RIDE時在中文Windows下出現Locale問題
self.normal = self._get_image(image_list, normal) File "C:\Users\AIT\AppData\Local\Programs\Python\Python38\lib\site-packages\robotide\ui\images.py" , line 91, in _get_image img = wx.Image(path, wx.BITMAP_TYPE_PNG).ConvertToBitmap() wx._core.wxAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), " C ") == 0" failed at ..\..\src\common\intl.cpp(1579) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C /C ++ and Windows locale. Things are going to break , please only change locale by creating wxLocale objects to avoid this! |
解決方法
- 編輯 site-packages\robotide\ui\images.py 和 site-packages\robotide\application\application.py
增加一句wx.Locale(wx.LANGUAGE_ENGLISH):
class TreeImageList(wx.ImageList): def __init__( self ): wx.ImageList.__init__( self , * _SIZE) self .locale = wx.Locale(wx.LANGUAGE_ENGLISH) # 增加這一句 |
class RIDE(wx.App): ... def OnInit( self ): # DEBUG To test RTL # self._initial_locale = wx.Locale(wx.LANGUAGE_ARABIC) self ._initial_locale = wx.Locale(wx.LANGUAGE_ENGLISH) self .locale = wx.Locale(wx.LANGUAGE_ENGLISH) # 增加這一句 |
在ride腳本運行後頁面出現亂碼問題解決出現亂碼
!worddav19700a0f65b5a9b1ac4531025b9039c4.png|height=319,width=554!
解決方法
site-packages\robotide\contrib\testrunner\testrunnerplugin.py下的 textctrl.AppendTextRaw(bytes(string, encoding\['SYSTEM'\]))改成 textctrl.AppendTextRaw(bytes(string, encoding\['OUTPUT'\]))