- 从官网下载python安装包,最新版3.9.6:?https://www.python.org/downloads/
- 命令行安装python library:
- Robot framework: pip install robotframework
- Selenium:?pip install robotframework-selenium2library
- 下载pycharm 社区版并安装:https://www.jetbrains.com/pycharm/download/?gclid=CjwKCAjwgb6IBhAREiwAgMYKRh0NNruOJ5iMQaLEQebUscIy-thu7Wq5szA_RJFMUEpqKPfrz2wFuxoCldYQAvD_BwE#section=windows
-
Pycharm File->Settings->Plugins 搜索并安装插件
- IntelliBot
- Run Robot Framework Testcase
- RunRobot Framework
- 下载对应浏览器的driver,这里下载的chrome的,下载地址:?https://sites.google.com/chromium.org/driver/
- 在Pycharm中打开测试project,在root路径下创建测试文件,命名为:baidu_search.robot
-
*** Settings ***
Documentation Simple examle using SeleniumLibrary
Library SeleniumLibrary
*** Variables ***
${URL} http://www.baidu.com
${BROWSER} Chrome
*** Keywords ***
Baidu Search
[Arguments] ${search_key}
Input text id:kw ${search_key}
click button id:su
Evaluate time.sleep(2) time
${title} Get title
[Return] ${title}
*** Test Case ***
case1
Open Browser ${URL} ${BROWSER}
${title} Baidu Search robot framework
Should contain ${title} robot framework_百度搜索
close Browser
case2
Open Browser ${URL} ${BROWSER}
${title} Baidu Search selenium
Should contain ${title} selenium_百度搜索
close Browser
- 在pycharm中添加python interceptor
- File->setting->project->python interpreter
- Run->Add configration->add new running configuration(指向配置好的interceptor和运行路径
- 点击绿色右向按钮,启动运行
P.S.
运行方式2:
- 在执行文件目录下输入“cmd”打开命令行工具
- 以命令行方式执行Robot脚本:robot baidu_search.robot
运行方式3:
- 在Pycharm中配置External tool,以在Pycharm中运行Robot脚本
- Go to File > Settings > External Tools
- Click '+' button under 'External Tools' panel
- In the 'Create Tool' dialog, enter the below values:
- Name: Robot
- Program: [Path of Pybot.bat e.g.C:\Python27\Scripts\Pybot.bat]
- Parameters: $FileName$
- Working Directory: $FileDir$
- 在Pycharm中点击Tool->ExternalTool,选择“Robot” 执行脚本
参考内容:
- https://www.cnblogs.com/superhin/p/12747548.html
- https://stackoverflow.com/questions/27256070/running-tests-on-pycharm-using-robot-framework
- http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#executing-robot-framework
- https://stackoverflow.com/questions/36501804/execute-robot-framework-file-from-python-script
|