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
    
    

      

  • 相关阅读:
    云架构和openstack的思考
    关于mysql中[Err] 1451 -Cannot delete or update a parent row: a foreign key constraint fails
    解决CentOS7-python-pip安装失败
    python 中使用 urllib2 伪造 http 报头的2个方法
    python urllib2 对 http 的 get,put,post,delete
    dpdk EAL: Error reading from file descriptor 23: Input/output error
    ovs-vsctl 命令详解
    openstack 虚机迁移 Unacceptable CPU info: CPU doesn't have compatibility
    ip route 命令详解
    influxDB 基本操作
  • 原文地址:https://www.cnblogs.com/saryli/p/7264047.html
Copyright © 2011-2022 走看看