Robot Framework环境搭建
安装 Java SDK 8
安装 Maven (仅要独立运行单元测试或配置流水线用的测试Runner时需要)
安装 Git
安装 GitLab-Runner(仅要配置流水线用的Runner时需要)
登记成为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
建议下载3.8.x版本的安装包。
下载后双击文件安装,默认安装路径为:C:\Users\Administrator\AppData\Local\Programs\Python\Python38(可自行更改安装路径)
python安装完成后,必须配置windows环境变量,在Path变量中加入python的两个路径:
Windows => System => Advanced System Settings => Advanced tab => Environment Variables => Path => Edit => NewC:\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,显示如下:
C:\Users\AIT>pip list
Package Version
------------------------------- -----------
Faker 9.7.1
pip 1.2.1
Pygments 2.9.0
Pypubsub 4.0.3
pywin32 301
requests 2.26.0
robotframework 4.1
robotframework-appiumlibrary 1.6.2
robotframework-excel 1.0.0b4
robotframework-faker 5.0.0
robotframework-pythonlibcore 3.0.0
robotframework-requests 0.9.1
robotframework-ride 1.7.4.2 #
robotframework-selenium2library 3.0.0
robotframework-seleniumlibrary 5.1.3
robotframeworklexer 1.1
selenium 3.141.0
setuptools 56.0.0
six 1.16.0
urllib3 1.26.6
wheel 0.37.0
wxPython 4.0.7.post2 #
xlrd 1.2.0 # pip install xlrd==1.2.0
xlutils 2.0.0
xlwt 1.3.0
安装 robotframework
-i 表示用镜像地址安装,这里使用阿里云的python库镜像地址
pip install robotframework -i https://mirrors.aliyun.com/pypi/simple/
安装 IDE
选择一个 IDE 做robot framework 文件(.robot)的编辑/运行器,不建议用 RIDE:
1. PyCharm / IDEA
a. 安装插件:
i. IntelliBot
ii. Robot Framework Language Server
iii. Robot Framework Support
iv. Run Robot Framework TestCase
v. YAML
vi. Git
2. Visual Studio Code
a. 安装插件:
i. Python
ii. Robot Framework Intellisense
iii. Robot Framework Language Server
iv. 2.
a.
iv. robotframework
v. robotcode(仅支持python3.8+)
3. Robotframework-Ride (RIDE) - 不建议用
a. 安装 wxPython
i. pip install wxPython==4.0.7.post2 -i https://mirrors.aliyun.com/pypi/simple/
b. 安装 robotframework-ride
i. pip install robotframework-ride -i https://mirrors.aliyun.com/pypi/simple/
安装 SeleniumLibrary
pip install robotframework-seleniumLibrary -i https://mirrors.aliyun.com/pypi/simple/
安装 robotframework-requests
pip install robotframework-requests -i https://mirrors.aliyun.com/pypi/simple/
安装浏览器驱动
下载driver驱动
1、chromedriver(谷歌)下载地址(注意需要与谷歌浏览器版本对应):http://npm.taobao.org/mirrors/chromedriver
chromedriver 下载完成解压后,将chromedriver.exe文件放到python安装目录(C:\Users\Administrator\AppData\Local\Programs\Python\Python38)。
对应的谷歌浏览器也是如此。
注意:Drvier驱动受到浏览器版本影响,故下载驱动后,如果RF还是启动不了浏览器,建议下载多几个版本试试。
常见问题
使用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'\]))
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· 【全网最全教程】使用最强DeepSeekR1+联网的火山引擎,没有生成长度限制,DeepSeek本体