Robot Framework--完整的接口测试用例

 

*** Settings ***
Library           Collections
Library           json
Library           requests
Library           RequestsLibrary
Library           HttpLibrary.HTTP

*** Variables ***
&{hosts}          dfc=http://dfc.xxxxx.com    crm=http://crm.xxxxx.com

*** Keywords ***
新建客户

登录xxxxx
    [Arguments]    ${apiurl}    ${jpushid}    ${loginName}    ${password}
    ${top}    Create Dictionary    Content-Type=application/x-www-form-urlencoded
    Create Session    api    ${apiurl}    ${top}
    ${data}    Create Dictionary    jpushid=${jpushid}    loginName=${loginName}    password=${password}
    ${req}    Post Request    api    /rest/account/login    data=${data}
    log    ${req.status_code}
    ${reqj}    To Json    ${req.content}
    log    ${reqj}
    ${reqjdata}    Get From Dictionary    ${reqj}    data
    ${TT}    Get From Dictionary    ${reqjdata}    token
    ${store}    Get From Dictionary    ${reqjdata}    store
    ${citycode}    Get From Dictionary    ${reqjdata}    cityCode
    set global variable    ${TT}
    Set Suite Variable    ${store}
    Set Suite Variable    ${citycode}
    ${form}    Create Dictionary    Content-Type=application/x-www-form-urlencoded
    Set Global Variable    ${form}
    ${json}    Create Dictionary    Content-Type=application/json    TT=${TT}
    Set Global Variable    ${json}
    #Set Suite Variable    $

MoGet
    [Arguments]    ${apiurl}    ${type}==json    ${params}==${EMPTY}
    #设置代理,用于调试
    ${proxy}    set variable    http://127.0.0.0:8888/
    #根据tag来获取host
    : FOR    ${tag}    IN    @{TEST TAGS}
    \    ${host}    Evaluate    ${hosts}.get($tag,"")
    \    Run Keyword If    "${host}"!=""    Exit For Loop
    log    ${host}
    #根据提交数据格式,设置Content-Type
    ${top}    Run Keyword If    "${type}"=="form"    Create Dictionary    Content-Type=application/x-www-form-urlencoded    TT=${TT}
    ...    ELSE    Create Dictionary    Content-Type=application/json    TT=${TT}
    Create Session    api    ${host}    ${top}
    ${resget}    Get Request    api    ${apiurl}    params=${params}
    Should Be Equal As Strings    ${resget.status_code}    200
    log    ${resget.status_code}
    ${resj}    To Json    ${resget.content}
    log    ${resj}

MoPost
    [Arguments]    ${apiurl}    ${type}==json    ${params}==${EMPTY}
    #设置代理,抓包
    ${proxy}    Set Variable    http://127.0.0.1:8888/
    #根据tag来获取host
    : FOR    ${tag}    IN    @{TEST TAGS}
    \    ${host}    Evaluate    ${hosts}.get($tag,"")
    \    Run Keyword If    "${host}"!=""    Exit For Loop
    log    ${host}
    #根据提交数据格式,设置Content-Type
    ${top}    Run Keyword If    "${type}"=="json"    Create Dictionary    Content-Type=application/json    TT=${TT}
    ...    ELSE IF    "${type}"=="form"    Create Dictionary    Content-Type=application/x-www-form-urlencoded    TT=${TT}
    Create Session    api    ${host}    ${top}
    ${respost}    Post Request    api    ${apiurl}    params=${params}
    Should Be Equal As Strings    ${respost.status_code}    200
    ${resj}    To Json    ${respost.content}
    log    ${resj}

 

原文地址:https://www.cnblogs.com/chengchengla1990/p/7044802.html

转载于:https://www.cnblogs.com/dydxw/p/10537177.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值