• 自动化测试 RobotFramework安装以及使用教程


    安装教程

    安装python,基于已安装好的python3.9版本教程

    大家百度安装一下就行啦

    安装Robot Framework

    Robot Framework是一个基于Python的,可扩展的关键字驱动的测试自动化框架,用于端到端验收测试和验收测试驱动开发(ATDD)。

    官网下载地址:https://github.com/robotframework/robotframework/releases/

    下载的是4.0.3版本的zip文件。解压缩zip文件后,在cmd命令行窗口解压出来的目录下

    在这里插入图片描述
    打开cmd命令窗口执行命令:python setup.py install

    安装wxPython

    wxPython是用于支持Python图形化界面的,安装它主要是用来运行RIDE的。

    官方下载地址:https://pypi.org/project/wxPython/
    Cmd命令执行:pip install wxPython

    安装robotframework-ride

    RIDE是一个可视化界面工具,专用于编写测试用例。

    官方下载地址:https://github.com/robotframework/RIDE/releases

    下载的是2.0b2.dev3版本的(1.7.4.2版本不支持,会闪退,升级就可以了。但是在cmd上输入pip install --update robotframework-ride进行升级,升级失败报错)。推荐使用在cmd上输入以下命令下载。

    命令:pip install -U https://github.com/robotframework/RIDE/archive/master.zip

    查看安装结果:pip list命令

    在这里插入图片描述

    安装完成后桌面没有exe执行文件?

    1、鼠标在空白桌面右击,新建,新建快捷方式,我命名为RIDE
    2、在弹出层填写D:\software\Python\python3.9.6\python.exe -c"from robotide import main; main()"
    注意:Python位置更改为自己的安装位置

    在这里插入图片描述

    在这里插入图片描述

    使用教程

    RF基本功能

    RF基本功能-设置区介绍
    项目 --》settings----》Document:添加用例说明
    
    suit setup:执行此测试套件的前置操作,如初始化数据等。
    
    suit TearDown:执行此测试套件结束后的操作,如恢复数据等。
    
    Setup:执行用例的前置操作
    
    Test TearDown:执行用例结束后的操作。
    
    Force Tags:用例标签。(选择运行的标志 run--》Only run tests with these tags)
    
    TimeOut:设置每一个测试案例的超时时间,超过这个时间就会失败,并停止案例运行
    
    Template:测试模板,可以指定某个关键字为这个测试套件下所有TestCase的模板,这样所有的TestCase就只需要设置这个关键字的传入参数即可。
    
    Arguments:传入参数(New User Keyword使用)
    
    Return Value:返回值(New User Keyword使用)
    
    RF基本功能-引用区
    Add Library:加载测试库,主要是你python\Lib\site-packages里的测试库
    
    Add Resource:加载资源,主要是你工程相关的资源文件
    
    Add Variable:加载变量文件
    
    RF基本功能-参数区
    Add Scalar:定义变量
    
    Add List:定义列表型变量
    
    Add Dict:定义字典
    
    RF基本功能-数据区
    
    Add Metadata:元数据,作用是在report和log里显示定义好的内容,格式和document一样。(report-点击用例集-测试用例,可以看到,相当于对用例组的描述)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    创建项目 new project ; Directory类型的

    在这里插入图片描述

    在项目中创建模块(它是测试用例的载体) New Directory

    在这里插入图片描述
    在这里插入图片描述

    创建测试套件(New Suite)

    注意:选择file类型

    在这里插入图片描述
    在这里插入图片描述

    创建测试用例(New Test Case)

    在这里插入图片描述
    在这里插入图片描述

    创建资源文件New Resource 自定义关键字的载体

    注意:txt文件类型

    在这里插入图片描述

    在这里插入图片描述

    创建自定义关键字(new user keyword)

    在这里插入图片描述
    在这里插入图片描述

    RF基本架构

    在这里插入图片描述

    RobotFramework常用类库

    标准库:不需要安装,直接用,RF自带

    Buitini(测试库) 
    Collections(集合库) 
    Date Time(时间库) 
    ScreenShot(截屏库)
    
    • 1
    • 2
    • 3
    • 4

    扩展库:需要通过pip安装库

    web自动化测试:SeleniumLibrary,Selenium2Library,Selenium2Library for java 
    接口自动化测试:RequestsLibrary 
    APP自动化测试:AppiumLibrary
    
    • 1
    • 2
    • 3

    安装方式:

    pip install robotframework-seleniumlibrary==3.0.0 
    pip install robotframework-requests 
    pip install robotframework-appiumlibrary
    
    • 1
    • 2
    • 3

    RobotFramework常用关键字

    快捷键的掌握

    1. 搜索:F5
    2. 自动补全:Ctrl+Shift+空格

    关键字使用

    在这里插入图片描述

    将一下信息复制到Text Edit内容当中

    *** Test Cases ***
    测试用例01
        Log    1.自动化测试
        Comment    2.设置变量
        ${a}    Set Variable    88
        Log    ${a}
        Comment    3.获取系统时间
        ${times}    Get Time
        Log    ${times}
        Comment    4.睡眠时间,强制等待
        Sleep    5
        Comment    5.字符串的拼接
        ${str}    Catenate    aaa    bbb    ccc    ddd
        Log    ${str}
        Comment    6.创建列表
        ${list1}    Create List    1    2    3
        Log    ${list1}
        @{list1}    Create List    4    5    6
        Log Many    @{list1}
        Comment    7.创建字典
        ${dic}    Create Dictionary    name=一个小浪吴呀    age=88
        Log    ${dic}
        Comment    8.执行内置方法
        ${random_number}    Evaluate    random.randint(1,101)    modules=random
        Log    ${random_number}
        ${timess}    Evaluate    time.time()    modules=time
        Log    ${timess}
        Comment    9.执行python中if方法
        ${age}    Set Variable    20
        Run Keyword If    ${age}>18    Log    成年了,可以上网
        ...    ELSE IF    14<${age}<18    Log    未成年,不能上网
        ...    ELSE    Log    你还小,不能变坏哦
        ${age}    Set Variable    15
        Run Keyword If    ${age}>18    Log    成年了,可以上网
        ...    ELSE IF    14<${age}<18    Log    未成年,不能上网
        ...    ELSE    Log    你还小,不能变坏哦
        Comment    10.执行python中for循环
        FOR    ${aa}    IN    1    2    3    4
            Log    ${aa}
        END
        FOR    ${bb}    IN    ${list1}
            Log    ${bb}
        END
        FOR    ${cc}    IN RANGE    1    10
            Run Keyword If    ${cc}==6    Exit For Loop
            Log    ${cc}
        END
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    在这里插入图片描述

    运行查看效果

    在这里插入图片描述

    以上就完成啦!

  • 相关阅读:
    vue中使用window.open打开assets文件夹下的pdf文件
    ADS1292检测原理及其驱动
    python 知识点汇总
    测试一下禁言
    揭秘AI 原生应用技术栈
    【LeetCode】经典的环形链表
    工业 web4.0 的 UI 卓越非凡
    (十三)强缓存和协商缓存的区别
    课后题:冒泡法排序
    Python批量获取高校基本信息
  • 原文地址:https://blog.csdn.net/A_yonga/article/details/126248202