zoukankan      html  css  js  c++  java
  • rf-demos (request)

    *** Settings ***
    Library           RequestsLibrary
    Library           Collections
    Library           XML
    
    *** Test Cases ***
    case1
        Create Session    api    http://localhost:8000
        ${addr}    Get Request    api    users/1
        Should Be Equal As Strings    ${addr.status_code}    200
        Log    ${addr.content}
        ${responsedata}    To Json    ${addr.content}
        ${keys}    Get Dictionary Keys    ${responsedata}
        ${items}    Get Dictionary Items    ${responsedata}
        ${values}    Get Dictionary Values    ${responsedata}
        ${str}    Get From Dictionary    ${responsedata}    1
        ${addr}    Get Request    api    users/5
        Should Be Equal As Strings    ${addr.status_code}    404
        Log    ${addr.content}
        ${responsedata}    To Json    ${addr.content}
        ${keys}    Get Dictionary Keys    ${responsedata}
        ${items}    Get Dictionary Items    ${responsedata}
        ${values}    Get Dictionary Values    ${responsedata}
        ${str}    Get From Dictionary    ${responsedata}    message
        Delete All Sessions
    
    case2
        Create Session    api    http://localhost:8000
        ${addr}    Get Request    api    hello/qitao
        Comment    Should Be Equal As Strings    ${addr.status_code}    200
        Log    ${addr.content}
        ${responsedata}    To Json    ${addr.content}
        ${keys}    Get Dictionary Keys    ${responsedata}
        ${items}    Get Dictionary Items    ${responsedata}
        ${values}    Get Dictionary Values    ${responsedata}
        ${str}    Get From Dictionary    ${responsedata}    hello
        #xml方式
        ${dict}    Create Dictionary    accept=application/xml
        ${addr}    Get Request    api    hello/qitao    ${dict}
        Comment    Should Be Equal As Strings    ${addr.status_code}    200
        Log    ${addr.content}
        ${responsedata}    Set Variable    ${addr.content}
        ${body}    Get Element Text    ${responsedata}    hello
        ${hello}    Get Element    ${responsedata}    hello
        Log    ${hello.text}
        ${responsedata}    Add Element    ${responsedata}    <new id="3">test</new>
        ${new}    Get Element Attribute    ${responsedata}    id    new
        Log    ${new}
        ${a}    Element To String    ${responsedata}
        Delete All Sessions
    
    case3
        #用户密码
        ${auth}    Create List    ok    python
        Create Session    api    http://localhost:8000            ${auth}
        ${addr}    Get Request    api    401
        Comment    Should Be Equal As Strings    ${addr.status_code}    200
        Log    ${addr.content}
        ${responsedata}    To Json    ${addr.content}
        ${keys}    Get Dictionary Keys    ${responsedata}
        ${items}    Get Dictionary Items    ${responsedata}
        ${values}    Get Dictionary Values    ${responsedata}
        ${str}    Get From Dictionary    ${responsedata}    pass
        Delete All Sessions
    
    case4
        ${dict}    Create Dictionary    Content-Type=application/x-www-form-urlencoded
        Create Session    api    http://localhost:8000    ${dict}
        ${data}    Create Dictionary    username=qitao    password=qt
        ${addr}    Post Request    api    post    data=${data}
        Comment    Should Be Equal As Strings    ${addr.status_code}    200
        Log    ${addr.content}
        Log    ${addr.json()}
        ${responsedata}    To Json    ${addr.content}
        ${keys}    Get Dictionary Keys    ${responsedata}
        ${items}    Get Dictionary Items    ${responsedata}
        ${values}    Get Dictionary Values    ${responsedata}
        ${str}    Get From Dictionary    ${responsedata}    username
        Delete All Sessions
    

    Post请求示例:

    Post Requests
        [Tags]  post
        Create Session  httpbin  http://httpbin.org
        &{data}=  Create Dictionary  name=bulkan  surname=evcimen
        &{headers}=  Create Dictionary  Content-Type=application/x-www-form-urlencoded
        ${resp}=  Post Request  httpbin  /post  data=${data}  headers=${headers}
        Dictionary Should Contain Value  ${resp.json()['form']}  bulkan
        Dictionary Should Contain Value  ${resp.json()['form']}  evcimen
    
    

      

  • 相关阅读:
    Spring+Spring MVC+Hibernate框架搭建实例
    数据结构:串
    为什么java中用枚举实现单例模式会更好
    验证码原理分析及实现
    Servlet监听器——实现在线登录人数统计小例子
    IntelliJ IDEA 远程调试 Tomcat 的方法
    SQL注入的一些技巧分享
    Java中String与byte[]的转换
    JavaSE基础:集合类
    二叉树的非递归遍历
  • 原文地址:https://www.cnblogs.com/saryli/p/7264047.html
Copyright © 2011-2022 走看看