美文网首页
Visual Studio Code+Robot framewo

Visual Studio Code+Robot framewo

作者: lynne_琳琳酱 | 来源:发表于2021-04-19 20:38 被阅读0次

Robotframework Python3 RIDE 在MAC系统中不太稳定,当文件太大时,经常出现卡死的情况

为了解决这一问题,推荐使用Visual Studio Code来编写自动化测试用例,使用RIDE来勾选需要执行的脚本(比如只跑135这种,vscode执行只能通过命令相对来说没有可视化的RIDE友好)

  1. 下载Visual Studio Code

  2. 打开浏览器访问https://code.visualstudio.com

  3. 点击download for Mac / download for Windows,下面具体举例是Mac版本的安装,Windows的配置和Mac一样


    vscode下载页面
  4. 安装解压工具The Unarchiver
    在Apple Store中搜索并下载The Unarchiver


    mac 解压工具
  5. 在下载文件夹中双击VSCode-darwin-stable.zip


    解压vscode
  1. 双击打开Visual Studio Code


    双击打开vscode

    Visual Studio Code汉化
    a) 点击积木图标,搜索框输入Chinese (Simplified) Language Pack for Visual Studio Code,点击install


    安装插件

b) Command + Q 重新启动Visual Studio Code

  1. 安装python插件
    a) 点击积木图标,搜索python点击install

b) 配置参数,点击python右下角的小齿轮》点击拓展设置,输入框搜索python.pythonPath


vscode python环境配置

Mac:打开终端,执行命令:which python3
Windows:打开cmd,执行命令:which python3
将结果粘贴到python.pythonPath的输入框中

  1. 安装Robot Framework Intellisense
    a) 点击积木图标,搜索Robot Framework Intellisens,点击install


    Robot Framework Intellisense

    b) 参数配置:点击Robot Framework Intellisens右下角的小齿轮,点击拓展设置,点击settings.json中编辑

粘贴配置:

{

    "files.associations": [

        "*.txt": "robot",

        "*.robot": "robot",

        "*.resource": "robot"

    ],

    "rfLanguageServer.includePaths": [

        "**/*.robot",

        "**/*.py",

        "**/*.resource"

    ],

    "rfExtension.singleKeywordFormat": true,

    "rfLanguageServer.logLevel": "info",

    "rfLanguageServer.libraries": [

        "BuiltIn-3.0.4",

        "SeleniumLibrary-3.2.0",

        "String-3.0.4",

        "XML-3.0.4",

        "Telnet-3.0.4",

        "Dialogs-3.0.4",

        "Process-3.0.4",

        "DateTime-3.0.4",

        "Screenshot-3.0.4",

        "Collections-3.0.4",

        "OperatingSystem-3.0.4",

    ],

    "terminal.integrated.shell.osx": "/bin/zsh",

    "search.actionsPosition": "right",

    "rfLanguageServer.trace.server": "verbose",

    "debug.openExplorerOnEnd": true,

    "explorer.confirmDelete": true,

    "diffEditor.renderSideBySide": true,

    "editor.largeFileOptimizations": false,

    "diffEditor.ignoreTrimWhitespace": false,

    "editor.renderWhitespace": "all",

    "editor.renderControlCharacters": true,

    "python.pythonPath": "/usr/local/bin/python3",

    "workbench.iconTheme": "vscode-icons",

    "editor.minimap.enabled": false,

    "breadcrumbs.enabled": true,

    "editor.fontSize": 15

}
  1. 安装Robotframework Debugger(调试用)
    在搜索框中搜索Robotframework Debugger 点击install

参数配置

a) 打开一个robot framework文件夹

b) 点击顶部运行》启动调试〉选择robot framework Debugger


Robotframework Debugger

粘贴一下配置

{

    // 使用 IntelliSense 了解相关属性。

    // 悬停以查看现有属性的描述。

    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",

    "configurations": [

        {

            "type": "robot",

            "request": "launch",

            "name": "Robotframework Debugger",

            "program": "${workspaceFolder}/${relativeFile}",

            "WorkingDirectory": "${workspaceFolder}/${relativeFile}",

            "stopOnEntry": true,

            "arguments": "",

            "libraries": ["${workspaceFolder}\\Libraries"],

            "variables": [{

                "Name": "RobotVariable",

                "Value": "data"

            }],

            "PythonPath": "/usr/local/bin/python3"

        }

    ]

}

11.其他好用的插件推荐
indent-rainbow(缩进的彩虹)
Beautify(将html和json传转化成标准缩进样式)
Rainbow Brackets(括号的彩虹)

12.启动脚本

在终端中输入需要执行的命令

执行一个用例
robot --test 测试登录 ./业务接口.robot

robot --t 测试登录 ./业务接口.robot

按用例文件执行
robot ./业务接口.robot

执行目录下所有用例
robot /Users/lynne/自动化/xxx/bbb/渠道接口

按执行tag执行用例
robot --include smoke test_directory
robot --include smoke path/test_file.robot

剔除用例执行
robot --exclude smoke test_directory
或者
robot --exclude smoke path/test_file.robot

乱序跑
可以有效避免testcase之间的依赖,保持独立性是testcase持续有效的关键
robot --randomize tests path/test_file.robot

变量参数
可以更新多个变量,达到每次跑不一样内容的目的,例如可以通过命令切换环境,切换数据等
robot --variable ENV:uat --variable TEST_DATA:uat regression.robot

相关文章

网友评论

      本文标题:Visual Studio Code+Robot framewo

      本文链接:https://www.haomeiwen.com/subject/xqhvlltx.html