美文网首页软件测试Python接口测试程序员
robot framework学习笔记二 : 单接口测试

robot framework学习笔记二 : 单接口测试

作者: wenshuang_he | 来源:发表于2020-07-27 19:19 被阅读0次

    1.进入RIDE可视化界面。File-->New Project,新建项目

    新建项目

    2.层级管理。


    接口测试层级管理

    3.新建测试包。选中项目,右键点击New Suite


    新建测试包
    4.新建测试页。右键点击New Suite
    测试页

    5.新建测试用例。


    测试用例
    6.pip命令安装python第三方依赖。

    allure-pytest 2.6.1
    allure-python-commons 2.6.1
    aniso8601 8.0.0
    Appium-Python-Client 0.26
    APScheduler 3.5.1
    atomicwrites 1.3.0
    attrs 19.1.0
    bcrypt 3.1.7
    blinker 1.4
    certifi 2019.3.9
    cffi 1.14.0
    chardet 3.0.4
    click 7.1.2
    colorama 0.4.1
    cryptography 2.9.2
    decorator 4.4.2
    docutils 0.16
    enum34 1.1.6
    et-xmlfile 1.0.1
    Flask 0.11
    Flask-APScheduler 1.8.0
    Flask-Login 0.2.11
    Flask-Mail 0.9.0
    Flask-RESTful 0.3.6
    Flask-Script 2.0.6
    Flask-SSLify 0.1.5
    idna 2.8
    importlib-metadata 0.17
    itsdangerous 1.1.0
    jdcal 1.4.1
    Jinja2 2.8
    kitchen 1.2.6
    lxml 4.3.2
    MarkupSafe 1.1.1
    more-itertools 6.0.0
    namedlist 1.7
    numpy 1.19.0
    openpyxl 3.0.4
    paramiko 2.7.1
    Pillow 7.1.2
    pip 20.1.1
    pluggy 0.9.0
    py 1.8.0
    pycparser 2.20
    Pygments 2.6.1
    PyMySQL 0.9.3
    PyNaCl 1.4.0
    Pypubsub 4.0.3
    pytest 4.3.1
    python-dateutil 2.7.3
    pytz 2020.1
    pywin32 228
    PyYAML 5.3.1
    requests 2.21.0
    robotframework 3.0.3
    robotframework-appiumlibrary 1.4.6
    robotframework-databaselibrary 1.0.1
    robotframework-requests 0.4.7
    robotframework-ride 1.7.4.1
    robotframework-seleniumlibrary 3.1.1
    robotframework-sshlibrary 3.1.1
    selenium 3.141.0
    setuptools 39.0.1
    six 1.12.0
    tzlocal 2.1
    urllib3 1.24.1
    Werkzeug 0.14.1
    wxPython 4.0.7.post2
    xlrd 1.2.0
    zipp 0.5.1

    7.RIDE界面导入依赖包。


    导入依赖包1
    导入依赖包2

    8.1新建post请求


    新建请求 post请求
    *** Settings ***
    Library           RequestsLibrary
    Library           Collections
    Resource          ../login/Keyword.txt
    
    *** Variables ***
    ${new_product_data}    {"appInfoIds":[18],"appPkName":"ws测试","appPkDesc":"测试","isVisible":0,"isQualified":true}
    ${new_product_path}    /consoleapi/console/app-pk
    
    *** Test Cases ***
    Class_01
        ${token}    Get_token    管理员
        Create Session    even    ${qa}
        ${headers}    Create Dictionary    Content-Type=application/json; charset=UTF-8    token=${token}
        ${data}    To Json    ${new_product_data}
        ${r}    Post Request    event    ${new_product_path}    ${data}    headers=${headers}
        Should Be Equal As Strings    ${r.status_code}    200
        log    ${r.json()}
        ${dict}    Set variable    ${r.json()}
        log    --------断言结果-------
        ${msg}    Get From Dictionary    ${dict}    message
        Should Be Equal    ${msg}    Success
        ${sta}    Get From Dictionary    ${dict}    code
        ${status}    Evaluate    int(200)
        Should Be Equal    ${sta}    ${status}
    
    

    8.2新建get请求


    get请求
    *** Settings ***
    Library           RequestsLibrary
    Library           Collections
    Resource          ../login/Keyword.txt
    Resource          poruct_keys.txt
    
    *** Variables ***
    ${find_product_data}    {"appPackageName":"ws测试产品","pageSize":6,"pageNum":1}
    ${find_product_path}    /consoleapi/console/app-pk
    
    *** Test Cases ***
    Class_01
        ${token}    Get_token    锱云管理员
        Create Session    even    ${qa}
        ${headers}    Create Dictionary    Content-Type=application/json; charset=UTF-8    token=${token}
        ${data}    To Json    ${find_product_data}
        ${r}    Get Request    event    ${find_product_path}    headers=${headers}    params=${data}
        Should Be Equal As Strings    ${r.status_code}    200
        log    ${r.json()}
        ${dict}    Set variable    ${r.json()}
        log    --------断言结果-------
        ${msg}    Get From Dictionary    ${dict}    message
        Should Be Equal    ${msg}    Success
        ${rp_data}    Get From Dictionary    ${dict}    data
        ${tot}    Get From Dictionary    ${rp_data}    total
        ${totals}    Evaluate    int(1)
        Should Be Equal    ${tot}    ${totals}
        ${sta}    Get From Dictionary    ${dict}    code
        ${status}    Evaluate    int(200)
        Should Be Equal    ${sta}    ${status}
    
    

    9.新建关键字。测试包右键-->New Resource


    新建关键字

    10.新建自定义变量。测试页-->Add Scalar


    自定义变量

    11.导入自定义关键字。


    自定义关键字导入

    12.导入的自定义关键字.txt文件,文件中的自定义变量也可以使用


    自定义关键字
    1 2

    相关文章

      网友评论

        本文标题:robot framework学习笔记二 : 单接口测试

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