问题描述
我已经查看了RESTinstance和RequestsLibrary,但是找不到将JSON作为请求的一部分发送到服务器的方法。感谢您的任何建议。
解决方法
使用RequestLibrary中的Get Request关键字可以像下面这样完成。
JSON通常是Robot Framework中的dictionary。在下面的示例中,&{JSON}
变量等效于以下JSON:
{
"name": "peter","other_attribute": "value"
}
使用其他关键字,您也可以创建嵌套结构。
示例:
*** Settings ***
Library RequestsLibrary
*** Variables ***
&{JSON} name=peter other_attribute=value
*** Test Cases ***
Test
Create session alias=my_session url=http://127.0.0.1:5000
${response}= Get Request alias=my_session uri=api/your_api_endpoint json=${JSON}
Log ${response}