如何通过Robot框架使用PUT方法来REST API [英] How to rest API with PUT method via robot framework
本文介绍了如何通过Robot框架使用PUT方法来REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个测试套件
Library RequestsLibrary
Library JSONLibrary
Library OperatingSystem
*** Variable ***
${base_url} https://api.sportpartnerxxx.vn/v1
${identity_URL} https://identity.sportpartnerxxx.vn
${Profile} https://api.sportpartnerxxx.vn/v1/profile
*** Test Cases ***
Login
${body}= Create Dictionary client_id=sportpartner-mobile-app client_secret=ifd-sportpartner-secret-2021-mobile-app grant_type=password username=nnbbtd@gmail.com password=123456
${header}= create dictionary content_type=application/x-www-form-urlencoded
${response}= Post ${identity_URL}/connect/token headers=${header} data=${body}
Set Suite Variable ${token} Bearer ${response.json()["access_token"]}
Set Suite Variable ${refresh_token} ${response.json()["refresh_token"]}
Status Should Be 200
Log To Console ${token}
UpdateLanguageStatus
${body}= Create Dictionary languageId=20
${header}= create dictionary Content-Type=application/json Authorization=${token}
${response}= PUT ${Profile}/me/settings data=${body} headers=${header}
Log To Console ${response.status_code}
Log To Console ${response.content}
返回Login Pass,UpdateLanguageStatus失败。UpdateLanguageStatus返回400。我不知道原因。另一方面,我在邮递员上运行这个测试用例,它工作得很好 enter image description here。有人帮我吗?
推荐答案
在发送请求之前,${Body}的词典内容似乎没有序列化为JSON。 输出如下所示:
{'languageId': '20'}
它应该是这样的:
{"languageId": "20"}
您可以在发送前添加以下内容:
${body} Evaluate json.dumps(${body}) json
附加说明-如果languageID为int,则您可能需要更改已有的行,以便20位于${}范围内,例如
${body}= Create Dictionary languageId=${20}
这篇关于如何通过Robot框架使用PUT方法来REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文