Robot Framework ride 接口测试

 
 #requestLibrary相关使用
    #创建一个会话使用别名local
    create session    local    http://localhost:8000
    #向别名local的会话发起一个请求,请i去uri为users/1
    ${addr}    get request    local    users/1
    log    ${addr}
    #判断请求响应是否为200,200就继续执行用例否则失败停止,status_code获取返回状态码
    should be equal as strings    ${addr.status_code}    200
    #输出addr对象的内容
    log    ${addr.content}
    #使用 to json将string转换为json串, 相应数据
    ${responsedata}    to json    ${addr.content}
    log    ${responsedata}
    #使用dictionary方法获取对应的值, 需要import Collections库
    ${keys}    get dictionary keys    ${responsedata}
    ${items}    get dictionary items    ${responsedata}
    ${values}    get dictionary values    ${responsedata}
    ${str}    get from dictionary    ${responsedata}    1    #通过键名获取对应的value
    ${addr}    get Request    local    users/5    #访问一个不存在的uri应该返回404
    should be equal as strings    ${addr.status_code}    404
    log    ${addr.content}
    ${res2}    To json    ${addr.content}
    ${keys}    get dictionary keys    ${res2}
    ${items}    get dictionary keys    ${res2}
    ${values}    get dictionary values    ${res2}
    ${str}    get from dictionary    ${res2}    message
    Delete all sessions    #删除当前所有的会话


    #接口返回xml格式内容处理
    #返回的xml按json的方式是处理
    create session    local    http://localhost:8000
    ${addr}    get request    local    hello/qitao
    should be equal as strings    ${addr.status_code}    200
    log    ${addr.content}
    ${res}    to json    ${addr.content}
    log    ${res}
    ${keys}    get dictionary keys    ${res}
    ${items}    get dictionary items    ${res}
    ${values}    get dictionary Values    ${res}
    ${str}    get from dictionary    ${res}    hello
    #处理为xml 需要导入XML模块
    ${dic}    create dictionary    accept=application/xml    #创建字典作为访问的header内容,即 accept:aaplication/xml
    ${addr2}    get request    local    hello/qitao    ${dic}    #添加header参数请求
    should be equal as strings    ${addr2.status_code}    200
    log    ${addr2.content}
    ${res2}    set variable    ${addr2.content}
    ${body}    get element text    ${res2}    hello
    ${hello}    get element    ${res2}    hello
    log    ${hello.text}
    ${res3}    add element    ${res2}    <new id='10'>test</new>    #添加元素
    ${new}    XML.get element attribute    ${res3}    id    new    #使用xml库中的get element attribute
    log    ${new}
    ${a}    element to string    ${res3}
    delete all sessions

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值