Robot Framework -007 RequestsLibrary 复杂json字符串发出http post request
2021-03-07 12:29
标签:robot att mamicode orm html sts 工具 代码 alt 研究了很长时间才成功。 假如有比较复杂的json串需要通过post提交: 其中的healthState还需要使用变量替换 则RF的代码如下: POST 的数据如下,json的数据在红框里。同时发现变量也被替换了。 同时推荐一个 json 格式化工具 的网址: https://www.freeformatter.com/json-formatter.html Robot Framework -007 RequestsLibrary 复杂json字符串发出http post request 标签:robot att mamicode orm html sts 工具 代码 alt 原文地址:https://www.cnblogs.com/abc789/p/12886614.html{
"links": [],
"fields": [],
"children": {
"serverRuntimes": {
"links": [],
"fields": ["name"],
"children": {
"JMSRuntime": {
"links": [],
"fields": ["name", "healthState"],
"children": {
"JMSServers": {
"links": [],
"fields": ["name", "healthState"],
"children": {
"destinations": {
"links": [],
"fields": ["name", "state"]
}
}
}
}
}
}
}
}
}
*** Settings ***
Library RequestsLibrary
Library Collections
Library json
JMS-related-runtimes
${ss} Set Variable healthState
${json_string}= catenate
... {
... "links": [], "fields": [],
... "children": {
... "serverRuntimes": {
... "links": [], "fields": [ "name" ],
... "children": {
... "JMSRuntime": {
... "links": [], "fields": [ "name", "${ss}" ],
... "children": {
... "JMSServers": {
... "links": [], "fields": [ "name", "${ss}" ],
... "children": {
... "destinations": {
... "links": [], "fields": [ "name", "state" ]
... }
... }
... }
... }
... }
... }
... }
... }
... }
${json}= evaluate json.loads(‘‘‘${json_string}‘‘‘) json
${data} Set Variable ${json}
${uri} Set Variable /domainRuntime/search
${resp} Post Request TOMCAT ${uri} data=${data}
Log ${resp}
Should Be Equal As Strings ‘${resp.status_code}‘ ‘200‘
文章标题:Robot Framework -007 RequestsLibrary 复杂json字符串发出http post request
文章链接:http://soscw.com/index.php/essay/61335.html