[英]RobotFramework Post Request with attributes on body
您好,我正在尝试用身体测试 api:
{
"customerAttributes": [
{
"customerId": 0,
"id": 0,
"name": "string",
"value": "string"
}
],
"emailAddress": "string",
"firstName": "string",
"id": 0,
"lastName": "string",
"registered": true
}
由于它有不止一个 object 我不知道如何使它工作。 这就是我目前所拥有的:
*** Settings ***
Library RequestsLibrary
*** Variables ***
${Base_URL}= http://localhost:8082 /api/v1
*** Test Cases ***
TC_004_POST_Customer
Create session customer ${Base_URL}
${body}= create dictionary customerId=100 id=100 name=test value=0 emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=true
${header}= create dictionary Content-Type=application/json
${response}= Post On Session customer /customer data=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
有人可以帮我吗? 谢谢!
你应该能够做这样的事情:
${inner}= Create Dictionary customerId=100 id=100 name=test value=0
${array}= Create List ${inner}
${body}= Create Dictionary customerAttributes=${array} emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=True
您必须POST on Session
中使用json
参数,如下所示:
TC_004_POST_Customer
Create session customer ${Base_URL}
${body}= create dictionary customerId=100 id=100 name=test value=0 emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=true
${header}= create dictionary Content-Type=application/json
${response}= Post On Session customer /customer json=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.