robot framework接口测试中碰到的问题,get request不能获取参数(已解决)

1、需要做接口测试,想到熟悉的工具是 robot framework ,就决定用它,开始觉得还不错。测试了几个都没有问题

Library           requests
Library           json
Library           RequestsLibrary
Library           Collections

*** Variables ***
${token}          ${EMPTY}

*** Test Cases ***
登录户动获取access_token
    ${dict}    create dictionary    Content-Type=application/x-www-form-urlencoded    verity=false
    create session    api    https://test.******.net/    ${dict}
    ${commdata}    create dictionary    type=1    account=13760479324    password=zj073935601    registration_id=1
    ${addr}    post request    api    /v1.1/user/login    data=${commdata}    headers=${dict}
    comment    should be equal as strings    ${addr.status_code}    200
    ${responsedata}    set variable    ${addr.json()}
    ${code}    get from dictionary    ${responsedata}    code
    comment    should be equal as strings    ${code}    1
    ${data}    get from dictionary    ${responsedata}    data
    ${access_token}    get from dictionary    ${data}    access_token
    ${refresh_token}    get from dictionary    ${data}    refresh_token
    set global variable    ${token}    ${access_token}
    delete all sessions

这个是post request ,获取token变量后保存,后续使用。

获取商户分类
    ${dict}    create dictionary    Content-Type=application/x-www-form-urlencoded    token=${token}    tamp=1493887380
    create session    api    https://test.******.net/    ${dict}
    ${addr}    get request    api    /v1.1/business/get_categories    headers=${dict}
    comment    should be equal as strings    ${addr.status_code}    200
    log    ${addr.content}
    delete all sessions

这个是get request 的接口测试,都木有问题。

然后问题来了,有一个get接口,参数有点多,四个

获取外卖商家列表
    ${dict}    create dictionary    longitude=114.137425    latitude=22.581316    tamp=1493887380    token=${token}
    create session    api    https://test.******.net/    ${dict}
    ${addr}    get request    api    /v1.1/waimai/find_shop    headers=${dict}
    comment    should be equal as strings    ${addr.status_code}    200
    log    ${addr.content}
    delete all sessions

运行结果:

Starting test: hudongTest.Interface test.Version1.1.获取外卖商家列表
20170802 10:16:09.271 :  INFO : ${dict} = {u'longitude': u'114.137425', u'latitude': u'22.581316', u'tamp': u'1493887380', u'token': u'5559cb28-194c-4b58-a420-a14057850ab4'}
20170802 10:16:09.272 :  INFO : Creating Session using : alias=api, url=https://********/, headers={u'longitude': u'114.137425', u'latitude': u'22.581316', u'tamp': u'1493887380', u'token': u'5559cb28-194c-4b58-a420-a14057850ab4'},                     cookies=None, auth=None, timeout=None, proxies=None, verify=False,                     debug=0
20170802 10:16:09.343 :  INFO : Get Request using : alias=api, uri=/v1.1/waimai/find_shop, headers={u'longitude': u'114.137425', u'latitude': u'22.581316', u'tamp': u'1493887380', u'token': u'5559cb28-194c-4b58-a420-a14057850ab4'} json=None
20170802 10:16:09.344 :  INFO : ${addr} = <Response [200]>
20170802 10:16:09.345 :  INFO : {"code":1102}
20170802 10:16:09.346 :  INFO : Delete All Sessions
Ending test:   hudongTest.Interface test.Version1.1.获取外卖商家列表

错误码意思是:找不到经纬度,但是经纬度的参数已经传进来了。参数放到url的后面也不行,报同样的错误:${addr}    get request    api    /v1.1/business/?longitude=114.137425?latitude=22.581316    ${dict}

接口用visual studio测试又是可以正常返回的。网上也找不到解决办法,准备弃用robot framework。

问题先记录下,后续找到解决方法再更新。

 

解决方法,原来参数要放到params里面,才明白看api的重要性,看不懂,硬着头皮也要看下去啊

获取大众商户列表
    ${dict}    create dictionary    token=${token}
    ${param}    create dictionary    tamp=1493887380    city=深圳    region=福田区    longitude=114.137425    latitude=22.581316
    create session    api    https://test.*********/    ${dict}
    ${addr}    get request    api    /v1.1/business/    headers=${dict}    params=${param}
    comment    should be equal as strings    ${addr.status_code}    200
    log    ${addr.content}
    delete all sessions

posted on 2017-08-02 10:24  张&娟  阅读(576)  评论(0编辑  收藏  举报

导航