Robotframework:如何在robotframework脚本中使用jsonp

时间:2015-10-20 08:35:01

标签: robotframework

现在我需要编写一个类似这样的脚本:

${result}    set variable    {}
create session    url    http://xxx
${resp}    get request    url    /
should be equal as strings    ${resp.status_code}    200
Dictionary Should Contain Value    ${resp.jsonp(${result})}    Success
log    ${resp.jsonp(${result})}

但URL使用jSonp脚本编写。 那么机器人框架如何与jSonp和jSon脚本一起使用? 它的错误是这样的:

Invalid variable name `${resp.jsonp({})}`.

所有这些都是: enter image description here

jsonp来自url.nd和url用jsonp脚本编写。我需要使用RobotFramework获取url接口脚本。可能是我的脚本错误。

2 个答案:

答案 0 :(得分:0)

jsonp来自哪里?我认为您希望使用$ {resp.content},因为您已从请求库发送了GET请求

答案 1 :(得分:0)

我假设您正在使用Robotframework-Requests库,基于您提供的代码。

返回的响应对象没有.jsonp()方法。它有一个.json()方法,它不带参数并返回字典:

Dictionary Should Contain Value    ${resp.json()}    Success

如果要执行多项检查,也可以将其保存到变量中:

${json}=    set variable    ${resp.json()}
Dictionary Should Contain Value    ${json}    Success