自动化环境安装指南(robotframework)

 

当我们在本地电脑开发自动化测试,或者在流水线上或其他环境上部署新的跑自动化用例的机子时候,我们需要安装一系列相关的软件包。此文为此给出了安装指南。

安装指南

  1. 范围:
    1. 个人开发用机
      1. 个人开发用的手提电脑、桌面机等
    2. 测试专用虚拟机
      1. 各项目通过GitLab流水线共同使用
      2. 或在甲方内部网络的测试机
    3. 测试专用物理机
      1. APP测试的手机模拟器需要先搭建一个虚拟机,所以用物理机可以更稳定和流畅(待更新)
  2. 操作系统:
    1. 如果是测试专用机,推荐使用 Ubuntu 20,已有Python3,工具支持度好,可自动化程度高,免费,开源,更新及时;但是企业微信无支持。
    2. 个人的本地开发环境,推荐用MacOS 。MacOS terminal 的命令类似Linux,体验良好。Windows 问题很多。
  3. 内存:8G+
  4. CPU内核:4+
  5. 安装工具:

    1. 命令行安装工具

      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

    2. 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

https://git-scm.com/download

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 浏览器

  1. 推荐用 Chrome - https://www.google.cn/chrome
    1. 如果知道版本号,可以直接下载,例如,在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

       

  2. 注意: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 库版本符合: 

 展开 pip list ...

 

2)运行 robot --help 确认Robot Framework 安装成功并能执行。

 展开 robot --help ...

 

 

安装 IDE

选择一个 IDE 做robot framework 文件(.robot)的编辑/运行器,不建议用 RIDE:

  1. PyCharm / IDEA

    1. 安装插件:
      1. Hyper Robot Framework Support (Windows 不要安装,有问题)
      2. Robot Framework Language Server
      3. Robot Framework Support
      4. Run Robot Framework file
      5. YAML
      6. Git
  2. Visual Studio Code

    1. 安装插件:
      1. Python
      2. Robot Framework Intellisense
      3. Robot Framework Language Server
      4. robotframework
      5. robotcode(仅支持python3.8+)
      6. Robotframework Debugger
  3. Robotframework-Ride (RIDE) - 不建议用

    1. 安装 wxPython
      1. pip install wxPython==4.0.7.post2 -i https://mirrors.aliyun.com/pypi/simple/
    2. 安装 robotframework-ride
      1. pip install robotframework-ride -i https://mirrors.aliyun.com/pypi/simple/

常见问题

使用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!

解决方法

  1. 编辑 site-packages\robotide\ui\images.py 和 site-packages\robotide\application\application.py
     增加一句wx.Locale(wx.LANGUAGE_ENGLISH):
images.py
class TreeImageList(wx.ImageList):
 
    def __init__(self):
        wx.ImageList.__init__(self*_SIZE)
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)  # 增加这一句
application.py
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'\]))

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章